Solution for the problem is provided below, please comment if any doubts:
1.
a)
Exact number of times execution of given statements in terms of n:
I. Statement 1
Answer: log3(n)
Explanation:
II. Statement 2
Answer: n*(n-1)/2 , if x<5 and 0 times otherwise
Explanation:
III. Statement 3
Answer: n(n+1)(n+2)/6 , if x>=5 and 0 times otherwise
Explanation:
IV. Statement 4
III. Statement 3
Answer: (16(logn)-1)/15
Explanation:
b)
Big-O complexity of program segments:
I. Segment I
Answer: O(log(n))
Explanation:
II. Segment II
Answer: O(n3)
Explanation:
III. Segment III
Answer: O(42logn)
Explanation:
Get Answers For Free
Most questions answered within 1 hours.