May19CS302-D KTUweb
May19CS302-D KTUweb
May19CS302-D KTUweb
1 Define the terms Best case, Worst case and Average case time complexities. (3)
2 What is the smallest value of n such that an algorithm whose running times is 100n2 runs faster (3)
than an algorithm whose running time is 2n on the same machine?
3 State Master Theorem. (3)
4 Explain the UNION and FIND-SET operations in the linked-list representation of disjoint sets. (3)
Discuss the complexity.
PART B
Answer any two full questions, each carries9 marks.
5 a) Determine the time complexities of the following two functions fun1() and fun2(): (2)
int fun1(int n)
{
if (n <= 1) return n;
return 2*fun1(n-1);
}
int fun2(int n)
{
if (n <= 1) return n;
return fun2(n-1) + fun2(n-1);
}
b) Find the solution to the recurrence equation using iteration method: (3)
T(2k) = 3 T(2k-1) + 1,
T (1) = 1
}
b) Explain the advantages of using height Balanced Trees? Explain AVL Rotations. (4)
c) Find the minimum and maximum height of any AVL-tree with 7 nodes? Assume that the height of a (2)
tree with a single node is 0.
7 a) List the Properties of B-Trees. (2)
b) A 2-3-4 tree is defined as a B-Tree with minimum degree t=2. Create a 2-3-4 tree by (4)
successively inserting the inserting the elements (in the given order) 42,56, 24, 89, 1, 5, 87,
8. 61. 6, 78, 7, 12, 34.
c) Delete the elements 89, 78. 12 and 8 from the above resultant tree. (3)
PART C
Answer all questions, each carries3 marks.
8 In a weighted graph, assume that the shortest path from a source ‘s’ to a destination ‘t’ is correctly (3)
calculated using a shortest path algorithm. Is the following statement true?
If we increase weight of every edge by 1, the shortest path always remains same. Justify your answer
with proper example.
9 Define Strongly Connected Components of a graph. (3)
Write the algorithm to find Strongly Connected Components in a graph.
10 Write an algorithm to merge two sorted arrays and analyse the complexity. (3)
11 Write notes on Dynamic Programming Approach. List the sequence of steps to be followed in (3)
Dynamic Programming.
PART D
Answer any two full questions, each carries9 marks.
12 a) State Shortest Path Problem and Optimal substructure of Shortest Path. (2)
b) Write Dijkstra’s Single Source Shortest path algorithm. Analyse the complexity. (4)
c) Find the shortest path from s to all other vertices in the following graph using Dijkstra’s Algorithm. (3)
13 a) Write the algorithm for DFS and analyse its complexity. (4)
b) Multiply the following two matrices using Strassen’s Matrix Multiplication Algorithm. (5)
Page 2 of 4
A F1008 Pages: 4
A= B=
14 a) State Matrix Chain Multiplication Problem. Write Dynamic Programming Algorithm for (4)
Matrix Chain Multiplication Problem.
b) Using Dynamic Programming, find the fully parenthesized matrix product for multiplying (5)
the chain of matrices< A1 A2 A3 A4 A5 A6 > whose dimensions are <30X35>, <35X15>,
<15X5>, <5X10>, <10X20> and <20X25> respectively.
PART E
Answer any four full questions, each carries10 marks.
15 a) Explain Greedy Approach. Write the general greedy algorithm. (3)
b) Formulate Fractional Knapsack Problem. Write Greedy Algorithm for fractional Knapsack (4)
Problem.
c) Find the optimal solution for the following fractional Knapsack problem. (3)
n=4, m = 60, W={40, 10, 20, 24} and P={280, 100, 120, 120}
16 a) Write the Kruskal’s algorithm for Minimum Spanning Tree. Analyse its complexity. (6)
b) Compute the Minimum Spanning Tree and its cost for the following graph using Kruskal’s (4)
Algorithm. Indicate each step clearly.
17 a) An undirected graph G=(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two vertices vi , vj are (4)
connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj) is assigned a weight i + j. What will be
the cost of the minimum spanning tree (as a function of n) of such a graph with n nodes?
b) Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry wij in the matrix W (6)
below is the weight of the edge {i, j}. What is the Cost of the Minimum Spanning Tree T using
Prim’s Algorithm in this graph such that vertex 0 is a leaf node in the tree T?
Page 3 of 4
A F1008 Pages: 4
18 a) State and Explain N Queens Problem. Write the backtracking algorithm for solving N (5)
Queens problem.
b) Show the state space tree for 4 Queens problem. Show the steps in solving 4 Queens (5)
problem using backtracking method to print all the solutions.
19 a) Explain Branch and Bound method for solving Travelling Salesman Problem. (5)
b) Solve Travelling Salesman problem for the following graph using Branch and Bound (5)
Technique.
Page 4 of 4