In: Computer Science
int Function(int n)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
for(int k = 0; k < n; k++)
{
Print(“hello world”);
}
}
}
}
1.
Let the following symbols denote the given statements :
h : it is hot outside
p : I will go to play
s : I will study
e : I will do good in 'exam'
The given premises are :
The conclusion to be proved is :
h
Let R be ( ( h -> ~p ) ∧ ( p -> ~s ) ∧ ( s -> e ) ∧ e ).
We need to show the truth value of ( ( h -> ~p ) ∧ ( p -> ~s ) ∧ ( s -> e ) ∧ e ) -> h
Let's use truth table for the given argument :
h | p | s | e | ( h -> ~p ) | ( p -> ~s ) | ( s -> e ) | R | R -> h |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 |
0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 |
1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
The final output that is R -> h or in other words, ( ( h -> ~p ) ∧ ( p -> ~s ) ∧ ( s -> e ) ∧ e ) -> h is not a tautology.
Hence, the given argument is not valid.
2.
Let the following symbols denote the given statements :
a : I can run faster than air plane
l : I can kill a lion
s : I am a super human
d : I am very careful about my diet
The given premises are :
The conclusion to be proved is :
~l
The given argument can be proved using the following table :
Statement no. | Statement | Justification |
1 | ( a v l ) -> s | given |
2 | s -> d | given |
3 | ~d | given |
4 | ~s | Modus tollens rule on statements 2 and 3 |
5 | ~(a v l ) | Modus tollens rule on statements 1 and 4 |
6 | ~ a ∧ ~ l | De Morgan's Law on statement 5 |
7 | ~l | Simplification rule on statement 6 |
The conclusion, ~l, can be derived from the given premises.
Hence, the given argument is valid.
3.
In the function, there are 3 for loops which are independent of each other and runs for O(n) times each.
So, total number of times the function executes is O(n^3) times.
Here, n = 100.
Then, the number of times the statement “hello world” will be printed is ( 100 * 100 * 100 ) = 1000000 times.
Hence, the answer is 1000000 times.