DS End Sem

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

INDIAN STATISTICAL INSTITUTE

ENDTERM EXAMINATION
M.TECH(CS) IYEAR
DATA STRUCTURES

Date: 05.12.2022 Maximum marks: 100 Duration: 3 hours.

The paper contains 110 marks. Answer as much as youcan, the maximum youcan score 1s 100.

1. Give the tightest possible upper bound for the worst case running time for each of the following
operations in terms of n. Give a very short explanation for your answer.
(a) Printing out the values in an AVL tree in post order.
(b) Finding the maximum value in a binary min heap of size n.
(c) Moving the values from a binary min heap, into an initially empty array of the same
size. The final contents of the array should besorted from low to high.
(d) Given a binary search tree cont aining n integers, create an AVL tree containing the same
values. You should not destroy the original binary search tree in the process.
Find the number of occurrences of a string of sizen in a text of m character stored in a
suffix tree. [5 x 3 = 15)
2. Give short answers to the following questions.

(a) Describe a procedure to implement two stacks in a single array.


edges
(b), Let the node i of a binary tree be at depth d, (the depth of a node is the number of of a
in the path from that node to the root; the root has depth 0). Define the weight
in
node i as wt(i) = 1/34:, and size of node i, s(i), as the sum of the weights of all nodes
the subtree rooted at i. Given any binary tree T with root r show that s(r) <3.

Consider a splay tree with nodes T, pand g where p is a left child of gand za left
child of
(c) Assuming
p. For splaying z, what elementary operation would be required at this step? implement
that each node has the fields left, right and parent, write a pseudo code to
possibly
the elementary operation. Note that t may not be the leaf node and p, q can
have right children.
T describe a
(d)/Given a binary search tree T of height h and a key k present in the tree and T>,
procedure which runs in O(h) time to split T into two binary search trees T
keys in T, are at least k.
such that all keys in T; are less than k and all
with n nodes have height O(lg n).
(e) Define AVL property ofa node. Show that an AVL tree
[5 x 8 = 40)

1
4.
(c) (b) (a) futureusing should
the behas The
written.sentence time
Describe The
company A (D)
Define Describe need Describe sentences writtenusers
needYounot Discuss data, the O(lg Tank(T):
return set. abstract
is get(): no
Contain
Suppose data
Demakebum(t),
not give e
a The how 1dentical
a data n)
necessarily helds be
binary
briefly i.e., a ofhas
universal in a comnpany ever part the where we return data
counter-example.
a I.that a
words data the that developed can Suppose to
standard
of
write search an writtentext-editor
completed. of n the type wewhich it
structure new they the implement the i, the and
hash how
implementation has is number, in value first
pseudo sentence the the RankedSet original that replaces all binary
tree sentences have
hiredusing a insert
function. you text-editor size z
you are set).
that already of in we itsof
codes, plan you the The then now Ranked the Draw one? then an the tree
need you that the elementsof in is descendents with
to company
editor
to demanding a element data
solve
a the set. Set set set pictures
immediately If
to of collected help for S ves the
2 description describe your would are such S ficld
written them text-editor and English that of give z usual
the has
require that elements
is if into in of
problem proposed and with the with an necessary. the the
the text the larger
along numberauto-complete both deletebinary a cachfields
in to it should set reason original
structure also it which node data,
Englishusing data solve developing
with a S than with z
big the
wants of that fronsearch
in
yourstructure. this their times data
give have above exactly the tree. inleft
no
wil of are following
the and
the problem. the it been more the tree
proposed
suffice. frequencies. an each setfeature, a operations less tree,right.
auto-complete
efficient suggestion i tree.
nodes (For which in than other than that
sentence
beenhas with
i.e, use operations: Wil does Write
|3+5+7= 15) data example,of consists elements
z 3 the
such way when for have (note
that T
of 5+5=10j sentences. the not surn a
structure. sornetime.
how procedure
a to
feature running new
tree). if store of a in already of
you this user [10] tree
all the the
f
omplete grap
eay different

ed grap'
ence
rtitir
rel (a) Using the above interface, design a procedure moveMinto Top(s), which given a stack s
puts it in the
t
hnds the minimmum clencnt in s, rernoves it from its current position and
top of s keeping the remainder of the stack in its original order. In your design you
oDerations/data structures except what 15
are not allowed to use any other non-trivial
multiple instances of stacks
provided by the stack interface described above. vOu can use
as returned by newStack() if required.
stack interface that you are proVided,
(b) Assume that in the specificimplementation of the s contains n elements what would be
If
each of the operations above takes O1) time. Top(s) that you designed in part
moveMinto
the asymptotic complexity of the pro cedure
(a) of this question.
(6 +4 = 10]

one possible exception, non leaf nodes have d


5. A d-ary heap is like a binary heap but with
children instead of two children.
particular, write procedures for
. Discuss an array implementation of a d-ary heap. In
finding the children and parent of a given node.
What is the height of a d-ary heap of n elements in terms of n and d.
a d-ary max-heap. Analyze the
(c) Give an efficient procedure to implement Extract-Max in
running time in terms of d and n.
(2 +2+6 = 10)
than promoting each node to the
6 Suppose we have a skip list with n entries in which, rather for 0 <p<1.
next higher level with probability 1/2, we promote each node with probability p,
height
(a) Given a skip list with n entries, show that the expected number of list entries of
log1 n is O(1). Briefly explain.
(b) Show that (excluding the sentinel nodes) the total mumber of nodes in such a skip list is
expected to be at most 1-p'

5+5= 10|

You might also like