0% found this document useful (0 votes)
45 views

Design and Analysis of Algorithms

The document describes a question paper for a Design and Analysis of Algorithms exam. It contains 8 questions testing different algorithm topics like quicksort analysis, longest common subsequence, red-black trees, graph algorithms, heaps, and amortized analysis.

Uploaded by

Anubhav Shukla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Design and Analysis of Algorithms

The document describes a question paper for a Design and Analysis of Algorithms exam. It contains 8 questions testing different algorithm topics like quicksort analysis, longest common subsequence, red-black trees, graph algorithms, heaps, and amortized analysis.

Uploaded by

Anubhav Shukla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.

This question paper contains 7 printed pages]

Roll No. I I I f I I I I I I 1· I
S. No. of Question Paper : 6070

Unique Paper Code : 234301 D

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.

Attempt any four questions from Q. No. 2 to Q. No. 7.


sD

1·. (a) Prove that the average running time of Quicksort is O(n lg ·n) where n is the number

of elements. 5
al

(b) Determine an LCS of <1, 0, 0, I, 0, 1, 0, 1> and <0, 1, 0, 1, 1, 0, 1, 1, 0>. 5


ri

(c) Beginning with an empty red-black tree insert in succession the following keys : 5
to

10 20 30 80 50 70 75
Tu

From the above tree delete 20.

P.T.O.

Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.

For any query, contact us at [email protected]


Visit https://www.tutorialsduniya.com for Notes,( books,
2 ) programs, question papers with solutions etc.
6070

(d) Consider the following recursive function: 5

TOH(in n, char from, char to,.char aux) .

m
{

if(n==I)

co
Cout<<"Move disk I from "<<from<<" to "<<to;

a.
else

iy
{
un
TOH (n-1, from,aux,to );
sD

cout<<"Move disk"<<n<<" from"<<from<<"to"<<to;

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.

For any query, contact us at [email protected]


,
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.

algorithms ? Give an argument or a counterexample.


al

3
ri

(g) Suppose the elements in an array are (starting at index 1) 25, 19,.15, 5, 12, 4, 13,

3, 7, 10. Does this array represent a heap ? Justify your answer. 2


to

(h) Suppose we perform a sequence of n operations on a data structure in which the


Tu

/h operation costs i if i is an exact power of2 and 1 otherwise~ Use aggregate analysis

to determine the amortized cost per operation. 5

P.T.O.

Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.

For any query, contact us at [email protected]


Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
( 4 ) . 6070

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

the same amount of water.

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

(h) Suppose that CONNECTED-COMPONENTS is run on the undirected graph

G = (V, E), where V = {a, b, c, d, e, j, g, h, i, j, k} and the edges of E are


Tu

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

after each iteration. 5

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

(ii) 35, 12, 28, 17, 19.

co
2

(b) Let a, b and c be arbitrary nodes m subtrees a, ~ and y respectively, in the

a.
following figure. How do the depths of a, b and c change when a left rotation is performed

on node x in the figure ? 3

iy
un
sD
al

.y
ri
to

(c) What is the 'largest possible number of internal nodes in a red-black tree with
Tu

black-height k ? What is the smallest possible number of nodes ? 3

(d) What is an order-statistic tree ? Explain and give an example. 2

P.T.O.

Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.

For any query, contact us at [email protected]


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

to find whether a given directed graph is bipartite or not. 5

. ~

Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.

For any query, contact us at [email protected]


Visit https://www.tutorialsduniya.com for Notes, books, programs, question papers with solutions etc.
( 7 ) 6070

7. (a) Find the failure indexes for the following pattern :

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.

For any query, contact us at [email protected]


----------------------------

You might also like