(2015) ADA-2nd internals-QN+Ans - Key
(2015) ADA-2nd internals-QN+Ans - Key
SCHOOL OF ENGINEERING
CO1: Analyse the worst case and average case running times of algorithms using asymptotic analysis.
CO3: Understand the dynamic programming paradigm and its algorithmic design situations
CO4: Familiarise the greedy design technique.
IV. Obtain optimal binary search tree for the following. CO-3
Keys 10 20 30 40
Frequency 4 2 6 3
*******************************
ANSWER KEY
Asymptotic Notations:
Asymptotic Notation is a way of comparing function that ignores constant factors and small input sizes.
Three notations are used to calculate the running time complexity of an algorithm:
1. Big-oh notation: Big-oh is the formal method of expressing the upper bound of an algorithm's
running time. It is the measure of the longest amount of time. The function f (n) = O (g (n)) [read as "f
of n is big-oh of g of n"] if and only if exist positive constant c and such that
f (n) ⩽ k.g (n)f(n)⩽k.g(n) for n>n0n>n0 in all case
Hence, function g (n) is an upper bound for function f (n), as g (n) grows faster than f (n)
For Example:
1. 1. 3n+2=O(n) as 3n+2≤4n for all n≥2
2. 2. 3n+3=O(n) as 3n+3≤4n for all n≥3
Hence, the complexity of f(n) can be represented as O (g (n))
2. Omega () Notation: The function f (n) = Ω (g (n)) [read as "f of n is omega of g of n"] if and only if
there exists positive constant c and n0 such that
F (n) ≥ k* g (n) for all n, n≥ n0
For Example:
f (n) =8n2+2n-3≥8n2-3
=7n2+(n2-3)≥7n2 (g(n))
Thus, k1=7
Hence, the complexity of f (n) can be represented as Ω (g (n))
3. Theta (θ): The function f (n) = θ (g (n)) [read as "f is the theta of g of n"] if and only if there exists
positive constant k1, k2 and k0 such that
k1 * g (n) ≤ f(n)≤ k2 g(n)for all n, n≥ n0
For Example:
3n+2= θ (n) as 3n+2≥3n and 3n+2≤ 4n, for n
k1=3,k2=4, and n0=2
Hence, the complexity of f (n) can be represented as θ (g(n)).
The Theta Notation is more precise than both the big-oh and Omega notation. The function f (n) = θ
(g (n)) if g(n) is both an upper and lower bound.
1. Dynamic Programming is used to obtain 1. Greedy Method is also used to get the
the optimal solution. optimal solution.