0 Analysis Sheet-1
0 Analysis Sheet-1
Contents
FIRST: Analysis of Normal Code .............................................................................................................................................. 2
SECOND: Analysis of Recursive Code ...................................................................................................................................... 3
THIRD: Asymptotic Notations ................................................................................................................................................. 4
FOURTH: Recurrence Equations.............................................................................................................................................. 5
FIRST: Analysis of Normal Code
#iteration =N
o(Body)=O(1)
o(1)*o(N)=O(N)
#iteration=R
o(Body)=O(R)
O(R)*O(R)=O(R^2)
1 R
1 2 4 8 16 2^L
SECOND: Analysis of Recursive Code
What's the exact complexity of the following code?
Fun2(A, S, E) 3T(N/3)+O(1) a. Θ(N)
IF (S == E) return A[S] master method b. Θ(N3 )
S1 = (S + E) / 3 n^logba =N c. Θ((log(𝑁))3)
1. S2 = 2 × (S + E) / 3
N>1 d. Θ(log(𝑁))
R1 = Fun2(A, S, S1)
#theta(N) e. Θ(3 × log(𝑁))
R2 = Fun2(A, S1+1, S2)
R3 = Fun2(A, S2+1, E) f. Θ(1)
Return Max(R1, R2, R3)
outer loop:-
4T(N\8)+O(1)
0 n
0 n/2 n
4T(N/4)+O(1)
# iteration =2
#iteration *o(Body)
inner loop:-
N ,N-1,N-2 N-L
N-l=1
L=n-1
#iteration*o(Body)
=N*O(1)=O(N)
________
total
2*O(N)=O(N)
THIRD: Asymptotic Notations
1. Chose the notation that BEST REPRESENTS the WORST case?
Fun2(N) a. O(1)
Sorted = true b. Θ(1)
I = 1 c. O(N)
While (I < N AND Sorted == true)
d. Θ(N)
If (A[I] > A[I + 1])
e. Ω(1)
Sorted = false
End If f. Ω(N)
I = I + 1 g. Θ(N-1)
End while h. None of the choices
Print Sorted
2. Let f(N) = 10N×Log2(N) and g(N) = N, what's the possible value(s) of N0 that makes f(N) = Ω(g(N)) for constant
C = 20?
a. 1≤ N0≤32 b. 0< N0 ≤ 2 c. N0 ≥ 2 d. N0 ≥ 4 e. No values exist. The relation is not valid
3. Given the following orders (log is base 2):
1)√ 𝑒 log(𝑁) + 𝑁 3 , 2) 1⁄√log (𝑁) , 3) 𝑁, 4) 𝑁 3 , 5) 4log (𝑁) , 6) 𝑁 log(𝑁)
Arrange them in increasing order of growth rate (with g(n) following f(n) in your list if and only if
f(n)=O(g(n))). Chose the correct order?
a. 2,3,6,5,1,4 b. 2,3,1,6,5,4 c. 2,6,3,1,5,4 d. 2,3,6,1,5,4 e. 4,5,1,3,6,2 f. None of choice
FOURTH: Recurrence Equations
1. Using the RECURSION TREE method, Answer the following questions:
𝐓(𝐍) = 𝐓(𝐍/𝟓) + 𝐓(𝟕𝐍/𝟏𝟎) + 𝚯(𝐍) ; 𝐓(𝟏) = 𝟏
Question Answer
2. Given T(N) = 64 T(N / 16) + (22/7) N√N, using Master Method: what's the correct value of Ɛ