Design and Analysis of Algorithms
Design and Analysis of Algorithms
Roll No. I I I f I I I I I I 1· I
S. No. of Question Paper : 6070
m
Name of the Paper : Design and Analysis of Algorithms (CSHT:305)
Name of the Course : B.Sc. (Hons.) Computer Science
co
Semester : III
Duration : 3 Hours Maximum Marks : 75
a.
(Write your Roll No. on the top immediately on receipt of this question paper) ·
iy
un Question No. 1 of 35 marks is compulsory.
1·. (a) Prove that the average running time of Quicksort is O(n lg ·n) where n is the number
of elements. 5
al
(c) Beginning with an empty red-black tree insert in succession the following keys : 5
to
10 20 30 80 50 70 75
Tu
P.T.O.
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
m
{
if(n==I)
co
Cout<<"Move disk I from "<<from<<" to "<<to;
a.
else
iy
{
un
TOH (n-1, from,aux,to );
sD
TOH(n-1 ,aux,to,from);
al
}
ri
}
to
Let T(n) represents the total number of moves required to move n disks from one
Tu
tower to another. Give a recurrence relation for T(n). Find T(n) in terms of
big Oh.
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
( 3 ) 6070
(e) · Apply DFS algorithm on the following graph. Assume that adjacency lists are in
alphabetical order. Also classify the different edges as tree, forward, back and
m
cross edge. 5
co
a.
iy
un
sD
(j) Is it always true th~t an array that is already sorted is a best-case input for sorting.
3
ri
(g) Suppose the elements in an array are (starting at index 1) 25, 19,.15, 5, 12, 4, 13,
/h operation costs i if i is an exact power of2 and 1 otherwise~ Use aggregate analysis
P.T.O.
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
2. (a) Suppose that you are given n red and n blue water jugs, all of different shapes and
sizes. All red jugs hold different amounts of water, as do the blue ones. Moreover, for
every red jug, there is a blue jug that holds the same amount of water, and vice versa.
m
It is your task to find a grouping of the jugs into pairs of red· and blue jugs that hold
co
To do so, you may perform the following operation : pick a pair of jugs in which
one is red and one is blue, fill the red jug with water, and then pour the wat~r
a.
into the blue jug. This operation will tell you whether the red or the blue jug can hold
iy
more water, or if they are of the same volume. Assurrie that such a comparison takes
one time unit. Your goal is to give an algorithm that uses O(n2) comparisons to group
un
the jugs into pairs. Remember that you may not directly compare two red jugs or two
blue jugs. 5
lsD
(b) Find the average/expected time taken by bucket sort to sort an array containing.
n elements. 5
ia
3. (a) Suppose we are to find the k smallest elements in a list ofn elements, and we are not
interested in their relative order. Give a linear time algorithm for the same. 5
r
to
processed in the following order : (d, i), if, k), (g, i), (b, g), (a, h), (i, j), (d, k),
(b, j), (d, f), (g, j), (a, e), (i, d). List the vertices in each connected component
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
I
For any query, contact us at [email protected]
L,
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
( 5 ) 6070
4. (a) Suppose that we have numbers between 1 and 50 in a red-black tree and want to
search for the number 19. Which of the following sequences could not be the sequence
of nodes examined ?
m
(i) 26, 28, 15, 17, 19
co
2
a.
following figure. How do the depths of a, b and c change when a left rotation is performed
iy
un
sD
al
.y
ri
to
(c) What is the 'largest possible number of internal nodes in a red-black tree with
Tu
P.T.O.
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
( 6 ) 6070
5. (a) What is memorization? Show how this helps in increasing the efficiency of a recursive
program. 5
m
(b) Not just any greedy approach to the activity-selection problem produces a maximum-
co
size set of mutually compatible activities. Give an example to show that the approach
a.
of selecting the activity of least duration from those that are compatible with previously
iy
selected activities does not work. 5
6. (a)
un
Find the minimum spanning tree for the following graph using Kruskal's algorithm. 5
a lsD
ri
to
Tu
(b) A bipartite graph is a graph whose vertices may be partitioned into two subsets such
that there is no edge between any two vertices in the same subset. Write an algorithm
. ~
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
AABAACAABABA
m
Assume array indexes are starting from 1.
5
(b) Is Prim's minimum spanning tree algorithm a greedy algorithm? Justify your answer. Also
co
give running time of the algorithm.
5
a.
iy .
un .
sD
al
ri
to
Tu
6070 7 1,200
Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.