Professional Documents
Culture Documents
4. Consider a recurrence relation T(n)= T(n-1)+n for n>0 with initial condition T(n) =1,n=0.
Solve it using Substitution method. T = O (n2) <4M>
5. Analyze the following code snippet and write the time and space complexity.
(a) for(i=n;i>=1;i=i/2)
{
for(j=1;j<=m;j*=2)
{
stmt; T = O (log2n * log2m) S = O (1)
}
}
(b) while(n>0)
{
Ans+=n;
n=n/2; T = O (log2n) S = O (1)
stmt;
}
(c) void T1(int n)
{
If(n>0)
{
stmt; T = O (n) S = O (n)
T1(n-1);
} <6M>
}
6. Write an algorithm for quick sort and discuss its time and space complexity. <6M>
7. Write iterative and recursive algorithm for finding an element in sequential order.
Compare and contrast both iterative and recursive approach in terms of time and
space complexity. <10M>
10. List out the steps in Mathematical Analysis of recursive Algorithms with an example. <8M>
11. Construct a recursion tree for the recurrence T(n)=3T(n/4)+cn2 and calculate it’s
time complexity. <8M>