0% found this document useful (0 votes)
16 views8 pages

Paper Daa

Uploaded by

ashish4125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Paper Daa

Uploaded by

ashish4125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

eo

This qucstion paer

Your Roll No....

Sr. No. of Question Paper


:

2208 C
nique l'aper Code 32341 401

Name of the Paper Design & Analysis o


Algorithms
Namc of the Course B.Sc. (H) Computer Science

Semester IV

Duration : 3 Hours Maximum Marks : 75

Instructions for Candidates


1.
1. Write your Roll No. on the top immediately on receipt
of this question paper.

2 Question No. 1 is compulsory.


3. Attempt any four of Questions Nos. 2 to 7.
3.

(Consider an input of n numbers that are all equal.


What would be the running time of the following
algorithms for the input:

G) Merge Sort

(1) Heap Sort (4)


P.T.O.
2208 2

(bX Give a recurrence for the running time of the

to sort n elements
following algorithms

(i) Maxheapify

(11) Quicksort (2)

(CCan Insertion Sort be used as an intermediate sort


for Radix sort? Explain why or why not. (3)

(d)Compare the worst case running times of the


following operations with respect to red-black trees
and binary search treesS.

(i) Searching a given key


i) Inserting a
given key (4)
e)Recall that the usual implementation of
makes two
quicksort
recursive calls. Consider a variant that
optimizes on stack space as follows. It recurses
on the smaller
subarray as
usual, but whenever it
needs to recurse
on the larger
iterative module subarray, it uses an
instead. What would be the
of
recursion for this depth
variant? Compare it to the
depth of
recursion for usual
quicksort. implementation of

(4)
2208 3

(D Give an example graph with 5 nodes that gives


lifferent Minimum Spanning Trecs when

computed with Prim's algorithm and Kruskal'

algorithm. (4)

(g)Consider the following recurrcnce relation for

computing the sum of n natural numbers.

F(n) F(n-1)+n.
=
n>l

F(1) = 1

What is the running time of the recursive


implementation of the above recurrence? Would

memoizing the recursive solution improve the


running time? Explain. (4)

certain application it is required to find the


(In a

nodes adjacent to a given node in a sparse graph.


Which of the two representations, namely
adjacency list and adjacency matrix, is more

suitable? Justify. (4)

)Can Depth First Search algorithm be used to


determine a shortest path from a source node

to a destination node in an unweighted graph?

Justify. (3)
P.T.O
2208

(i) Consider the Interval Scheduling problem whcrein


We are given a resource and a set of requests

cach having a start time and a finish time. The


goal is 1o maximize the number of requests
schedulcd. Show that the following greedy strategy
does not give an optimal solution for the above
problem: select the request with fewest number
of incompatible requests. (3)

(a) Let T be a red-black tree and x be a node in it.


Let h be the height of the node x in T and d be
its depth. Left rotate operation is performed on
the node x to give resultant tree 7T'.

(i) How does the height of x change post


rotation?

(i) How does the depth of x change post


rotation? (4)
(b) Give a scenario in which the naive string
matching algorithm demonstrates its worst casse
behaviour.
(3)

(c) Give a recurrence relation for solving the subset


sum problem.
(3)

(a) Consider the following graphs:


2208
5

G2
V

X
y

For each of the


graphs, specify whether the graph
is bipartite or not. If it is
bipartite then give the
two partitions else justify. (4)
(b) Recall the scheduling problem wherein we are
given a
single resource and a set of requests
having deadlines. A request is said to be late if it
misses the deadline. Our goal is to minimize the
maximum lateness. With respect to a schedule S,
we define idle time as the time during which the
resource is idle, in between two requests. S is

P.T.O.
2 2
Lag2

2208
2
said to have an inversion when request i has
hee.
cen
schcduled before j, and d(i) dý) (d{k)
being the
deadline of a request k). Argue that all
schedules
with idle time and
no no inversions have the same
maximum lateness.
(6)
(a) Consider the
Heapsort Algorithm. Fill in the
missing details correctly.
(3)
Assume A[1...length] be the array to be sorted

MaxHeapify(A,i)
1-2
F2*i+1
ifl<=
A.heapsize and A[l]>A[r]
largest==1
else largest = i
if
r=A.heapsize and A[r] >A[largest]
largest =Fr
iflargest!=i
exchange A[i] and A[largest]
Maxheapify(A, _
BuildMaxHeap(A)
A.heapsize = A.length
for i =

MaxHcapify (A,i)
Heapsort(A)
BuildMaxHeap
for i= (A)
A.lengthdownto
Cxchange A[_]with2 A[i]
A.heapsize= A.heapsize -1
MaxHeapify (A,_)
7
2208

(h) Is the following recurrence for the


problem correct? 1f Nol,
Knapsack
gIve the
urrence. ust1Ty you correct
answer in either
case
1fw<w, then OPTGi. = OPTG-1,w) "
Otherwise, OPT(i,w)= max(OPTG-1).w
OPT(i-1, w) V,
(4)
Give an algorithm to determine if a
given
undirected graph is connected.
(3)
5.
5. (a) Consider a stack that supports the
operations Push,
Pop and Multi-push (pushes k items onto the stack).
Suppose a sequence of n operations is performed
on the stack. Would the amortized cost of an
operation be O(1)? Explain. (4)

b)If quick sort is run on an n sized array such that


the array is always divided into 2 equal halves.
How many times is the partition algorithm called?

Explain briefly. (3)

(c) Consider the weighted interval scheduling


problem. Will the following greedy strategy
Choose
work? Justify.While requests remain,
that has the
and add a request to solution
non-compatible
argest starting time and delete all
(3)
requests.
randomized

6. (a) In randomized-select
algorithm
tne
replace
is used. If
we
Pal t i o n
subroutine P.T.O.

2.T
208
8
partition
subroutine which
randomized partition by
a
list as pivot and
and
element of the
chooses the last
as the
select algorithm
call the modified algorithm
on the running time of
What affect does
it have
the select algorithm? (3)
a topological
directed graph having
(6) Show that any
(4)
must be acyclic.
ordering
valid Red
6, 2, 8, 3, 10; give
a
elements
c) For the (3)
Black tree.

d-ary heap is like a binary heap, except that


a))A instead of two children.
nodes may have d children
Consider a represented using an array,
3-ary heap
children of a
how would the indices of the three
node be computed? (3)

A thief wants to steal all the gold dust from


(b)
having W kg of it. The thief has
n
a store
sacks having different capacities. Give an

efficient algorithm for the thief to fill his sacks


with dust so that the number of sacks used 1s

minimized. (3)
(cDiscuss the running time of the following function
func(A)
for i 0 to A.length -2
for j = i+1 to A.length - 1

if(Aj-1]> A[j])
exchange (Aj-1] and AD]) (4)
(1400)

You might also like