You are on page 1of 404

FINALTERM EXAMINATION

Spring 2010
CS301- Data Structures
Time: 90 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne

A
solution is said to be efficient if it solves the problem within its resource constraints i.e. hardware and
time.
) True
) False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! is known as "#ast$%n& First$'ut" or #%F' (ata )tructure*
) #inked #ist
) )tack
) +ueue
) Tree
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
hat will be postfi, e,pression of the followin! infi, e,pression*
%nfi, -,pression : a.b/c$d
) ab.c/d$
) abc/.d$
) abc./d$
) abcd./$
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne

For
compiler a postfi, e,pression is easier to evaluate than infi, e,pression*
) True
) False
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


C!nsi,er t(e -!''!.ing pseu,! c!,e
declare a stack of characters
while 0 there are more characters in the word to read 1
2
read a character
push the character on the stack
3
while 0 the stack is not empt4 1
2
pop a character off the stack
write the character to the screen
3
/(at is .ritten t! t(e screen -!r t(e input 0app'es01
) selpa
) selppa 5
) apples
) aaappppplleess
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! function:
void test7a0int n1
2
cout 88 n 88 " "9
if 0n:01
test7a0n$;19
3
hat is printed b4 the call test7a0<1*
) < ;
) 0 ; <
) 0 ;
) ; <
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne

%f
there are = e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) = $>
) =.>
) =.;
) =
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne

%f
there are = internal nodes in a binar4 tree then what will be the no. of e,ternal nodes in this binar4 tree*
) = $>
) =
) = .>
) = .;
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne

%f we
have >000 sets each containin! a sin!le different person. hich of the followin! relation will be true on
each set:
) ?efle,ive
) )4mmetric
) Transitive
) Associative
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! is ='T the propert4 of e@uivalence relation:
) ?efle,ive
) )4mmetric
) Transitive
) Associative
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne

A
binar4 tree of = nodes has 7777777.
) #o!>0 = levels
) #o!; = levels
) = A ; levels
) = , ; levels
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne

The easiest case of deletin! a node from B)T is the case in which the node to be deleted 77777777777.
) %s a leaf node
) Cas left subtree onl4
) Cas ri!ht subtree onl4
) Cas both left and ri!ht subtree
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

If
there are N elements in an array then the number of maximum steps needed to fnd
an element using Binary Search is _______ .
) =
) =
;
) =lo!;=
) lo!;=
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
Mer!e sort and @uick sort both fall into the same cate!or4 of sortin! al!orithms. hat is this
cate!or4*
) '0nlo!n1 sorts
) %nterchan!e sort
) Avera!e time is @uadratic
) =one of the !iven options.
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
%f one pointer of the node in a binar4 tree is =D## then it will be aAan 7777777 .
) -,ternal node
) ?oot node
) %nner node
) #eaf node
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne

e
convert the 77777777 pointers of binar4 to threads in threaded binar4 tree.
) #eft
) ?i!ht
) =D##
) =one of the !iven options
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

%f the
bottom level of a binar4 tree is ='T completel4 filled& depicts that the tree is ='T a ) -,pression
tree
) Threaded binar4 tree
) complete Binar4 tree
) Eerfectl4 complete Binar4 tree
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne


hat is the best definition of a collision in a hash table*
) Two entries are identical e,cept for their ke4s.
) Two entries with different data have the e,act same ke4
) Two entries with different ke4s have the same e,act hash value.
)Two entries with the e,act same ke4 have different hash values.
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose that a selection sort of >00 items has completed <; iterations of the main loop. Cow man4 items
are now !uaranteed to be in their final spot 0never to be moved a!ain
) ;>
) <>
) <;
) <5
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !n
)uppose 4ou implement a Min heap 0with the smallest element on top1 in an arra4. 6onsider the different
arra4s below9 determine the one that cannot possibl4 be a heap:
) >F& >8& ;0& ;;& ;<& ;8& 50
) >F& ;0& >8& ;<& ;;& 50& ;8
) >F& ;<& >8& ;8& 50& ;0& ;;
) >F& ;<& ;0& 50& ;8& >8& ;;
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !ne
(o 4ou see an4 problem in the code of ne,t%n'rder below:
Tree=ode / ne,t%norder0Tree=ode / p1
2
if0p$:?TC GG thread1
return0 p$:? 19
else 2
p G p$:?9
while0p$:#TC GG child1
p G p$:?9
return p9
3
3
) The function has no problem and will fulfill the purpose successfull4.
) The function cannot be compile as it has s4nta, error.
) The function has lo!ical problem& therefore& it will not work properl4.
) The function will be compiled but will throw runtime e,ception immediatel4 after the control is
transferred to this function.
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne


/(ic( !- t(e -!''!.ing state6ent is c!rrect a7!ut -in,#8% !perati!n"
) A find0,1 on element , is performed b4 returnin! e,actl4 the same node that is found.
) A find0,1 on element , is performed b4 returnin! the root of the tree containin! ,.
) A find0,1 on element , is performed b4 returnin! the whole tree itself containin! ,.
) A find0,1 on element , is performed b4 returnin! T?D-.
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !n
hich of the followin! statement is ='T correct about find operation:
) %t is not a re@uirement that a find operation returns an4 specific name& Hust that finds on two elements
return the same answer if and onl4 if the4 are in the same set.
) 'ne idea mi!ht be to use a tree to represent each set& since each element in a tree has the same root&
thus the root can be used to name the set.
) %nitiall4 each set contains one element.
) %nitiall4 each set contains one element and it does not make sense to make a tree of one node onl4.
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne
%n complete binar4 tree the bottom level is filled from 77777777
) #eft to ri!ht
) ?i!ht to left
) =ot filled at all
) =one of the !iven options
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne
Cere is an arra4 of ten inte!ers:
5 5 8 9 > I 0 ; F <
The arra4 after the F%?)T iteration of the lar!e loop in a selection sort 0sortin! from smallest to lar!est1.
) 0 5 8 9 > I 5 ; F <
) ; F < 0 5 8 9 > I 5
) ; F < 9 > I 0 5 8 5
) 0 5 8 ; F < 9 > I 5
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
hat re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4*
) The arra4 elements must form a heap.
) The arra4 must have at least ; entries.
) The arra4 must be sorted.
) The arra4Js siKe must be a power of two.
uesti!n N!" 23 # Mar$s" 2 %
Live one e,ample of Cashin!
uesti!n N!" 24 # Mar$s" 2 %
Cow heap sort works to sort a set of data.
uesti!n N!" 25 # Mar$s" 2 %
Cow we can implement Table A(T usin! #inked #ist
uesti!n N!" 30 # Mar$s" 2 %
%f we allow assi!nment to constants what will happen*
uesti!n N!" 31 # Mar$s" 3 %
-,plain the process of (eletion in a Min$Ceap
uesti!n N!" 32 # Mar$s" 3 %
Live an4 three characteristics of Dnion b4 ei!ht method.
uesti!n N!" 33 # Mar$s" 3 %
"For smaller lists& linear insertion sort performs well& but for lar!er lists& @uick sort is suitable to appl4."
Mustif4 wh4*
uesti!n N!" 3* # Mar$s" + %
/rite ,!.n t(e C99 c!,e t! i6p'e6ent Inserti!n S!rt A'g!rit(6:
uesti!n N!" 3+ # Mar$s" + %
6onsider the followin! Threaded Binar4 Tree&
Nou have to !ive the values that should be in the four variables !iven below& for the node 33
>. #TC 0#eft fla!1
;. ?TC 0?i!ht fla!1
5. #eft node pointer 0$:#1
<. ?i!ht node pointer 0$:?1
uesti!n N!" 32 # Mar$s" + %
hat is (isHoint )ets* -,plain with an e,ample.
FINALTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
Time: 90 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !
hich one of the followin! operations returns top value of the stack*
) Eush
) &!p
) Top
) First
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
6ompiler uses which one of the followin! in Function calls&
) )tack
) +ueue
) ;inar< Searc( Tree
) AO# Tree
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
-ver4 AO# is 77777777777777777
) Binar4 Tree
) 6omplete Binar4 Tree
) =one of these
) ;inar< Searc( Tree
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
%f there are 5F internal nodes in a binar4 tree then how man4 e,ternal nodes this binar4 tree will have*
) 5<
) 55
) 5F
) +3
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne

%f
there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) ;5
) ;<
) ;>
) 22
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is not an e,ample of e@uivalence relation*
) -lectrical connectivit4
) )et of people
) => re'ati!n
) )et of pi,els
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne

Bina
ry Search is an algorithm of searching, used with the ______ data.
) S!rte,
) Dnsorted
) Cetero!eneous
) ?andom
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne

hic
h one of the followin! is ='T true re!ardin! the skip list*
) -ach list )i contains the special ke4s . infinit4 and $ infinit4.
) #ist )0 contains the ke4s of ) in non$decreasin! order.
) -ach list is a subse@uence of the previous one.
) List S( c!ntains !n'< t(e n specia' $e<s:
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne

A
simple sortin! al!orithm like selection sort or bubble sort has a worst$case of
) '0>1 time because all lists take the same amount of time to sort
) '0n1 time because it has to perform n swaps to order the list.
) O#n
2
% ti6e 7ecause s!rting 1 e'e6ent ta$es O#n% ti6e - A-ter 1 pass t(r!ug( t(e 'ist?
eit(er !- t(ese a'g!rit(6s can guarantee t(at 1 e'e6ent is s!rte,:
) '0n
5
1 time& because the worst case has reall4 random input which takes lon!er to
sort.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne

@-hich of the followin! is a propert4 of binar4 tree*
) A binar4 tree of = e,ternal nodes has = internal node.
) A 7inar< tree !- N interna' n!,es (as N9 1 e8terna' n!,e:
) A binar4 tree of = e,ternal nodes has =. > internal node.
) A binar4 tree of = internal nodes has =$ > e,ternal node.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
B4 usin! 7777777777we avoid the recursive method of traversin! a Tree& which makes use of stacks and
consumes a lot of memor4 and time.
) Binar4 tree onl4
) T(rea,e, 7inar< tree
) Ceap data structure
) Cuffman encodin!
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne

hic
h of the followin! statement is true about dumm4 node of threaded binar4 tree*
) This dumm4 node never has a value.
) This dumm4 node has alwa4s some dumm4 value.
) T(is ,u66< n!,e (as eit(er n! Aa'ue !r s!6e ,u66< Aa'ue:
) This dumm4 node has alwa4s some inte!er value.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

For a
perfect binar4 tree of hei!ht h& havin! = nodes& the sum of hei!hts of nodes is
) = P 0h P >1
) N B #( 9 1%
) = P >
) = P > . h
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne

hat
is the best definition of a collision in a hash table*
) Two entries are identical e,cept for their ke4s.
) T.! entries .it( ,i--erent ,ata (aAe t(e e8act sa6e $e<
) Two entries with different ke4s have the same e,act hash value.
) Two entries with the e,act same ke4 have different hash values.
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
hich formula is the best appro,imation for the depth of a heap with n nodes*
) '!g #7ase 2% !- n
) The number of di!its in n 0base >01& e.!.& ><5 has three di!its
) The s@uare root of n
) n
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! statement is ='T correct about find operation:
) %t is not a re@uirement that a find operation returns an4 specific name& Hust that finds on two
elements return the same answer if and onl4 if the4 are in the same set.
) 'ne idea mi!ht be to use a tree to represent each set& since each element in a tree has the same
root& thus the root can be used to name the set.
) %nitiall4 each set contains one element.
) Initia''< eac( set c!ntains !ne e'e6ent an, it ,!es n!t 6a$e sense t! 6a$e a tree !- !ne n!,e
!n'<:
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

hich of the followin! is not true re!ardin! the maKe !eneration*
) ?andoml4 remove walls until the entrance and e,it cells are in the same set.
) ?emovin! a wall is the same as doin! a union operation.
) Re6!Ae a ran,!6'< c(!sen .a'' i- t(e ce''s it separates are a'rea,< in t(e sa6e set:
) (o not remove a randoml4 chosen wall if the cells it separates are alread4 in the same set.
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne
%n threaded binar4 tree the =D## pointers are replaced b4 &
) preorder successor or predecessor
) in!r,er success!r !r pre,ecess!r
) postorder successor or predecessor
) =D## pointers are not replaced
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the !iven option is ='T a factor in Dnion b4 )iKe:
) Maintain siKes 0number of nodes1 of all trees& and durin! union.
) Make smaller tree& the subtree of the lar!er one.
) Ma$e t(e 'arger tree? t(e su7tree !- t(e s6a''er !ne:
) %mplementation: for each root node i& instead of settin! parentQiR to $>& set it to $k if tree rooted at i
has k nodes.
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose we had a hash table whose hash function is Sn T >;U& if the number 55 is alread4 in the hash
table& which of the followin! numbers would cause a collision*
) ><<
) ><5
) 1*3
) ><8
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !
hat re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4*
) The arra4 elements must form a heap.
) The arra4 must have at least ; entries.
) T(e arra< 6ust 7e s!rte,.
) The arra4Js siKe must be a power of two
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
A binar4 tree with ;< internal nodes has 777777 e,ternal nodes.
) ;;
) ;5
) <8
) 2+
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !n
%n case of deletin! a node from AO# tree& rotation could be prolon! to the root node.
) Ces
) =o
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne
.(en .e (aAe ,ec'are, t(e siDe !- t(e arra<? it is n!t p!ssi7'e t! increase !r ,ecrease it ,uring t(e
EEEEEEEE!- t(e pr!gra6:
) (eclaration
) E8ecuti!n
) (efinin!
) =one of the abov
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne
it .i'' 7e e--icient t! p'ace stac$ e'e6ents at t(e start !- t(e 'ist 7ecause inserti!n an, re6!Aa' ta$e
EEEEEEEti6e:
) Oariable
) C!nstant
) %nconsistent
) =one of the above
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne


_______ is t(e stac$ c(aracteristic 7ut EEEEEEE.as i6p'e6ente, 7ecause !- t(e siDe 'i6itati!n !-
t(e arra<:
) isFull01&is-mpt401
) pop01& push01
) isE6pt<#% ? isFu''#%
) push01&pop01
uesti!n N!" 23 # Mar$s" 2 %

FiAe t(e ,i--erence 7et.een strict an, c!6p'ete 7inar< tree:
Ans"
A tree is a strict'< 7inar< tree i- its eac( 'ea- n!,e (as n!n-e6pt< 'e-t an, rig(t su7 trees? an,
I- t(ere are 'e-t an, rig(t su7-trees -!r eac( n!,e in a 7inar< tree is $n!.n as c!6p'ete 7inar< tree:
uesti!n N!" 24 # Mar$s" 2 %
A complete binar4 tree can be stored in an arra4. hile storin! the tree in an arra4
we leave the first position 00th inde, 1of the arra4 empt4. h4*
Ans
;ecause .e nee, a p!inter in an arra< t! p!int a p!siti!n !- n!,e !- tree: parent n!,e an, t(e
c(i',ren n!,es: In case !- (aAing a n!,e .it( 'e-t an, rig(t c(i',ren? st!re, at p!siti!n i in t(e
arra<? t(e 'e-t 2i an, t(e rig(t c(i', .i'' 7e at 2i91 p!siti!n: I- t(e Aa'ue !- i 2? t(e parent .i'' 7e at
p!siti!n 2 an, t(e 'e-t c(i', .i'' 7e at p!siti!n 2i i:e: * :T(e rig(t c(i', .i'' 7e at p!siti!n 2i91 i:e: +:
.e (aAe n!t starte, t(e 0
t(
p!siti!n: It is si6p'< ,ue t! t(e -act i- t(e p!siti!n is 0? 2i .i'' a's!
7ec!6e 0: S! .e .i'' start -r!6 t(e 1
st
p!siti!n? ign!ring t(e 0
t(
:
uesti!n N!" 25 # Mar$s" 2 %
Live the name of two (ivide and 6on@uer al!orithms.
Ans"
1: Merge s!rt
2: uic$ s!rt
3: Geap s!rt
uesti!n N!" 30 # Mar$s" 2 %
Live the effect of sorted data on Binar4 )earch.
uesti!n N!" 31 # Mar$s" 3
Live an4 three characteristics of Dnion b4 ei!ht method.
Ans"
1: T(is is a's! ca''es uni!n 7< siDe:
2: Maintain siDes #nu67er !- n!,es% !- a'' trees? an, ,uring uni!n:
3: Ma$e s6a''er tree? t(e su7tree !- t(e 'arger !ne:
*: -!r eac( r!!t n!,e i? instea, !- setting parentHiI t! -1? set it
t! -$ i- tree r!!te, at i (as $ n!,es:
uesti!n N!" 32 # Mar$s" 3 %

Gere
is an arra< !- ten integers"
+ 3 4 5 1 3 0 2 2 *
Dra. t(is arra< a-ter t(e FIRST iterati!n !- t(e 'arge '!!p in an inserti!n s!rt #s!rting -r!6
s6a''est t! 'argest%: T(is iterati!n (as s(i-te, at 'east !ne ite6 in t(e arra<J
uesti!n N!" 33 # Mar$s" 3 %

Live
4our comment on the statement that heap uses least memor4 in arra4 representation of binar4 trees.
Mustif4 4our answer in either case.
uesti!n N!" 3* # Mar$s" + %
)uppose we have the followin! representation for a complete Binar4 )earch Tree& tell the #eft and ?i!ht
child nodes and Earent node of the node D
uesti!n N!" 3+ # Mar$s" + %

-,pla
in the followin! terms:
>. 6ollision
;. #inear Erobin!
5. +uadratic Erobin!
Ans"
C!''isi!n"
it takes place when two or more ke4s 0data items1 produce the same inde,.
Linear &r!7ing
when there is a collision& some other location in the arra4 is found. This is known as linear probin!. %n
linear probin!& at the time of collisions& we add one to the inde, and check that location. %f it is also not
empt4& we add ; and check that position. )uppose we keep on incrementin! the arra4 inde, and reach at
the end of the table. e were unable to find the space and reached the last location of the arra4.
A B 6 D - F L C % M V # M = ' E + ? ) T W
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9 ;0 W
ua,ratic &r!7ing
%n the @uadratic probin! when a collision happens we tr4 to find the empt4 location at
inde, . >;. %f it is filled then we add ;; and so on.
+uadratic probin! uses different formula:
>.
Dse F0i1 G i
;
0s@uare of i1 to resolve collisions
;.
%f hash function resolves to C and a search in cell C is inconclusive& tr4
C . >
;
& C . ;;& C . 5;
uesti!n N!" 32 # Mar$s" + %

Cere
is an arra4 with e,actl4 >5 elements:
> ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5.
)uppose that we are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4
e,aminin! two or fewer numbers from the arra4.
FINALTERM EXAMINATION
Fall ;009
6)50>$ (ata )tructures
Time: >;0 min
Marks: I5
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne
The ar!uments passed to a function should match in number& t4pe and order with the parameters in the
function definition.
) True
) False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
If numbers 5, 222, 4, 48 are inserted in a queue, which one will be removed first?
) <8
) <
) ;;;
) +
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member variables called
data and ne,t=ode1. hat statement chan!es current=ode so that it refers to the ne,t node*
) current=ode ..9
) current=ode G ne,t=ode9
) current=ode .G ne,t=ode9
) current=ode G current=ode$:ne,t=ode9
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
A C!6p!un, Data Structure is the data structure which can have multiple data items of same t4pe
or of different t4pes. hich of the followin! can be considered compound data structure*
) Arra4s
) Lin$Lists
) Binar4 )earch Trees
) All of the !iven options
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne

Cere
is a small function definition:
void f0int i& int Xk1
2
i G >9
k G ;9
3
)uppose that a main pro!ram has two inte!er variables , and 4& which are !iven the value 0. Then the
main pro!ram calls f0,&419 hat are the values of , and 4 after the function f finishes*
) Both , and 4 are still 0.
) , is now >& but 4 is still 0.
) 8 is sti'' 0? 7ut < is n!. 2:
) , is now >& and 4 is now ;.
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

T(e
,i--erence 7et.een a 7inar< tree an, a 7inar< searc( tree is t(at ?
) a binar4 search tree has two children per node whereas a binar4 tree can have none& one& or two
children per node
) in binar4 search tree nodes are inserted based on the values the4 contain
) in binar4 tree nodes are inserted based on the values the4 contain
) n!ne !- t(ese
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
6ompiler uses which one of the followin! to evaluate a mathematical e@uation&
) Binar4 Tree
) Binar4 )earch Tree
) &arse Tree
) AO# Tree
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
%f there are 5F internal nodes in a binar4 tree then how man4 e,ternal nodes this binar4 tree will have*
) 5<
) ++
) 5F
) 5I
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne

if
there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) ;5
) ;<
) ;>
) 22
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne

hic
h of the followin! method is helpful in creatin! the heap at once*
) insert
) add
) update
) precu'ateD!.n #'ecture K31 page 1%
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne

The
definition of Transitivit4 propert4 is
) For all element , member of )& , ? ,
) For all elements , and 4& , ? 4 if and onl4 if 4 ? ,
) F!r a'' e'e6ents 8? < an, D? i- 8 R < an, < R D t(en 8 R D
) For all elements w& ,& 4 and K& if , ? 4 and w ? K then , ? K
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne

A
binar4 tree of = nodes has 7777777.
) #o!>0 = levels
) L!g2 N 'eAe's
) = A ; levels
) = , ; levels
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

%f
there are = elements in an arra4 then the number of ma,imum steps needed to find an element usin!
Binar4 )earch is 7777777 .
Y =
Y =
;
Y =lo!;=
) '!g2N
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


6onsider te followin! arra4
;5 >5 5 >; <0 >0 I
After the first pass of a particular al!orithm& the arra4 looks like
>5 5 >; ;5 >0 I <0
=ame the al!orithm used
Y Ceap sort
) )election sort
) %nsertion sort
Bubble sort
Question No: 15 ( Marks: 1 ) - Please choose one

%f
both pointers of the node in a binar4 tree are =D## then it will be aAan 7777777 .
) %nner node
) Lea- n!,e
) ?oot node
) =one of the !iven options
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
B4 usin! 7777777777we avoid the recursive method of traversin! a Tree& which makes use of stacks and
consumes a lot of memor4 and time.
) Binar4 tree onl4
) T(rea,e, 7inar< tree
) Ceap data structure
) Cuffman encodin!
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne

A
complete binar4 tree of hei!ht 3 has between 77777777 nodes.
) 8 to ><
) 4 t! 1+
) 8 to >F
) 8 to >I
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne

6onsi
der a min heap& represented b4 the followin! arra4:
5&<&F&I&5&>0
After insertin! a node with value >.hich of the followin! is the updated min heap*
) 5&<&F&I&5&>0&>
) 5&<&F&I&5&>&>0
) 5&<&>&5&I&>0&F
) 1?*?3?+?3?10?2 c'!se t! c!rrect 7ut c!rrect ans is 1?*?3?3?+?10?2
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider a min heap& represented b4 the followin! arra4:
>0&50&;0&I0&<0&50&80&F0
After insertin! a node with value 5>.hich of the followin! is the updated min heap*
) 10?30?20?31?*0?+0?40?20?30
) >0&50&;0&I0&<0&50&80&F0&5>
) >0&5>&;0&50&<0&50&80&F0&5>
) 5>&>0&50&;0&I0&<0&50&80&F0
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! al!orithms is most widel4 used due to its !ood avera!e time&
) Bubble )ort
) %nsertion )ort
) uic$ S!rt
) Mer!e )ort
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !ne

hic
h of the followin! statement is correct about find0,1 operation:
) A find0,1 on element , is performed b4 returnin! e,actl4 the same node that is found.
) A -in,#8% !n e'e6ent 8 is per-!r6e, 7< returning t(e r!!t !- t(e tree c!ntaining 8.
) A find0,1 on element , is performed b4 returnin! the whole tree itself containin! ,.
) A find0,1 on element , is performed b4 returnin! T?D-.
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
/(ic( !- t(e -!''!.ing state6ent is NOT c!rrect a7!ut -in, !perati!n"
)%t is not a re@uirement that a find operation returns an4 specific name& Hust that finds on two elements
return the same answer if and onl4 if the4 are in the same set.
) 'ne idea mi!ht be to use a tree to represent each set& since each element in a tree has the same root&
thus the root can be used to name the set.
) %nitiall4 each set contains one element.
) Initia''< eac( set c!ntains !ne e'e6ent an, it ,!es n!t 6a$e sense t! 6a$e a tree !- !ne n!,e
!n'<:
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne

The
following are statements related to ueues.
0i1 The last item to be added to a @ueue is the first item to be removed Fa'se state6ent
0ii1A @ueue is a structure in which both ends are not used Fa'se state6ent
0iii1The last element hasnJt to wait until all elements precedin! it on the @ueue are removed
Fa'se state6ent
0iv1 A @ueue is said to be a last$in$first$out list or #%F' data structure. Fa'se state6ent
hich of the above isAare related to normal @ueues*
) 0iii1 and 0ii1 onl4
) 0i1& 0ii1 and 0iv1 onl4
) 0ii1 and 0iv1 onl4
) N!ne !- t(e giAen !pti!ns
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne

The
ma,imum number of e,ternal nodes 0leaves1 for a binar4 tree of hei!ht C is EEEEEEE
) 2
G
) ;
C
.>
) ;
C
$>
) ;
C
.;
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne
%n complete binar4 tree the bottom level is filled from 77777777
) #eft to ri!ht
) ?i!ht to left
) =ot filled at all
) =one of the !iven options
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne

e
are !iven = items to build a heap & this can be done with 77777 successive inserts.
) =$>
) N
) =.>
) =Z;
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne

)upp
ose we had a hash table whose hash function is Sn T >;U& if the number 55 is alread4 in the hash table&
which of the followin! numbers would cause a collision*
) ><<
) ><5
) ><5
) ><8
uesti!n N!" 24 # Mar$s" 1 % - &'ease c(!!se !ne

Cere
is an arra4 of ten inte!ers:
5 5 8 9 > I 0 ; F <
The arra4 after the F%?)T iteration of the lar!e loop in a selection sort 0sortin! from smallest to lar!est1.
) 0 3 4 5 1 3 + 2 2 *
) ; F < 0 5 8 9 > I 5
) ; F < 9 > I 0 5 8 5
) 0 5 8 ; F < 9 > I 5
uesti!n N!" 25 # Mar$s" 1 % - &'ease c(!!se !ne

hat
re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4* ) The arra4
elements must form a heap.
) The arra4 must have at least ; entries.
) T(e arra< 6ust 7e s!rte,:
) The arra4Js siKe must be a power of two.
uesti!n N!" 30 # Mar$s" 1 % - &'ease c(!!se !ne

%n
case of deletin! a node from AO# tree& rotation could be prolon! to the root node.
) Nes
) N!
uesti!n N!" 31 # Mar$s" 1 %
%n mer!e sort do we need to have e,tra memor4& Hustif4 4our answer in either case.
Ces .e nee, e8tra 6e6!r< in 6erge s!rt:
uesti!n N!" 32 # Mar$s" 1 %

her
e is %norder Eredecessor of a non leaf node is present in a Binar4 )earch Tree*
uesti!n N!" 33 # Mar$s" 2 %
Cow we can search an element in )kip #ist.
uesti!n N!" 3* # Mar$s" 2 %
hat is the drawback of usin! arra4s to store Binar4 )earch Trees.
uesti!n N!" 3+ # Mar$s" 3 %

6alculate the codes of the followin! characters in table below usin! the hoffman encodin! tree&
character 6ode
=# >0000
)E >>>>
o 00>
b 0>00
i 0>0>
r >>0
uesti!n N!" 32 # Mar$s" 3 %

"For
smaller lists& linear insertion sort performs well& but for lar!er lists& @uick sort is suitable to appl4." Mustif4
wh4*
uesti!n N!" 33 # Mar$s" 3 %
Supp!se t(at .e (aAe i6p'e6ente, a pri!rit< Lueue 7< st!ring t(e ite6s in a (eap: /e are n!.
e8ecuting a re(eapi-icati!n ,!.n.ar, an, t(e !ut-!--p'ace n!,e (as pri!rit< !- *2: T(e n!,eMs
parent (as a pri!rit< !- 32? t(e 'e-t c(i', (as pri!rit< +2 an, t(e n!,eMs rig(t c(i', (as pri!rit< 22:
/(ic( state6ent 7est ,escri7es t(e status !- t(e re(eapi-icati!n:
A. The reheapification is done.
B. The ne,t step will swap the out$of$place node with its parent.
6. The ne,t step will swap the out$of$place node with its left child.
(. The ne,t step will swap the out$of$place node with its ri!ht child.
-. =one of these.
uesti!n N!" 34 # Mar$s" + %

FiAe
t.! ,i--erent reas!ns t! e8p'ain .(< t(e -!''!.ing 7inar< tree is n!t a (eap"

uesti!n N!" 35 # Mar$s" + %
Cere is an arra4 of ten inte!ers:
5 5 8 9 > I 0 ; F <
)ort the arra4 b4 usin! selection sort al!orithm and show content of arra4 after each step.
+ 3 4 5 1 3 0 2 2 *
STE&
1
0
3 4 5 1 3
+
2 2 *
STE&
2
0
1
4 5
3
3 + 2 2 *
STE&3 0 1
2
5 3 3 +
4
2 *
STE&
*
0 1 2
3
5
3 + 4 2 *
STE&+ 0 1 2 3
*
3 + 4 2
5
STE&2 0 1 2 3 *
+ 3
4 2 5
STE&
3
0 1 2 3 * +
2
4
3
5
STE&4 0 1 2 3 * + 2
3 4
5
0 1 2 3 * + 2 3 4 5
uesti!n N!" *0 # Mar$s" 10 %

A
'!ng seLuence !- A!.e's nee,s t! 7e trans6itte, e--icient'< s! a pr!gra66er ,eci,es t! use
Gu--6an enc!,ing t! enc!,e t(e A!.e's: A ,istri7uti!n c!unt stu,< !- t<pica' ,ata <ie',e, t(e
-!''!.ing -reLuenc< ta7'e:
FreLuenc< Ta7'e
c(aracter -reLuenc< Gu--6an c!,e
A 33534 E E E E E E E
E 20232 E E E E E E E
I 1+41* E E E E E E E
O 21++2 E E E E E E E
N 1032* E E E E E E E
C *53+ E E E E E E E
A% Create a Gu--6an tree t! ,eter6ine t(e 7inar< c!,es -!r eac( c(aracter:
;% Fi'' t(e c!,es int! t(e ta7'e a7!Ae:
C% Enc!,e t(e -!''!.ing seLuence EICONA
uesti!n N!" *1 # Mar$s" 10 %


6onsider the followin! tree.
a1 )how that either it is a heap or not.
b1 %f it is a heap then what t4pe of heap is it*
c1 Add <0 in the heap and convert it in ma, heap.
FINALTERM EXAMINATION
Fall ;009
6)50>$ (ata )tructures
Time: >;0 min
Marks: I5
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne

7777
777777 onl4 removes items in reverse order as the4 were entered.
) Stac$
) +ueue
) Both of these
) =one of these
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
Cere is a small function definition:
void f0int i& int Xk1
2
i G >9
k G ;9
3
)uppose that a main pro!ram has two inte!er variables , and 4& which are !iven the value 0. Then the
main pro!ram calls f0,&419 hat are the values of , and 4 after the function f finishes*
) Both , and 4 are still 0.
) , is now >& but 4 is still 0.
) 8 is sti'' 0? 7ut < is n!. 2:
) , is now >& and 4 is now ;.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
)elect the one FALSE statement about binar4 trees:
) EAer< 7inar< tree (as at 'east !ne n!,e:
) -ver4 non$empt4 tree has e,actl4 one root node.
) -ver4 node has at most two children.
) -ver4 non$root node has e,actl4 one parent.
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
-ver4 AO# is 77777777777777777
) Binar4 Tree
) 6omplete Binar4 Tree
) =one of these
) ;inar< Searc( Tree
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
)earchin! an element in an AO# tree take ma,imum 7777777 time 0where n is no. of nodes in AO#
tree1&
) #o!;0n.>1
) #o!;0n.>1 $>
) 1:** L!g2n
) >.FF #o!;n
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose that we have implemented a priority queue b4 storin! the items in a heap. e are now e,ecutin!
a reheapification downward and the out$of$place node has priorit4 of <;. The nodeJs parent has a priorit4
of I;& the left child has priorit4 5; and the nodeJs ri!ht child has priorit4 F;. hich statement best
describes the status of the reheapification.
) The reheapification is done.
) The ne,t step will interchan!e the two children of the out$of$place node.
) The ne,t step will swap the out$of$place node with its parent.
) The ne,t step will swap the out$of$place node with its left child.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne

)upp
ose 4ou implement a heap 0with the lar!est element on top1 in an arra4. 6onsider the different arra4s
below& determine the one that cannot possibl4 be a heap:
) I F 5 < 5 ; >
) I 5 F ; > < 5
) I F < 5 5 ; >
) 3 3 2 * 2 + 1
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne

%f
there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) ;5
) ;<
Y ;>
22
Less!n K 23#t(e nu67er !- interna' n!,es is N? t(e nu67er !- e8terna' n!,es .i'' 7e N91:%
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
%f there are = e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) N -1
) =.>
) =.;
) =
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is ='T the propert4 of e@uivalence relation:
) ?efle,ive
) )4mmetric
) Transitive
) Ass!ciatiAe #'ess!n n! 3*%
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne

The
definition of Transitivit4 propert4 is
) For all element , member of )& , ? ,
) For all elements , and 4& , ? 4 if and onl4 if 4 ? ,
) F!r a'' e'e6ents 8? < an, D? i- 8 R < an, < R D t(en 8 R D #'ess!n n! 3*%
) For all elements w& ,& 4 and K& if , ? 4 and w ? K then , ? K
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
Dnion is a 7777777 time operation.
) C!nstant # 'ess!n K 3+ page 11%
) Eol4nomial
) -,ponential
) =one of the !iven option
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is ='T a correct statement about Table A(T.
) %n a table& the t4pe of information in columns ma4 be different. 4es
) A ta7'e c!nsists !- seAera' c!'u6ns? $n!.n as entities: 0#esson [ 58 pa!e > 1
) The row of a table is called a record.
) A maHor use of table is in databases where we build and use tables for keepin! information.
6orrect A table consists of several columns& known as fields.
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
%n the worst case of deletion in AO# tree re@uires 777777777.
) 'nl4 one rotation
) ?otation at each non$leaf node
) ?otation at each leaf node
) R!tati!ns eLua' t! '!g2 N #'ess!n K 23%
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !n
Binar4 )earch is an al!orithm of searchin!& used with the 777777 data.
) S!rte, #'ess!n K 35%
Y Dnsorted
) Cetero!eneous
) ?andom
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !n
hich of the followin! statement is correct*
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a left child has a
TC?-A( 0in actual sense& a link1 to its %='?(-? successor.
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a ri!ht child has a
TC?-A( 0in actual sense& a link1 to its E?-'?-(? successor.
) A T(rea,e, ;inar< Tree is a 7inar< tree in .(ic( eAer< n!,e t(at ,!es n!t (aAe a rig(t c(i', (as
a TGREAD #in actua' sense? a 'in$% t! its INORDER success!r:
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a ri!ht child has a
TC?-A( 0in actual sense& a link1 to its E')T'?(-? successor.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
B4 usin! 7777777777we avoid the recursive method of traversin! a Tree& which makes use of stacks and
consumes a lot of memor4 and time.
) Binar4 tree onl4
) T(rea,e, 7inar< tree 0lesson [ ;I pa!e 51
) Ceap data structure
) Cuffman encodin!
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne

hic
h of the followin! statement is ='T true about threaded binar4 tree*
) ?i!ht thread of the ri!ht$most node points to the dummy node.
) #eft thread of the left$most node points to the dummy node.
) The left pointer of dumm4 node points to the root node of the tree.
) Le-t t(rea, !- t(e rig(t-6!st n!,e p!ints t! t(e dummy n!,e:
Lecture # 28 "The left pointer of this node is pointin to the root node of the tree while the ri!ht pointer is
seen pointin! itself i.e. to dummy node. There is no problem in doin! all these thin!s. e have put the
address of dummy node in its ri!ht pointer and pointed the left thread of the left most node towards the
dummy node. )imilarl4 the ri!ht thread of the ri!ht$most node is pointin! to the dummy node. =ow we
have some e,tra pointers whose help will make the ne!t"norder routine function properl4."
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider a min heap& represented b4 the followin! arra4:
>>&;;&55&<<&55
After insertin! a node with value FF.hich of the followin! is the updated min heap*
Y >>&;;&55&<<&55&FF
) >>&;;&55&<<&FF&55
) >>&;;&55&FF&<<&55
) >>&;;&FF&55&<<&55
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !ne

6onsi
der a min heap& represented b4 the followin! arra4:
5&<&F&I&5
After callin! the function deleteMin01.hich of the followin! is the updated min heap*
) <&F&I&5
) F&I&5&<
) *?+?2?3
) <&F&5&I
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !ne

e can build a heap in 77777777 time.
) Linear #'ecture K 30 page 4%
) -,ponential
) Eol4nomial
) =one of the !iven options
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne

)uppose we are sortin! an arra4 of ei!ht inte!ers usin! @uick sort& and we have Hust finished the first
partitionin! with the arra4 lookin! like this:\
; 5 > I 9 >; >> >0
hich statement is correct*
) T(e piA!t c!u', 7e eit(er t(e 3 !r t(e 5:
) T(e piA!t c!u', 7e t(e 3? 7ut it is n!t t(e 5:
) The pivot is not the I& but it could be the 9
) =either the I nor the 9 is the pivot.
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne

hich formula is the best appro,imation for the depth of a heap with n nodes*
) '!g #7ase 2% !- n
) The number of di!its in n 0base >01& e.!.& ><5 has three di!its
) The s@uare root of n
) n
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne

)upp
ose 4ou implement a Min heap 0with the smallest element on top1 in an arra4. 6onsider the different
arra4s below9 determine the one that cannot possibl4 be a heap:
) >F& >8& ;0& ;;& ;<& ;8& 50
) >F& ;0& >8& ;<& ;;& 50& ;8
) >F& ;<& >8& ;8& 50& ;0& ;;
) 12? 2*? 20? 30? 24? 14? 22
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne

hil
e Hoinin! nodes in the buildin! of Cuffman encodin! tree if there are more nodes with same fre@uenc4& we
choose the nodes 7777777.
) Ran,!6'<
) That occur first in the te,t messa!e
) That are le,icall4 smaller amon! others.
) That are le,icall4 !reater amon! others
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider the followin! para!raph with blanks.
A WW.WW.. is a linear list where WWWWW and WWWW take place at the
same end . This end is called the WW.WWW.
hat would be the correct fillin! the above blank positions*
) 0i1 @ueue 0ii1 insertion 0iii1 removals 0iv1 top
) 0i1 stack 0ii1 insertion 0iii1 removals 0iv1 bottom
) #i% stac$ #ii% inserti!n #iii% re6!Aa's #iA% t!p
) 0i1 tree 0ii1 insertion 0iii1 removals 0iv1 top
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne
A binar4 tree with 55 internal nodes has 7777777 links to internal nodes.
) 5>
) 32 #n-1 'in$s t! interna' n!,es%
) 55
) FF 0;n links1
A binary tree with N internal nodes has N+1 external nodes.
&r!pert<" A binary tree with N internal nodes has 2N links:
N-1 links to internal nodes and N+1 links to external nodes.
uesti!n N!" 24 # Mar$s" 1 % - &'ease c(!!se !n
hich traversal !ives a decreasin! order of elements in a heap where the ma, element is stored at the
top*
) post$order
) level$order
) inorder
) N!ne !- t(e giAen !pti!ns
uesti!n N!" 25 # Mar$s" 1 % - &'ease c(!!se !ne
hat re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4
) The arra4 elements must form a heap.
) The arra4 must have at least ; entries.
) T(e arra< 6ust 7e s!rte,: #'ecture K 34%
) The arra4Js siKe must be a power of two.
uesti!n N!" 30 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is a non linear data structure*
) #inked #ist
) )tack
) +ueue
) Tree #'ecture K 11 page *%
Luesti!n N!" 31 # Mar$s" 1 %
%f a Binar4 Tree has = internal nodes what are the no. of e,ternal nodes in it.
. Less!n K 23#t(e nu67er !- interna' n!,es is N? t(e nu67er !- e8terna' n!,es .i'' 7e N91:%
uesti!n N!" 32 # Mar$s" 1 %

hat
is meant b4 )4mmetr4 in e@uivalence relations*
S!':> S<66etr< in eLuiAa'ence re'ati!ns 6ean -!r a'' e'e6ents 8 an, <? 8 R < i- an, !n'< i- < R 8
uesti!n N!" 33 # Mar$s" 2 %

Cow
heap sort works to sort a set of data.
uesti!n N!" 3* # Mar$s" 2 %

Cow we can appl4 Find operation on elements combined throu!h Dnion operation.
uesti!n N!" 3+ # Mar$s" 3 %
Cow we can use concept of e@uivalence relations to !enerate a MaKe.
uesti!n N!" 32 # Mar$s" 3 %
Supp!se .e are s!rting an arra< !- eig(t integers using a s!6e Lua,ratic s!rting a'g!rit(6: A-ter
-!ur iterati!ns !- t(e a'g!rit(6Ms 6ain '!!p? t(e arra< e'e6ents are !r,ere, as s(!.n (ere"\
2 * + 3 4 1 3 2
/(ic( state6ent is c!rrect1 #N!te" Our se'ecti!ns!rt pic$s 'argest ite6s -irst:%
A. The al!orithm mi!ht be either selectionsort or insertionsort.
B. The al!orithm mi!ht be selectionsort& but it is not insertionsort.
C: T(e a'g!rit(6 is n!t se'ecti!ns!rt? 7ut it 6ig(t 7e inserti!ns!rt: #C!rrect%
(. The al!orithm is neither selectionsort nor insertionsort.
-. =one of these.
uesti!n N!" 33 # Mar$s" 3 %
Cow man4 leaf and non$leaf nodes are present in a complete binar4 tree if its depth is I *
S!'uti!n"
Lea- n!,es > 2O3>124
N!n-'ea- n!,es >123
uesti!n N!" 34 # Mar$s" + %
%f we insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish balance*
Mustif4 4our answer.\
uesti!n N!" 35 # Mar$s" + %
/rite ,!.n t(e C99 c!,e -r!6 Se'ecti!n S!rt A'g!rit(6:
uesti!n N!" *0 # Mar$s" 10 %
6onsider the followin! data:
t(e cat in t(e (at
a1 Build fre@uenc4 table for the above data.
b1 6reate a Cuffman tree to determine the binar4 codes for each character.
c1 hat will be the code of each letter*
a1
c%
uesti!n N!" *1 # Mar$s" 10 %
C(aracter FreLuenc<
c >
i >
n >
e ;
a ;
h 5
t <
sp <
C(aracter C!,e
c 0000
i 000>
n 00>0
e 00>>
a 0>0
h 0>>
t >0
sp >>


)uppose we have build a )kip list .=ow we want to add and remove items from the list .Live Al!orithms
for insert #ite6% and ,e'ete #ite6% methods of the )kip #ist.
S!'uti!n"
/(en .e are g!ing t! insert #a,,% an ite6 #x,0% int! a s$ip 'ist? .e use a ran,!6iDe, a'g!rit(6: /e
sen, t(e ite6 in a pair:
insert
To insert an item 0x& o1 into a skip list& we use a randomiKed al!orithm:
] e repeatedl4 toss a coin until we !et tails& and we denote with i the number of times the
coin came up heads
] %f i h& we add to the skip list new lists h.>& W & i .>& each containin! onl4 the two
special ke4s
] e search for x in the skip list and find the positions !0& !> & W& !i of the items with
lar!est ke4 less than x in each list 0& >& W & i
] For " 0& W& i& we insert item 0x& o1 into list " after position !"
,e'ete
To remove an item with ke4 x from a skip list& we proceed as follows:
] e search for x in the skip list and find the positions !0& !> & W& !i of the items with ke4
x& where position !" is in list "
] e remove positions !0& !> & W& !i from the lists 0& >& W & i
] e remove all but one list containin! onl4 the two special ke4
CS301 Solved Current paper
MCQs was from past papers
What is the difference between call by value and call by reference?
!nswer"
Call by value"
In case of call by value, a copy of object is made and placed at
the time of function calling in the activation record. Here the copy constructor is used
to make a copy of the object. If we dont want the function to change the parameter
Without going for the use of time, memory creating and storing an entire copy of, it is
Advisable to use the reference parameter as const.
Call by reference"
y using the references, we are not making the copy. !oreover, with the const keyword, the function
cannot change the object. "he calling function has read only access to this object. It can use this
object in the computation but can not change it.
What is a pre#order traversal?
!nswer"
$he first of these three is %&' (' )*' also called as preorder traversal+ ,n preorder traversal the root
node comes first then left sub trees node and ri-ht sub trees occur+
#edraw the given tree and write balance of it. $
Chapter " 1. /a-e no 00
A code was given and we have to tell what the recursive function is doing. %
/a-e " 11.
Chapter " 11
&' integer values was given and we have to draw a binary search tree. "hen delete a node () from it
and redraw the tree. )
(* (% () *+ )$ (( ), %) (+ )( --I suppose numbers
S2(3$,2&"
68
63
65
89 52
66
54
69
.eleted.. ()
56 35
68
/alues were given and we have to draw A/0 tree after balancing it. )
Chapter " 1. pa-e no 00
i1 2ueue is a linear data structure. .iscuss
! 4ueue is a linear data structure into which items can only be inserted at one end and
removed from the other+ ,n contrast to the stac5' which is a (,62 %(ast ,n 6irst 2ut*
structure' a 4ueue is a 6,62 %6irst ,n 6irst 2ut* structure+
ii1 A/0 #otation
/a-e no 0 71 chapter no 0
iii1 Insert &$ in following A/0 tree
/a-e no "1. chapter no 0
63
89
52
66
54
69
56 35
3ubject4 !y cs %'& paper
------------
5!y todays paper 63%'& data structure1
3hort 7uestions4
Write transversal types of 3".
!&S" /reorder' in order and post order traversal
How can dangling reference problem be avoided8
!&S"
$o avoid dan-lin- reference' dont return the reference of a local variable
%transient* from a function+
.raw complete binary tree containing four nodes and three levels.
Chapter no 11 pa-e no 13
3nable to draw+
$he numbers of nodes at level three should be four+
What is the output of the following program8
9include
9include
Int val!inus%5int:rgval1
!nswer"
8 $ype9 findMin% * const:
$his method is used to find the minimum data value in the binary tree+
$his will find minmum number 3 in binary tree+
What is the output of the following program8
9include
9include
Int val!inus&5int:rgval1
!nswer"
$his will find minmum number 1 in binary tree+
&'',;',&&',(',*',)',&$',&)',*),*;
&. $. provide A/0 finaly for the following inorder and post order
elements
$. Inorder 4- 06A.<=
%. >ost order 4- 06.=<A
!""
#" !!"
$" %"
&
!'"
!("
%(
%#
)
* +
,
;0 M6+)& ; @uestionsG ;& ; marks& ; @uestions G 5& 5 marks& ; @uestions G 5&5 marks mostl4
mc@s from past papers 0 His main reference bhi di4a howa hai mc@s ka1.
)DbHective portion :
+: hei!ht of a tree& balance of a node 05 marks1
+: how we de!enerate a binar4 search tree* 05 marks1
e de!enerate a binar4 search tree after balancin! it. This new tree is purposed to sa4 APL tree
.(ic( (as t(e sa6e attri7utes a 7inar< searc( tree !n'< 2 ,i--erent p!ints
1% T(e (eig(t !- 'e-t su7tree an, rig(t su7 trees is at 6!st 1
2% T(e (eig(t !- e6pt< su7 tree is #-1%:
In APL tree t(e 7a'ance !- n!,es s(!u', 7e 0?1?-1
+: binar4 search tree !iven tha aur mH4 0i1 post order 0ii1 level order batana tha bss 05 marks1
+: aur aik @uestion tha k values !uven thee tau uski dia!ram banani thee AO# tree main Hust
dia!ram like values >0&>5&>F&>I&F0&I0&80&90&95&9I etc
-
+: delete a node leaf in a tree && then in B)T how man4 pointers are used to =D## it** is tarha
kar k kuch @uestion tha 0; marks1
T(e p!inter passe, t! t(e -uncti!n is p!inting T! NNLL: In case it is NNLL? t(ere is n!
n!,e t! traAerse an, t(e 6et(!, .i'' return
+: aur aik @uestion aisa tha His main diar!ram !iven thee aur batan tha k 4eh konsa tree hai for
e,ample simple tree& binar4 tree& bst& AO#& strictl4 binar4 tree etc aur issi ka aik part aur tha k
nodes bhi batani thee k total nodes kitni use ho rahi hain dia!ram main oka4 ; marks 0 > for tree
name and > for total nodes** clear ho !a4a sab ok enHo4 karo
6+s were from past papers almost I0T. ; marks @uestions are:
Cow we can delete a node havin! two childs*
This is 6ase no three of deletion . %f we have two childs then we will find out the inorder
successor of that parent node that is to be deleted in the ri!ht subtree and link it to that parent
node then the node will be deleted and inorder successor will take the place of that node.
)uppose , and 4 are int variable then write two statements which show two reference variables a
and b referencin! , and 4.
Int Q A>8R
IntQ ;> <R
pro!ram tha bnene ko
write the details o# $i%en statements.
&a'. int x(
int ) y * + x(
,ere y is a !ointer to the re#eren-e %ariable x that re#erred to y !ointer itsel# these are not the
a-tual ob"e-ts themsel%es
&b'. int x(
int +y * x(
.he y is re#eren-e %ariable re#eren-in$ to the x.
&-'. int x(
int y * x(
The value of 4 will be e@ual to ,.
Cow to calculate hei!ht of tree
6onstruct binar4 tree with values 59&;0&;;&55&>F&55&>8 and then delete ;;
(elete node from bst
Benefit and s4nta, of reference
The s4nta, we are usin! here is 6.. specific& like we are sendin! a parameter b4 pointer usin!
X si!n. y using the references, we are not making the copy. !oreover, with the const keyword, the
function cannot change the object. "he calling function has read only access to this object. It can use
this object in the computation but can not change it.
int x(
int +y * x(
.y today paper of cs/"!
0!1 *escribe main disad2antage of -3& tree4
For making it a balanced one, we have to carry the heigh computations
!hile dealing with "#$ trees, we have to keep the in%ormation o% balance
%actor o% the nodes along with the data o% nodes
0'1 *escribe only two cases of deletion of nodes in the BST4
0/1 Brie5y explain following..6eference 2ariable, const 7eyword and *angling
6eference4
-nswer1 89age !:%;
)onst 7eyword
The const 7eyword is used for something to be constant. The actual meanings
depend on where it occurs but it
generally means something is to held constant. There can be constant functions,
constant 2ariables or parameters
etc.
6eference 2ariable
The references are pointers internally, actually they are constant pointers. <ou
cannot perform any 7ind of
arithmetic manipulation with references that you normally do with pointers.
*angling reference
The pointer of the ob=ect 8when ob=ect has already been deallocated or released; is
called dangling pointer.
0>1*raw complete tree of f2e nodes4
.
0(1 )onstruct a tree of !(,!#,!%,'!,'/,'(,/! nodes
0$1 Tree was gi2en and we ha2e to write its tra2ersal methods pre and post order
Which cases of insertion in A/0 re7uire double rotations to make tree
balance8
An insertion into right subtree of the left child of ..
An insertion into left subtree of the right child of ..
FINALTERM EXAMINATION
Fa'' 2005
CS301- Data Structures
&uestion 'o( 3) * +arks( ) ,

(escribe the conditions for second case of deletion in AO# Trees.

&uestion 'o( 32 * +arks( ) ,

hat is Table abstract data t4pe.

&uestion 'o( 33 * +arks( 2 ,

Cow
we can !enerate a maKe .Live an al!orithm.

&uestion 'o( 34 * +arks( 2 ,


?epresent the followin! Binar4 tree usin! arra4 representation.

&uestion 'o( 35 * +arks( 3 ,


hat is an -@uivalent relation* Live an4 two e,amples.

&uestion 'o( 36 * +arks( 3 ,

"For
smaller lists& linear insertion sort performs well& but for lar!er lists& @uick sort is suitable to appl4." Mustif4
wh4*
&uestion 'o( 3- * +arks( 3 ,

Cow
man4 leaf and non$leaf nodes are present in a complete binar4 tree if its depth is I *

&uestion 'o( 38 * +arks( 5 ,


Re6!Ae t(e s6a''est e'e6ent -r!6 t(e -!''!.ing arra< .(ic( represents a 6in-(eap:
!rigina' 6in-(eap 1 3 2 + * 4 5 10 3
an, s(!. t(e resu'tant (eap in t(e -!r6 !- arra< as s(!.n 7e'!.?

&uestion 'o( 39 * +arks( 5 ,

Cere
is an arra4 with e,actl4 >5 elements:
> ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5.
)uppose that we are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4
e,aminin! two or fewer numbers from the arra4.

&uestion 'o( 4. * +arks( ). ,

a1
rite 6.. al!orithm for Binar4 )earch
int is#resent$int %arr& int 'al& int ()
*
int lo+ , -.
int hih , ( / 0.
int mid.
+hile $ lo+ 1, hih )
*
mid , $ lo+ 2 hih )32.
if $arr4mid5 ,, 'al)
return 0. 33 found6
else if $arr4mid5 1 'al)
lo+ , mid 2 0.
else
hih , mid / 0.
7
return -. 33 not found
b1 6onsider the followin! arra4 of values9 show how the binar4 search al!orithm would find the value -/.
6learl4 showAe,plain 4our work9 that is& show the values of start& end& etc. for each step of the al!orithm.

&uestion 'o( 4) * +arks( ). ,


)how the result of followin! se@uence of instructions
Dnion0>&;1
Dnion05&<1
Dnion05&51
Dnion0>&I1
Dnion05&F1
Dnion08&91
Dnion0>&81
Dnion05&>01
Dnion05&>>1
Dnion05&>;1
Dnion05&>51
Dnion0><&>51
Dnion0>F&>I1
Dnion0><&>F1
Dnion0>&51
Dnion0>&><1
hen the unions are performed b4 hei!ht
N!te" Nou have to show onl4 Final tree& =o need to show all steps.
FINALTERM EXAMINATION
Fall ;009
6)50>$ (ata )tructures
uesti!n N!" 31 # Mar$s" 1 %


%f a Binar4 Tree has = internal nodes what are the no. of e,ternal nodes in it.
)ol. The =o. of e,ternal nodes will be N91
uesti!n N!" 32 # Mar$s" 1 %


hat is meant b4 )4mmetr4 in e@uivalence relations*
S!': )4mmetr4 in e@uivalence relations mean for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
uesti!n N!" 33 # Mar$s" 2 %


Cow heap sort works to sort a set of data.
uesti!n N!" 3* # Mar$s" 2 %


Cow we can appl4 Find operation on elements combined throu!h Dnion operation.
uesti!n N!" 3+ # Mar$s" 3 %


Cow we can use concept of e@uivalence relations to !enerate a MaKe.
uesti!n N!" 32 # Mar$s" 3 %


Supp!se .e are s!rting an arra< !- eig(t integers using a s!6e Lua,ratic s!rting a'g!rit(6: A-ter
-!ur iterati!ns !- t(e a'g!rit(6Ms 6ain '!!p? t(e arra< e'e6ents are !r,ere, as s(!.n (ere"
2 * + 3 4 1 3 2
/(ic( state6ent is c!rrect1 #N!te" Our se'ecti!ns!rt pic$s 'argest ite6s -irst:%
A: T(e a'g!rit(6 6ig(t 7e eit(er se'ecti!ns!rt !r inserti!ns!rt:
;: T(e a'g!rit(6 6ig(t 7e se'ecti!ns!rt? 7ut it is n!t inserti!ns!rt:
C: T(e a'g!rit(6 is n!t se'ecti!ns!rt? 7ut it 6ig(t 7e inserti!ns!rt: #C!rrect%
D: T(e a'g!rit(6 is neit(er se'ecti!ns!rt n!r inserti!ns!rt:
E: N!ne !- t(ese:
uesti!n N!" 33 # Mar$s" 3 %


Cow man4 leaf and non$leaf nodes are present in a complete binar4 tree if its depth is I *
uesti!n N!" 34 # Mar$s" + %


%f we insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish balance*
Mustif4 4our answer.
uesti!n N!" 35 # Mar$s" + %


/rite ,!.n t(e C99 c!,e -r!6 Se'ecti!n S!rt A'g!rit(6:
uesti!n N!" *0 # Mar$s" 10 %


6onsider the followin! data:
t(e cat in t(e (at
d1 Build fre@uenc4 table for the above data.
e1 6reate a Cuffman tree to determine the binar4 codes for each character.
f1 hat will be the code of each letter*
uesti!n N!" *1 # Mar$s" 10 %


)uppose we have build a )kip list .=ow we want to add and remove items from the list .Live Al!orithms
for insert #ite6% and ,e'ete #ite6% methods of the )kip #ist.
F/'"$012+ 13"+/'"0/4'
+all '"":
)S/"!? *ata Structures
&uestion 'o( 3) * +arks( ) ,


In merge sort do we need to ha2e extra memory, =ustify your answer in either
case.
&uestion 'o( 32 * +arks( ) ,


@here is Inorder 9redecessor of a non leaf node is present in a Binary Search
Tree4
&uestion 'o( 33 * +arks( 2 ,


Aow we can search an element in S7ip &ist.
&uestion 'o( 34 * +arks( 2 ,


@hat is the drawbac7 of using arrays to store Binary Search Trees.
&uestion 'o( 35 * +arks( 3 ,


)alculate the codes of the following characters in table below using the hoBman
encoding tree,
charact
er
code
N&
S9
o
b
i
r
&uestion 'o( 36 * +arks( 3 ,


C+or smaller lists, linear insertion sort performs well, but for larger lists, uic7 sort is
suitable to apply.C Dustify why4
&uestion 'o( 3- * +arks( 3 ,


5uppose that we have implemented a priority 6ueue by storing the items
in a heap !e are now e7ecuting a reheapi8cation downward and the out9
o%9place node has priority o% 42 0he node:s parent has a priority o% -2, the
le%t child has priority 52 and the node:s right child has priority 62 !hich
statement best describes the status o% the reheapi8cation
" 0he reheapi8cation is done
; 0he ne7t step will swap the out9o%9place node with its parent
< 0he ne7t step will swap the out9o%9place node with its le%t child
= 0he ne7t step will swap the out9o%9place node with its right child
1 'one o% these
&uestion 'o( 38 * +arks( 5 ,


>ive two di?erent reasons to e7plain why the %ollowing binary tree is not a
heap(

&uestion 'o( 39 * +arks( 5 ,


Aere is an array of ten integers1
( / % : ! # " ' $ >
Sort the array by using selection sort algorithm and show content of array after
each step.
&uestion 'o( 4. * +arks( ). ,


" long se6uence o% vowels needs to be transmitted e@ciently so a
programmer decides to use Au?man encoding to encode the vowels "
distribution count study o% typical data yielded the %ollowing %re6uency
table
Fre6uency 0able
character %re6uency Au?man code
" 339-8 B B B B B B B
1 2.6-6 B B B B B B B
/ )58)4 B B B B B B B
4 2)552 B B B B B B B
C ).324 B B B B B B B
D 49-5 B B B B B B B
", <reate a Au?man tree to determine the binary codes %or each
character
;, Fill the codes into the table above
<, 1ncode the %ollowing se6uence 1/D4C"
&uestion 'o( 4) * +arks( ). ,


)onsider the following tree.
d; Show that either it is a heap or not.
e; If it is a heap then what type of heap is it4
f; -dd >" in the heap and con2ert it in max heap.
FINALTERM EXAMINATION
Fa'' 2005
CS301- Data Structures #Sessi!n - *%
uesti!n N!" 31 # Mar$s" 1 %


hich is the initial step while usin! Cuffman encodin! when sendin! te,t messa!e from one point to the
other*

uesti!n N!" 32 # Mar$s" 1 %


hat is ma,imum level difference between two leaf nodes in a Ceap*Mustif4 4our answer as well.

uesti!n N!" 33 # Mar$s" 2 %

Cow
we can appl4 Find operation on elements combined throu!h Dnion operation.

uesti!n N!" 3* # Mar$s" 2 %

hat is the drawback of usin! arra4s to store Binar4 )earch Trees.

uesti!n N!" 3+ # Mar$s" 3 %

Live
an4 three properties of complete binar4 tree.

uesti!n N!" 32 # Mar$s" 3 %


hen Cashin! is ='T suitable*

uesti!n N!" 33 # Mar$s" 3 %

Live
an4 three important facts about buildin! a heap.

uesti!n N!" 34 # Mar$s" + %

%f we
insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish balance* Mustif4
4our answer.

uesti!n N!" 35 # Mar$s" + %

Cere
is an arra4 of ten inte!ers:
5 5 8 9 > I 0 ; F <
)how the first three mer!in! steps for Mer!e sort on this arra4.

uesti!n N!" *0 # Mar$s" 10 %
>.


Dra. a ne. (eap t(at is create, 7< inserting 42 int! t(e -!''!.ing (eap"
2: Is t(e -!''!.ing a (eap tree1 E8p'ain <!ur ans.er 7rie-'<:

uesti!n N!" *1 # Mar$s" 10 %


De'ete 3 in t(e -!''!.ing arra< .(ic( represents a 6in-(eap: S(!. pr!cess steps 7< ,ra.ing (eap
tree:
5 5 9 F 8 ;0 >0 >; >8 9
5 marks
C*ata StucturesC
)hracter +reuency
C '
sp !
d !
a '
t /
s '
r '
u '
c !
e !
nl !
6ode correction 5 marks
%nt isEresent0int /arr&int val&int =1
2
%nt #owG09
%nt hi!h G=$>9
%nt mid9
hile0low8Ghi!h 1
2
Mid G 0low.hi!h 1A;9
%f 0arrQmidRGGval1
?eturn >9AAfound^
-lse if 0 arrQmidR8val1
#owGmid.>9
-lse hi!h G mid$>9
3
?eturn09AAnot found
.imum heap mien se !> delete 7rna tha , miene 7rlya tha =ust lin7 7rna tha orpast
7rna tha time
End ho gya mare ( mar7s miss ho gy hien isay
mien se 7ey > 7o delete 7rna tha ( mar7s
Then balance 7rna tha -3& tree 7o
Total (' 0s
>" mc ("F from boo7 and ("F from .aaG fles
!(
!#
$:
'"
''
'(
$$ '#
/'
//
M4 6)50> paper dated ;< feb ;0>5
Total @uestions 5;
<0 M6+_s mostl4 from past paers speciall4 4e wal4 ;
%f
there are = e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this
binar4 tree*
%f
there are = internal nodes in a binar4 tree then what will be the no. of e,ternal nodes in this
binar4 tree*
baki < @uestions ; marks k
< @uestions of 5 marks
and < @uestions 5 marks.
Ceap and it_s t4pe.
)uppose we have the followin! representation for a complete Binar4 )earch Tree& tell the #eft
and ?i!ht child nodes and Earent node of the node D

A B 6 D - F L C % M V # M = ' E + ? ) T W
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9 ;0 W

%n$order$ pre$order and post$order k ; @uestions th4.
; marks ka @uestion tha k in k name likhn4 hen
5 marks ka @uestion tha k ek tree ko in order and pre order me likhna tha.
e@uivalence class ki properties 0 refle,ive& s4mmetr4 v!era1 k name likhna tha
+: For smaller lists& linear insertion sort performs well& but for lar!er lists& @uick sort is suitable
to appl4." Mustif4 wh4* 5 marks
A: )ince for smaller lists number of comparisons and interchan!e 0if needed1 decreases radicall4
in insertion sort than @uick sort. For lar!er lists& opposite occurs in both sortin! techni@ues.
=lo! base ;0=1 al!orithm 0divide and con@uer I1
Mer!e sort
+uick sort
Ceap sort

+: hat is an -@uivalent relation* ; marks pa!e <;<
A: Two cells are e@uivalent if the4 can be reached from each other.
+: hat is meant b4 SA(TU* ; marks.
A: The table& Abstract data t4pe& is a collection of rows and columns of information.
Operati!n na6e"
%nsert
Find
?emove
I6p'e6entati!n !- Ta7'e
o Dnsorted )e@uential Arra4
o )orted )e@uential Arra4
+: hat is stack*
A: )tack is a collection of elements arran!ed in a linear orderU
+: what are the characteristic of a !ood hash function*
A: %f the ke4s are inte!ers& ke4TT is !enerall4 a !ood hash function& unless the data has some
undesirable features. For e,ample& if T G >0 and all ke4s end in Keros& then ke4TT G 0 for all
ke4s. )uppose we have emplo4ee %( i.e. an inte!er. The emplo4ee %( ma4 be in hundreds of
thousand. Cere the table siKe is >0. %n this case& we will take mod of the emplo4ee %( with the
table siKe to !et the hash value. Cere& the entire emplo4ee %(s end in Kero. hat will be the
remainder when we divide this number with >0* %t will be 0 for all emplo4ees. )o this hash
function cannot work with this data. %n !eneral& to avoid situations like this& T should be a prime
number.
+: !ive an4 three facts about buildin! heap*
A: methods of heap
,ecreaseSe<#p? ,e'ta%
increaseSe<#p? ,e'ta%
re6!Ae#p%
+: wh4 binar4 search cannot be used for link list*
A: Because it store sorted data.
+: Cow can we appl4 F%=( operation on elements combined throu!h union operation*
Ans.er"- #&age 352%
e !ive an element to the find method and it returns the name of the set.
+: )ort the list Q; 9 I 5 8Rthrou!h insertion sort al!orithm show each step.
Ea!e 9 moaaK file
+: what is difference bAw AO# and binar4 tree*
A: A binar4 search tree has two children per node whereas a binar4 tree can have none& one& or two
children per node
" /(at are ,iAi,e n c!nLuer s!rting 6et(!,s1 N'!g 7ase 2 N
A" Three al!orithm fall under divide and con@uer
mer!e sort
@uick sort
heap sort
" .(at are pr!perties !- eLuiAa'ence set
Ans" A binar4 relation ? over a set ) is called an e@uivalence relation if it has followin!
properties`:
>. ?efle,ivit4: for all element , )& , ? ,
;. )4mmetr4: for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
5. Transitivit4: for all elements ,& 4 and K& if , ? 4 and 4 ? K then , ? K
-,ample9 sets of peoples &electric circuit domain
" C!nAert t(e giAen in-i8 -!r6 t! p!st-i8 -!r6:
A9;TC-DOE-F
Ans.er" AB.6A($-F $Z
" G!. .e can i6p'e6ent Ta7'e ADT using Lin$e, List
A" #ist linked list is one choice to implement table abstract data t4pe. For unsorted elements& the
insertion at front operation will take constant time. But if the data inside the list is kept in sorted
order then to insert a new element in the list& the entire linked list is traversed throu!h to find the
appropriate position for the element.
" I- .e a''!. assign6ent t! c!nstants .(at .i'' (appen1
A" )uppose aa` has the value number 5. =ow we assi!ned number ; the number 5 i.e. all the
number ; will become number 5 and the result of ; . ; will become F. Therefore it is not
allowed.
" G!. (eap s!rt .!r$s t! s!rt a set !- ,ata:
A" Min heap and ma, heap are used to sort the data. Min heap convert the data in ascendin!
sorted order and ma, heap convert the in descendin! order.
" FiAe <!ur c!66ent !n t(e state6ent t(at (eap uses 'east 6e6!r< in arra<
representati!n !- 7inar< trees: Uusti-< <!ur ans.er in eit(er case:
A" A heap is a complete binar4 tree& so it is eas4 to be implemented usin! an arra4 representation
%t is a binar4 tree with the followin! properties:$
Eropert4 >: it is a complete binar4 tree
Eropert4 ;: the value stored at a node is !reater or e@ual to the values stored at the
children
From propert4 ; the lar!est value of the heap is alwa4s stored at the root
" G!. .e can use c!ncept !- eLuiAa'ence re'ati!ns t! generate a MaDe:
A" Al!orithm is as follows
?andoml4 remove walls until the entrance and e,it cells are in the same cell
?emoval of the wall is the same as doin! a union operation
(o not remove randoml4 chosen wall if the cells it separates are alread4 % the same set.
" 2 5 + 0 * 1 3 3 2 S(!. t(e -irst -iAe 6erging steps -!r Merge s!rt !n t(is arra<:
Ea!e >5 moaaK file
" /(at is DisV!int Sets1 E8p'ain .it( an e8a6p'e:
Ans" DisV!int sets - Two sets are disHoint if the4 have no elements in common. -,ample:$
)uppose there are man4 people around 4ou. Cow can we separate those who are related to each
other in this !atherin!* e make !roups of people who are related to each other. The people in
one !roup will sa4 that the4 are related to each other. )imilarl4 we can have man4 !roups. )o
ever4 !roup will sa4 that the4 are related to each other with famil4 relationship and there is no
!roup that is related to an4 other !roup. The people in the !roup will sa4 that there is not a sin!le
person in the other !roup who is related to them.
" In t(e arra< representati!n !- uni!n .(at represents -11
A" This shows that this node has no parent. Moreover& this node will be a root that ma4 be a
parent of some other node
" /(ic( ,ata structure is 7est -!r pri!rit< Lueue1
A" The use of priorit4 @ueue with the help of heap is a maHor application. The priorit4 @ueue is
itself a maHor data structure& much$used in operatin! s4stems. )imilarl4 priorit4 @ueue data
structure is used in network devices especiall4 in routers. Ceap data structure is also emplo4ed in
sortin! al!orithms
" G!. .e can app'< Nni!n !perati!n !n e'e6ents initia''< in ,i--erent sets1
A" To e,ecute the union operation in two sets& we mer!e the two trees of these sets in such a
manner that the root of one tree points to the root of other. )o there will be one root& resultin! in
the mer!er of the trees.
" /(at is S$ip 'ist1
" /rite t.! c(aracteristics !- s$ip 'ist1 2 6ar$s
Ans.er"- #&age **21 A skip list for a set ) of distinct 0ke4& element1 items is a series of lists )0&
)> & W & )h such that
] -ach list )i contains the special ke4s .b and $b
] #ist )0 contains the ke4s of ) in non$decreasin! order
] -ach list is a subse@uence of the previous one& i.e.& )0 H )> H W H )h
] #ist )h contains onl4 the two special ke4s
" /(at is t(e .!rst case !- W-in,M !perati!n !- t(e 'in$e, 'ist1
A: orst case of the find method is that it has to search the entire list from be!innin! to end.
" /(at is t(e ,ra.7ac$ !- using arra< t! st!re X;inar< Searc( TreesM1
A"- #&age 21% The drawback of usin! is the limitations that arra4 bein! of fi,ed siKe can onl4
store a fi,ed number of elements. Therefore& no more elements can be stored after the siKe of the
arra4 is reached.
" FiAe an< 3 c(aracteristics !- uni!n 7< .eig(t 6et(!,1
A"- #&age *04% Followin! are the salient characteristics of this method:
Maintain siKes 0number of nodes1 of all trees& and durin! union.
Make smaller tree& the sub$tree of the lar!er one.
%mplementation: for each root node i& instead of settin! parentQiR to $>& set it to $k if tree
rooted at i has k nodes.
" Geig(t !- a tree is + -in, su6 !- (eig(ts1
A: Cei!ht G 5
=odes G ;Zh G ;Z5 G5;
)um of =odes G =$0h.>1G 5;$05.>1 G 5;$F G ;F
" G!. can .e searc( an e'e6ent in s$ip 'ist1
A: e search for a ke4 , in the followin! fashion:
e start at the first position of the top list
] At the current position p& we compare , with 4 ke40after0p11
] , G 4: we return element0after0p11
] , : 4: we cscan forward
] , 8 4: we cdrop down
] %f we tr4 to drop down past the bottom list& we return ='7)D6C7V-N
" /(en (as(ing is NOT suita7'e1
A" Cash tables are not so !ood if there are man4 insertions and deletions& or if table traversals
are needed d in this case& AO# trees are better
" FiAe an< t(ree i6p!rtant -acts a7!ut 7ui',ing a (eap:1
A" Followin! are some of the important facts about buildin! a heap.
e )uppose we are !iven as input = ke4s 0or items1 to build a heap of the ke4s.
e 'bviousl4& this can be done with = successive inserts.
e -ach call to insert will either take unit time 0leaf node1 or lo!;= 0if new ke4 percolates all the
wa4 up to the root1.
e The worst time for buildin! a heap of = ke4s could be =lo!;=.
e %t turns out that we can build a heap in linear time.
e )uppose we have a method percolate(own0p1 that moves down the ke4 in node p
downwards.
e This is what happens in deleteMin.e have used the word ke4s in the first point.
" E8p'ain t(e -!''!.ing ter6
ans.er"
>.. 6ollision
;.. #inear probin!
5.. +uadratic probin!..
C!''isi!n" hen two values hash to the same arra4 location& this is called a collision8.
Linear &r!7ing hen there is a collision& some other location in the arra4 is found. This is known as
linear probin!. %n linear probin!& at the time of collisions& we add one to the inde, and check that
location. %f it is also not empt4& we add ; and check that position. )uppose we keep on incrementin!
the arra4 inde, and reach at the end of the table. e were unable to find the space and reached the
last location of the arra4.
ua,ratic &r!7ing %n the @uadratic probin! when a collision happens we tr4 to find the empt4
location at inde, . >Z;. %f it is filled then we add ;Z; and so on.
+uadratic probin! uses different formula:
>. Dse F0i1 G i; 0s@uare of i1 to resolve collisions
;. %f hash function resolves to C and a search in cell C is inconclusive& tr4
C . >;& C . ;;& C . 5;
" FiAe !ne e8a6p'e !- Gas(ing
A" Cashin! can be used to store the data. )uppose we have a list of fruits. The names of Fruits are in
strin!. The ke4 is the name of the fruit. e will pass it to the hash Function to !et the hash ke4.
Cash6ode 0"apple"1 G 5
e pass it to the strin! capple . ?esultantl4& it returns a number 5.
" /!rst case !- se'ecti!n s!rt1
A" worst case occurs if the arra4 is alread4 sorted in descendin! order. =onetheless& the time re@uire
b4 selection sort al!orithm is not ver4 sensitive to the ori!inal order of the arra4 to be sorted
" C99 c!,e -!r ,!u7'< 'in$ 'ist1 + 6ar$s
A" Ea!e ;5 moaaK file
" Gere is an arra< .it( e8act'< 1+ e'e6ents"
1 2 3 * + 2 3 4 5 10 11 12 13 1* 1+:
Supp!se t(at .e are ,!ing a 7inar< searc( -!r an e'e6ent: In,icate an< e'e6ents t(at .i''
7e -!un, 7<
e8a6ining t.! !r -e.er nu67ers -r!6 t(e arra<: #Mar$s" +%
Ans.er"
e see the data in arra4 it is sorted so performin! a B) is !ood. =ow consider arra4
A G 2>& ;& 5& < & 5& F& I& 8& 9& >0& >>& >;& >5& ><& >53
As binar4 search starts first element we e,amine mid element which is at inde,
arra4)iKeA;0i.e. >5A; G I1& which is I. =ow if the element is to compare is less then I we
will consider the left part of arra4 from the mid which is 2>& ;& 5& <& 5& F3. =ow a!ain
choose the mid element& which is 5 and campare with it. %f less then divide the arra4
a!ain.
6ome to ?i!ht side we have the followin! arra428& 9& >0& >>& >;& >5& ><& >53 if we divide
it in middle we !et the element >;. Based on value a!ain comparison divide the arra4
a!ain and do the same steps a!ain
)o the possible numbers are if we e,amine the arra4 are
I& 5& >& >;& 9
For more clarit4 see e,ample from handout !iven on pa!e <5>.
" uni!n !perati!n: Fr!6 n!tes" E8a6p'e !n pageK *00
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
what is table abstract data t4pe*
Assume that 4ou have a sorted linked list.write a function that inserts a node at proper place in
sorted linked list.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
plese answer
hat will be the output of followin! link list function.*
Ooid linklist m4ster4012
=ode/tempGheadnode9
%nt resultG09
>. hat is the union of an arra4. The arra4 was !iven Ho ab bhool !ai mH4.. ;marks
;. 6onsider the arra4 and find the union05& I1 union05& F1 union05&81* 5 marks
5. 6onsider an arra4 and draw a dia!ram usin! ma, heap method. 5 marks
<. ; pro!rams th4 Hin k errors detect krn4 th4 or output k4a hai wo btani thi.
5. hat is mer!esort method*
F. The arra4 was !iven and we have to sort the arra4 b4 selection sort method.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Hustif4 that k searchin! k lia binar4 tree efficient hai than heap structure*
sortin! a4 the aur union opration a4a tha 5 5 numbers kaa*
ak sawal nai hoa us main cod btana tha leaf node ; recursion kar k btana tha Hab k pointer dia tha
Ho root ko point kar raha tha.............if an4 hav idea thn tell me *
ak sawal main bta4a !a4a tha k ak arra4 ko use karta hoa nlo!;n time main sortin! kar li Hati hai*
woud u prefer usin! of heap structure instead of arra4 for more efficinc4* is main doubt hai plK
an4 one tell me*
ak sawal tha k b4 mer!e sortin! main Kiada mmor4 us hoti hai Hustif4 karo*
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
toda4s paper ;5 Hul4 ;0>5
all @uestions were from last >5 lectures almost.
inorder n post order @uestion
postfi, n infi, @uestion
arra4 was !iven n mer!esort was asked.
heap is efficient for sortin! minimum& wh4*
selection sort n @uick sort
a code for arra4 sort was !iven n asked to correct the mistakes
a code of stack n @ueue was !iven n output was asked
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
uesti!n N!" +1 0 Marks: 5 1
rite the code of the perculate(own01 function and also comment it.
uesti!n N!" +2 0 Marks: 5 1
Cere is an arra4 with e,actl4 >5 elements:
> ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5.
)uppose that we are doin! a binar4 search for an element. %ndicate an4 elements that will be
found b4 e,aminin! two or fewer numbers from the arra4.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Su7VectiAe Luesti!ns"
uesti!ns !- 2 6ar$s
>. %f we want to delete the node from B)T which has left and ri!ht child then which rotation
is applied *
;. 6ollision in hashin! definition*
uesti!n !- 3 6ar$s"
>. Al!orithm union b4 wei!ht*
;. 'ne tree is !iven @uestion is it heap or not if it is heap then write its t4pe
uesti!ns !- + 6ar$s"
>. )ome numbers are !iven and usin! those make B)T*
;. 'ne arra4 is !iven we re@uire to sort it usin! bubble sort and write onl4 ; iterations*
5. 'ne tree is !iven which not the heap but after minimum chan!es it becomes ma, heap
make it*
<. Make tree 4ou are re@uired to show onl4 the final tree
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
F1 The followin! arra4 represents a heap structure.
> ; 5 < 5 F I 8 9 >0 >> >;
9I IF F> 59 5< <9 << <; 5> ;5 >I
%nsert a new value 8F into the heap. )how the resultant heap& after insertion& in the form
of arra4*
I1 Cere is an arra4 of ten inte!ers.
5&5&8&9&>&I&0&;&F&<
(raw this arra4 after the first iteration of main loop of insertion sort 0sortin! from
smallest to lar!est1. This insertion has shifted at least one item in the arra4*
81 Liven %nput 2;5& <F& >;& 59& I8& 8I& ;& 53 and a hash function (#8% > 8 6!, 11& show
the resultin! S6hainin! hash TableU*
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
*: Gere is an arra< !- 10 integers:
+ 3 4 1 3 0 2 2 *:
Dra. t(is arra< a-ter t(e -irst iterati!n !- t(e 'arge '!!p in a se'ecti!n s!rt #S!rting -r!6
s6a''est t! 'argest%
* Luesti!ns !- + 6ar$s:
3: C!nsi,er t(e -!''!.ing T(rea,e, ;inar< Tree1
*: /rite ,!.n t(e C99 c!,e t! i6p'e6ent Inserti!n S!rt A'g!rit(6:
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
6)50> 6urrent Final Eaper..........^^^
Toda4 b4 Meeru7 A'i of 6) 50> 0AT 08:00 T' >0:00W (ated ;5$0I$;0>;1
50T mc@s were from past papers nd others from book..
; Marks +uestionsW
>W hat is the formula to calculate the front of a circular @ueue 0arra4$based implementation1..*
;W %n arra4 representation of union operation what $> represents on a particular inde,..*
5 Marks +uestionsW
<.. hat will be the output of followin! link list function.*
Ooid linklist m4ster4012
=ode/tempGheadnode9
%nt resultG09
5 Marks +uestionsW
>.. hat will be the `Jpostfi, e,pression for 0infi, e,pression1
0a.b$c1A0d$f.!1/h1.k
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+ues >: rite min heap after removal of root. 5 marks.
> 5 ; 5 < 8 9 >0 I
+ues ;: rite %n order and preorder traversal. 5 marks
tree was small and eas4.
+ues 5: show steps of mer!e sort: 5 marks.
>> >; >5 ;> ;; ;5 5> 55 <> <;
+ues <: correct the followin! code.
int isEresent0int /arr& int val& int =1
2 int low G 09
int hi!h G = $ >9
int mid9
while 0 low :G hi!h 1
2 mid G 0 low$hi!h 1A;9
if 0arrQmidR GG val1
return >9 AA found^
else if 0arrQmidR : val1
low G mid $ >9
else
hi!h G mid . >9
3
return 09 AA not found
3
+ues 5: 6orrect the code: 5 marks
A/ The inorder routine for threaded binar4 tree /A
Tree=ode/ ne,t%norder0Tree=ode/ p12
if0p$:?TC GG thread1
return0p$:?19
else 2
p G p$:?9
while0p$:#TC GG child1
p G p$:#9
return p9
3
3
@ues F:
for telephone directr4 which is best linear or non$linear arra4. ; marks
+ues I:
how to cope with collision. ; marks
Mostl4 mc@_s were from past papers
> @uestion about ma,$heap
> @uestion about min$heap
> @uestion about code of Find.
> @uestion about realtions& Transitivit4& etc.
> @uestion about insert an node in a heap and reor!aKniKe as ma,$heap.
> about %nsertion sortin! method.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
< @uestions of 5 marks.
;. )uppose we have the followin! representation child nodes and Earent node of the node
(
5. .6onsider the followin! ma, heap. Add node ;< in it and show the resultant Ceap.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Total @uestions 5;
<0 M6+_s mostl4 from past paers speciall4 4e wal4 ;
%f there are = e,ternal nodes in a binar4 tree then what will be the no. of internal nodes
in this binar4 tree*
%f there are = internal nodes in a binar4 tree then what will be the no. of e,ternal nodes
in this binar4 tree*
Ceap and it_s t4pe.
)uppose we have the followin! representation for a complete Binar4 )earch Tree& tell the
#eft and ?i!ht child nodes and Earent node of the node D

A B 6 D - F L C % M V # M = ' E + ? ) T W
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9 ;0 W

%n$order$ pre$order and post$order k ; @uestions th4.
; marks ka @uestion tha k in k name likhn4 hen
5 marks ka @uestion tha k ek tree ko in order and pre order me likhna tha.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Cere is an arra4 with e,actl4 >5 elements: 5 marks
> ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5.
)uppose that we are doin! a binar4 search for an element. %ndicate an4 elements that will
be found b4 e,aminin! two or fewer numbers from the arra4.
benifit of stack ; marks
6onsider the followin! ma, heap. Add node ;< in it and show the resultant Ceap*
harshin! s4 related aik @uestion tha*
function C0Ve41G0;/ke4.51mod I b@i 4ad nahi
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
+>: Cere is an arra4 with e,actl4 >5 elements: > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5. )uppose that
we are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4
e,aminin! two or fewer numbers from the arra4* + 6ar$s
+;: )uppose we have the followin! representation for a complete Binar4 )earch Tree&
A B 6 ( - F L C % M V # M = ' E + ? )
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9
Find
>. #eft child
;. ?i!ht child
5. Earent node
of the node C and %* + 6ar$s
+5: S5& I& 8& 9U implement these hash elements. Dse arra4 of siKe >5 and solve this collision b4
usin! hash code where h G ke4T><* + 6ar$s
+<: perform preorder and inorder b4 usin! the tree 0implement manuall4 not usin! an4
pro!rammin! code1.* + 6ar$s
Mustif4 wh4*
+F: >0
A f
F 9
A f A f
; 5 I 8
(elete the root and show the resultant heap* 3 6ar$s

+I: S;& F& 5& <& I& 9& 8U show B)T as tall hei!ht as possible* 3 6ar$s
+8: Binar4 )earch is much faster al!orithm Hustif4* 3 6ar$s
+9: )how arra4 of the !iven heap* 2 6ar$s
12
T Y
10 13
T Y T Y
3 5 + 2
T T Y
1 2 3
+>0: =ame two operations of link list* 2 6ar$s
+>;: Cow can we appl4 union operation on two different set* 2 6ar$s
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
>1 which method removes the value from the top of stack* ;mrks
;1 write the maHor use of table A(T in computin!* ;mrks
<1 what are the characteristics of a !ood hashin! function* 5
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
5marks ka @uestion tha His main new node insert kerni thi 8I or write balance factor of
none leaf nodes 4a bhi likhna tha.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
McLs *0::
3" ,i-- app'icati!n !- (as(ing:
+" c!Aert -!''!.ing inn pre-i8 23Z45T-
2" .(ic( i6p'e6entati!n !- ,isV!int .et is 7etter .t( space an, <T
37inar< tree 6a ,e'eti!n $a pr!cesss t(a
4 s(!. resu't !- t(e seLuences !- instructi!n
1: uni!n#1?2%
2: uni!n#3?+%
3: uni!n#3?2%
*: uni!n#4?5%
+: uni!n#1*?1+%
2: uni!n#12?13%
3: uni!n#1*?13%
s!rt 'ist 2 5 3 + 4 Inserti!n s!rt a'g!rit(6
ai$ aur 7 t(a re6!Ae pri!rit< Lueue $a pr!gra6 'i$(na t(a
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;.e,plain how does heap sort work*
5.write and e,plain the code for union and find operation of parent arra4 in disHoint sets*
<.what is level of binar4 trees*
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
>. union0>&;1
union05&51
union0I&;1
union08&I1
union09&>1
union0><&>51
union0>F&>I1
union0><&>I1
use the union b4 wei!ht method

binar4 tree dia !a4a the us men c ek node ko delete kr dia Hata h4e tree balance krna tha
tree dia howa tha us ka inorder aur preorder traversal krna tha 5 marks
<hapter no 24E 25
17pression 0ree
17pression (
0here "21 two types o% 17pressions(
) /n87 17pression
2 Fost87 17pression
/n87 17pression and /n order 0raversal(
/n the in87 e7pressions, one operand is on the le%t side o% the operator
and the other is on the right side 5uppose, i% we have E operator, it will
be written as 2 E 4
!e have an e7pression tree and per%orm inorder traversal on it !e get
the in87 %orm
o% the e7pression below(
Fost87 17pression and Fost order 0raversal(
/n the Fost87 e7pressions, both operands on le%t side and operator
between them on right side suppose, i% we have a E b will be written as
abE
<onverting From /n order to post order(
/n this the tree didn:t change only e7pression changed
/' order(
Fost order(
5tep )( Cse Frecedence order to write operaters
;1=+"5( ;2"<G10 13F4'1'0 =ivision +C$0/F$/<"0/4' "==/0/4'
5C;502"<0/4'
4k take one side aEbHc aEbcH abcHE according to ;1=+"5
0ake other side **dHeE%,Hg, *dHeE%Hg,9 dHeE%HgdeH%EgH
"dding both e6uations we get
abcHEdeH%EgHE
/n the same way we can also do this to e6uation
'4! make a 17pression tree %rom this e7pression(
501F )(
501F 2(
501F 3(
501F 4(
501F 5(
(

501F )(
501F 2(
501F *i,
501F *ii,

501F *iii,

501F *iv,
501F *v,
501F 3(
501F 4(
<A"F012 (2-
$ink(
0A21"=1= ;/'"2D 0211(
)8
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! statement is ='T correct .
) %n linked list the elements are necessaril4 to be conti!uous
) In 'in$e, 'ist t(e e'e6ents 6a< '!cate at -ar p!siti!ns in t(e 6e6!r<
) %n linked list each element also has the ne,t to it
) %n an arra4 the elements are conti!uous
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


-ach operator in a postfi, e,pression refers to the previous 77777777 operand0s1.
) 'ne
) T.!
) Three
) Four
p23
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! callin! methods does not chan!e the ori!inal value of the ar!ument in the
callin! function*
) =one of the !iven options
) Ca'' 7< passing t(e Aa'ue !- t(e argu6ent
) 6all b4 passin! reference of the ar!ument
) 6all b4 passin! the address of the ar!ument
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


A tree is an AO# tree if
) An4 one node fulfills the AO# condition
) At least half of the nodes fulfill the AO# condition
) All the nodes fulfill the AO# condition
) N!ne !- t(e giAen !pti!ns
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member
variables called data and ne,t=ode1. hat statement chan!es current=ode so that it refers to the
ne,t node*
) current=ode ..9
) current=ode G ne,t=ode9
) current=ode .G ne,t=ode9
) currentN!,e > currentN!,e-[ne8tN!,eR
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


A @ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
) False
) True
p101
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one is a self$ referential data t4pe*
) )tack
) +ueue
) Lin$ 'ist
) All of these
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


-ach node in doubl4 link list has&
) > pointer
) 2 p!inters
) 5 pointers
) < pointers
p35
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


% have implemented the @ueue with a linked list& keepin! track of a front pointer and a rear pointer. hich
of these pointers will chan!e durin! an insertion into an E9#T: @ueue*
) =either chan!es
) 'nl4 front pointer chan!es.
) On'< rear p!inter c(anges:
) Both chan!e.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! tree.
Cow man4 of the nodes have at least one siblin!*
) 8
) I
) +
) F
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


The nodes with no successor are called 777777777
) ?oot =odes
) Lea- N!,es
) Both of these
) =one of these
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


AO# Tree is&
) N!n Linear ,ata structure
) #inear data structure
) C4brid data structure 0Mi,ture of #inear and =on #inear1
) =one of the !iven options.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


e access elements in AO# Tree in&
) #inear wa4 onl4
) N!n Linear .a< !n'<
) Both linear and non linear wa4s
) =one of the !iven options.
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


A binar4 search tree should have minimum of one 77777777 nodeAs at each level&
) One # n!t sure %
) Two
) Three
) Four
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! statements.
0i1 A binar4 tree can contain at least ;
#
=odes at level #.
0ii1 A complete binar4 tree of depth d is a binar4 tree that contains ;
#
=odes at each level # between 0
and d& both inclusive.
0iii1 The total number of nodes 0Tn 1 in a complete binar4 tree of depth d is ;
d.>
$ > .
0iv1 The hei!ht of the complete binar4 tree can be written as h G lo! ; 0Tn.>1$> where Tn is Total
number of =odes.
hich one of the followin! is correct in respect of the above statements re!ardin! the Binar4 trees*
) 0i1 and 0iii1 onl4
) 0i1& 0ii1 and 0iii1 onl4
) 0ii1 and 0iii1 onl4
) #ii%? #iii% an, #iA% !n'<
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


X9\ is a EEEEEEEEEo!erator.
) Dnar4
) ;inar<
) Ternar4
) =one of the above
uesti!n N!" 13 # Mar$s" 2 %


/(at .!u', t(e state !- a stac$ 7e a-ter t(e -!''!.ing !perati!ns1
create stack
push A onto stack
push F onto stack
push g onto stack
pop item from stack
push B onto stack
pop item from stack
pop item from stack
A Re6ening On T(e Stac$
uesti!n N!" 14 # Mar$s" 2 %


hat are the applications of Binar4 Tree.
uesti!n N!" 15 # Mar$s" 2 %


hat is difference between call b4 reference and call b4 value*
'ne application is to find duplicates in a list of numbers.
#et a !iven list be" >; 5< 5F 89 55 >> 89
the first number in the list is placed in a node that is established as the root of a binar4 tree. -ach
number is compared with the node in the root& if the number is lar!er& we search the ri!ht sub$
tree else we search the left sub$tree. %f the sub$tree is empt4& the number is not a duplicate and
this will be added as a new node.
;. Binar4 trees can be used for sortin! a !iven list such that& if we take the first number as root&
the numbers less than that number will be transfered to left sub$tree and the !reater numbers to
ri!ht sub$tree.
5. Binar4 trees are also used for developin! the huffman codes.
uesti!n N!" 20 # Mar$s" 3 %


hat is the functionalit4 of the followin! method of B)T class
Tree=ode8int:/ function0Tree=ode8int:/ tree1
2
if0 tree GG =D## 1
return =D##9
if0 tree$:!et#eft01 GG =D## 1
return tree9 AA this is it8
return function0 tree$:!et#eft01 19
3
uesti!n N!" 21 # Mar$s" 3 %


a1 rite a 6.. statement that declares a valid reference of int i9
b1 hat is the benefit of reference and where can we use it*
%n the last lecture we were discussin! about reference variables& we saw three e,amples9 call b4
value& call b4 reference and call b4 pointer. e saw the use of stack when a function is called b4
value& b4 reference or b4 pointer. The ar!uments passed to the function and local variables are
pushed on to the stack. There is one important point to note that in this course& we are usin! 6A6..
but the usa!e of stack is similar in most of the computer lan!ua!es like F'?T?A= and Mava . The
s4nta, we are usin! here is 6.. specific& like we are sendin! a parameter b4 pointer usin! ; si!n. %n
Mava& the native data t4pes like int& float are passed b4 value and the obHects are passed b4 reference.
%n F'?T?A=& ever4 parameter is passed b4 reference. %n EA)6A#& 4ou can pass a parameter b4
value or b4 reference like 6... Nou mi!ht have heard of A#L'#& this lan!ua!e had provided
another wa4 of passin! parameter ca
lled call by name. These kinds of topics are covered in subHects like
uesti!n N!" 22 # Mar$s" + %


Deter6ine .(at t(e -!''!.ing recursiAe X6<ster<\ -uncti!n c!6putes .(en giAen a p!inter t! t(e
r!!t n!,e !- a 7inar< tree:
struct bt7s 2 int ke49 struct bt7s /left& /ri!ht9 3 bt7t9
int MFunc 0bt7t /T1 2
int =>& =;9
if 0T GG =D##1 return $>9
=> G MFunc0T$:left19
=; G MFunc0T$:ri!ht19
return 0=> : =; * => : =;1 . >9
3
uesti!n N!" 23 # Mar$s" + %


Is t(e giAen tree is an APL tree1 I- N!t t(en re,ra. is s! t(at it 7ec!6es APL
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne

A
@ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
) False
) True
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
data of the problem is of ;LB and the hard disk is of >LB capacit4& to solve this problem we should
) Dse better data structures
) %ncrease the hard disk space
) Dse the better al!orithm
) Dse as much data as we can store on the hard disk
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the function g as under
int g 0intX Oalue1
2
return Oalue9
3
=ow a and b are inte!ers in a callin! function. hich one of the followin! is a valid call to the above
function g.
) a G g 0b1 9
) a G g 0Xb1 9
) a G g 0/b1 9
) =one of the !iven options
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


%n the call b4 value methodolo!4& a cop4 of the obHect is passed to the called function.
) False
) True
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


The tree data structure is a
) #inear data structure
) =on$linear data structure
) Lraphical data structure
) (ata structure like @ueue
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


hen should 4ou use a c!nst re-erence parameter*
) henever the parameter has hu!e siKe.
) henever the parameter has hu!e siKe& the function chan!es the parameter within its bod4& and
4ou do ='T want these chan!es to alter the actual ar!ument.
) henever the parameter has hu!e siKe& the function chan!es the parameter within its bod4& and
4ou (' want these chan!es to alter the actual ar!ument.
) henever the parameter has hu!e siKe& and the function does not chan!e the parameter within its
bod4.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


Cere is the start of a 6.. class declaration:
class foo
2
public:
void ,0foo f19
void 40const foo f19
void K0foo f1 const9
...
hich of the three member functions can alter the E?%OAT- member variables of the foo obHect that
activates the function*
) 'nl4 , can alter the private member variables of the obHect that activates the function.
) 'nl4 4 can alter the private member variables of the obHect that activates the function.
) 'nl4 K can alter the private member variables of the obHect that activates the function.
) Two of the functions can alter the private member variables of the obHect that activates the
function.
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


hat is the ma,imum depth of recursive calls a function ma4 make*
) >
) ;
) n 0where n is the ar!ument1
) There is no fi,ed ma,imum
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose n is the number of nodes in a complete Binar4 Tree then ma,imum steps re@uired for a
search operation are&
) #o!; 0n.>1 $>
) #o!; 0n.>1
) #o!; 0n1 P >
) #o!; 0n1
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


%n the linked list implementation of the stack class& where does the push member function places the new
entr4 on the linked list*
) At the head
) At the tail
) After all other entries that are !reater than the new entr4.
) After all other entries that are smaller than the new entr4.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose we have a circular arra4 implementation of the @ueue class& with ten items in the @ueue stored at
dataQ;R throu!h dataQ>>R. The 6AEA6%TN is <;& i.e.& the arra4 has been declared to be of siKe <;. here
does the push member function place the new entr4 in the arra4*
) dataQ>R
) dataQ;R
) dataQ>>R
) dataQ>;R
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


The e,pression AB.6/ is called *
) Erefi, e,pression
) Eostfi, e,pression
) %nfi, e,pression
) =one of these
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a binar4 tree where ever4 node has a value& ever4 node_s left subtree contains onl4 values
less than or e@ual to the node_s value& and ever4 node_s ri!ht subtree contains onl4 values that are !reater
then or e@ual *
) )trictl4 Binar4 Tree
) Binar4 )earch tree
) AO# tree
) All of these
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! binar4 search tree 0B)T1:
%f node A in the B)T is deleted& which two nodes are the candidates to take its place*
) M and %
) C and -
) ( and -
) # and M
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


LetMs ca'' t(e n!,e as a t(at reLuires re-7a'ancing: C!nsi,er t(e t.! cases giAen 7e'!."
>1 An insertion into left subtree of the left child of a
;1 An insertion into ri!ht subtree of the ri!ht child of a.
hich of the followin! statement is correct about these two cases.

>1 The insertion occurs outside 0i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation can fi, the
balance in these two cases.
;1 The insertion occurs inside 00i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation cannot fi, the
balance in these two cases
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


e access elements in AO# Tree in&
) #inear wa4 onl4
) =on #inear wa4 onl4
) Both linear and non linear wa4s
) =one of the !iven options.
uesti!n N!" 13 # Mar$s" 2 %


AO# Tree is&
) =on #inear data structure
) #inear data structure
) C4brid data structure 0Mi,ture of #inear and =on #inear1
) =one of the !iven options.
uesti!n N!" 14 # Mar$s" 2 %


Cow we can delete a node with two 6hilds in a binar4 search tree usin! its ri!ht sub tree.
uesti!n N!" 15 # Mar$s" 2 %

hat is Function 6all )tack Live short answer.
uesti!n N!" 20 # Mar$s" 3 %


,plain the two cases in which we appl4 double rotation in an AO# tree.
uesti!n N!" 21 # Mar$s" 3 %


Cere is a small binar4 tree.
/rite t(e !r,er !- t(e n!,es Aisite, in
a1 A Eost$order traversal
b1 A level$order traversal
uesti!n N!" 22 # Mar$s" + %


Elease consider the followin! AO# tree.
. %nsert new node 8I in this tree and make tree balance.
. rite balance factor of each node after and before insertin! node 8I.
uesti!n N!" 23 # Mar$s" + %


6onsider the followin! binar4 tree
)how the state of the tree after deletin! ;<.
MIDTERM EXAMINATION
Fa'' 2005
CS301- Data Structures #Sessi!n - +%
Re- N!" 44+*42
Ti6e" 20 6in
Mar$s" 34

uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! is a valid postfi, e,pression*
Y ab.c/d$
Y abc/.d$
Y abc./d$
Y 0abc/1.d$

uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
tree data structure is a
Y #inear data structure
Y =on$linear data structure
Y Lraphical data structure
Y (ata structure like @ueue

uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


A C!6p!un, Data Structure is the data structure which can have multiple data items of same t4pe
or of different t4pes. hich of the followin! can be considered compound data structure*
Y Arra4s
Y #ink#ists
Y Binar4 )earch Trees
Y All of the !iven options

uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


)uppose a pointer has been declared in main but has not assi!ned an4 variable address then
\\\\\\\Y\That pointer points to First b4te in main function
\\\\\\\Y\That pointer contains a =D## value
\\\\\\\Y\=one of these

\\\\\\\Y\That pointer points to an4 memor4 address

uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne

Cere
is the start of a 6.. class declaration:
class foo
2
public:
void ,0foo f19
void 40const foo f19
void K0foo f1 const9
...
hich of the three member functions can alter the E?%OAT- member variables of the foo obHect that
activates the function*
\\\\\\\Y\'nl4 , can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\'nl4 4 can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\'nl4 K can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\Two of the functions can alter the private member variables of the obHect that activates the function.

uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
operation for removin! an entr4 from a stack is traditionall4 called:
Y delete
Y peek
Y pop
Y remove

uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich statement of the followin! statements is incorrect*
Y #ists can be implemented b4 usin! arra4s or linked lists
Y A list is a se@uence of one or more data items
Y )tack is a special kind of list in which all insertions and deletions take place at one end
Y )tacks are easier to implement than lists

uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


Earameters in function call are passed usin!&
Y )tack
Y +ueue
Y Binar4 )earch Tree
Y AO# Tree

uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! se@uence of push operations in a stack:
stack.push0JIJ19
stack.push0J8J19
stack.push0J9J19
stack.push0J>0J19
stack.push0J>>J19
stack.push0J>;J19
\\\\\\\Y\I 8 9 >0 >> >;
\\\\\\\Y\9 8 >> >0 I >;
\\\\\\\Y\9 >0 8 >> >; I
\\\\\\\Y\9 >0 8 >; I >>

uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hat is the ma,imum depth of recursive calls a function ma4 make*
Y >
Y ;
Y n 0where n is the ar!ument1
Y There is no fi,ed ma,imum

uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! function:
void test7a0int n1
2
cout 88 n 88 " "9
if 0n:01
test7a0n$;19
3
hat is printed b4 the call test7a0<1*
Y < ;
Y 0 ; <
Y 0 ;
Y ; <

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


+ueue follows&
Y #ast in First out
Y First in #ast out
Y First in First out
Y =one of these

uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a binar4 tree where ever4 node has a value& ever4 node_s left subtree contains onl4 values
less than or e@ual to the node_s value& and ever4 node_s ri!ht subtree contains onl4 values that are !reater
then or e@ual *
\\\\\\\Y\)trictl4 Binar4 Tree
\\\\\\\Y\Binar4 )earch tree
\\\\\\\Y\AO# tree
\\\\\\\Y\All of these

uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne

Four
statements about trees are below. Three of them are correct. hich one is %=6'??-6T*
\\\\\\\Y\Trees are recursivel4 defined multi$dimensional data structures
\\\\\\\Y\The order of a tree indicates a ma,imum number of childen allowed at each node of the tree
\\\\\\\Y\A search tree is a special t4pe of tree where all values 0i.e. ke4s1 are ordered
\\\\\\\Y\%f Tree>_s siKe is !reater than Tree;_s siKe& then the hei!ht of Tree> must also be !reater than Tree;_s
hei!ht.

uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


Below is a binar4 search tree. %f we delete the value 50 usin! the al!orithm we discussed& what value will
be in the root of the remainin! tree*
Y 50
Y F0
Y I0
Y 80

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a data structure that can !row easil4 d4namicall4 at run time without havin! to cop4
e,istin! elements.
Y Arra4
Y #ist
Y Both of these
Y =one of these

uesti!n N!" 13 # Mar$s" 1 %

Live the names of basic +ueue 'perations
Ans:
(efinition: A collection of items in which onl4 the earliest added item ma4 be accessed. Basic operations
are add 0to the tail1 or en@ueue and delete 0from the head1 or de@ueue. (elete returns the item removed.
Also known as "first$in& first$out" or F%F'.

uesti!n N!" 14 # Mar$s" 1 %

Live
one benefit of usin! )tack.
%n computer science& a stack is a last in& first out 0#%F'1 abstract data t4pe and data structure. A stack can
have an4 abstract data t4pe as an element& but is characteriKed b4 onl4 two fundamental operations: push
and pop.the data structure itself enforces the proper order of calls.

uesti!n N!" 15 # Mar$s" 2 %

LetMs
ca'' t(e n!,e as a t(at reLuires re-7a'ancing: C!nsi,er t(e t.! cases giAen 7e'!."
>1 An insertion into left subtree of the left child of a
;1 An insertion into ri!ht subtree of the ri!ht child of a.
hich of the followin! statement is correct about these two cases.

>1 The insertion occurs outside 0i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation can fi, the
balance in these two cases.
;1 The insertion occurs inside 00i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation cannot fi, the
balance in these two cases

uesti!n N!" 20 # Mar$s" 3 %


6onsider the followin! se@uence of push operations in a stack:
stack.push0J>J19
stack.push0J;J19
stack.push0J5J19
stack.push0J<J19
stack.push0J5J19
stack.push0JFJ19
Nou can insert as man4 stack.pop01Js as 4ou like in the above se@uence of stack.pushJs to !et a desired
output. hich of the followin! cannot be an output*
A. >;5<5F
B. 5;5<>F
6. 5<;5F>
(. 5<;F>5
-. 5<;>F5

uesti!n N!" 21 # Mar$s" + %

FiAe
s(!rt ans.ers !- t(e -!''!.ing Luesti!ns"
5. h4 #ist wastes less memor4 as compared to Arra4s.
Ans:
>. #inked lists do not need conti!uous blocks of memor49 e,tremel4 lar!e data sets stored in an arra4
mi!ht not be able to fit in memor4.
;. #inked list stora!e does not need to be preallocated 0a!ain& due to arra4s needin! conti!uous memor4
blocks1.
5. %nsertin! or removin! an element into a linked list re@uires one data update& insertin! or removin! an
element into an arra4 re@uires n 0all elements after the modified inde, need to be shifted1.
Arra4 is a collection of same data t4pe. %n linked list there are two field one is address and other is
pointer. %n arra4 elements are arran!ed in a specific order
<. h4 we can chan!e the siKe of list after its creation when we can not do that in simple arra4s.
)ome how the answer will be same as part > because %nsertin! or removin! an element into a linked list
re@uires one data update& insertin! or removin! an element into an arra4 re@uires n 0all elements after the
modified inde, need to be shifted1.
Arra4 is a collection of same data t4pe. The siKe of arra4 is mentioned with its declaration. in arra4s the
elements are in conti!uous position. one must after another. while in linked list we !ave the address of
ne,t element in the ne,t part of node.

uesti!n N!" 22 # Mar$s" 10 %


6onvert the followin! infi, e,pression into postfi, e,pressions usin! stack 0)how complete steps1
>$; 55$0<.5/F1/I
111*1<1 1+1111*11 111111 1141 14M4144M1 1111
)tep > Eost fi, stack


I I
I
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne
/(ic( !ne !- t(e -!''!.ing state6ent is NOT c!rrect :
Y %n linked list the elements are necessaril4 to be conti!uous
Y %n linked list the elements ma4 locate at far positions in the memor4
Y %n linked list each element also has the address of the element ne,t to it
Y %n an arra4 the elements are conti!uous
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
In a pr!gra6 a re-erence Aaria7'e? sa< 8? can 7e ,ec'are, as
Y int X, 9
Y int /, 9
Y int , 9
Y =one of the !iven options
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
Lin$e, 'ists are c!''ecti!ns !- ,ata ite6s 0'ine, up in a r!.0 ? inserti!ns an, ,e'eti!ns can
7e 6a,e !n'< at t(e -r!nt an, t(e 7ac$ !- a 'in$e, 'ist:
Y True
Y False
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
A Linear Data Structure is t(e ,ata structure in .(ic( ,ata e'e6ents are arrange, in a
seLuence !r a 'inear 'ist: /(ic( !- t(e -!''!.ing is N!n Linear Data Structure1
Y Arra4s
Y #ink#ists
Y Binar4 )earch Trees
Y =one of these
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
A @ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
Y
Y True
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! statements is correct*
Y Arra4 siKe is fi,ed once it is created.
#ink #ist siKe is fi,ed Y once it is created.
Binar4 )earch Tree siKe is Y fi,ed once it is created
AO# Tree siKe is fi,ed Y once it is created
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is correct about pointers*
The4 alwa4s point to Y different memor4 locations
The4 ma4 point to a sin!le Y memor4 location
Y The address of two pointer variables is same
=one of these Y
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! abstract data t4pes are ='T used b4 %nte!er Abstract (ata t4pe !roup*
Y short
int Y
float Y
lon! Y
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for addin! an entr4 to a stack is traditionall4 called :
add Y
append Y
insert Y
Y push
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for removin! an entr4 from a stack is traditionall4 called:
delete Y
peek Y
Y pop
remove Y
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
e can add elements in +D-D- From 777777777
Front Y
Y ?ear
From Both ?are and Front Y
=one of these Y
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
The difference between a binar4 tree and a binar4 search tree is that &
a binar4 search tree has Y two children per node whereas a binar4 tree can have none& one&
or two children per node
Y in binar4 search tree nodes are inserted based on the values the4 contain
in binar4 tree nodes are Y inserted based on the values the4 contain
none of these Y
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose n is the number of nodes in a complete Binar4 Tree then ma,imum steps re@uired for a
search operation are&
Y #o!; 0n.>1 $>
#o! Y ; 0n.>1
#o! Y ; 0n1 P >
#o! Y ; 0n1
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
The followin! is a se!ment of a 6 pro!ram.
int p@r0Binar4=ode t1
2 if 0t GG null 1
return $>9
else
return >.ma,0p@r0t.left1&p@r0t.ri!ht11 3
%dentif4& what the above pro!ram intend0s1 to do*
6ompute the hei!ht of a Y binar4 tree usin! an in$order traversal
6ompute the hei!ht of a Y binar4 tree usin! a pre$order traversal
Y 6ompute the depth of a binar4 tree usin! a pre$order traversal
6ompute the depth of a Y binar4 tree usin! a post$order traversal
+uestion =o: >5 0 Marks: > 1 $ Elease choose one
6onsider the followin! infi, e,pression:
5 . 5 / F P I / 08 . 51
hich of the followin! is a correct e@uivalent e,pression0s1 for the above*
Y 5 F 5 . / I 5 8 . $ /
Y 5 F 5 I 5 8 . / . $ /
Y 5 5 F . / I 8 5 . $ /
Y 5 5 F / . I 8 5 . / $
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
An arra4 is a !roup of consecutive related memor4 locations.
Y True
Y False
uesti!n N!" 13 # Mar$s" 1 %
%s this a correct statement* Live answer in Nes or =o.
A node cannot be deleted& when the node to be deleted has both left and ri!ht subtrees.
=o& it can be deleted.
uesti!n N!" 14 # Mar$s" 1 %
(eletin! a leaf node in binar4 search tree involves settin! 777777 pointerAs of that nodes parent
as null.
>
;
5
<
uesti!n N!" 15 # Mar$s" 2 %
(escribe an4 two uses of priorit4 @ueues*
uesti!n N!" 20 # Mar$s" 3 %
Cow we evaluate postfi, e,pressions*
uesti!n N!" 21 # Mar$s" + %
Followin! is the while loop used in level$order traversal:
while0 ^@.empt401 1
2
tree=ode G @.de@ueue019
cout 88 /0tree=ode$:!et%nfo011 88 " "9
if0tree=ode$:!et#eft01 ^G =D## 1
@.en@ueue0 tree=ode$:!et#eft0119
if0tree=ode$:!et?i!ht01 ^G =D## 1
*
3
hat should be the statement to replace the @uestion mark in the loop above:
uesti!n N!" 22 # Mar$s" 10 %
rite a friend function for a #inked #ist class called mer!e#ists that takes two non$empt4 lists&
mer!e these two lists and return the mer!ed list.
Dse the followin! function protot4pe:
#ist mer!e#ists0#ist ,&#ist 41
111*1<1 1+1111*11 111111 1141 14M4144M1 11
11
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne
A subscript of an arra4 ma4 be an inte!er or an inte!er e,pression.
Y True
Y False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
(oubl4 #inked #ist alwa4s has one =D## pointer.

Y True
Y False
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne

%n which of the traversal method& the recursive calls can be used to traverse a binar4 tree *
Y %n preorder traversal onl4
Y %n inorder traversal onl4
Y %n postorder traversal onl4
Y All of the !iven options
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
A tree is an AO# tree if

Y An4 one node fulfills the AO# condition
Y At least half of the nodes fulfill the AO# condition
Y All the nodes fulfill the AO# condition
Y =one of the !iven options
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member
variables called data and ne,t=ode1. hat boolean e,pression will be true when cursor refers to
the tail node of the list*

Y 0current=ode GG null1
Y 0current=ode$:ne,t=ode GG null1
Y 0ne,t=ode.data GG null1
Y 0current=ode.data GG 0.01
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose that the class declaration of )ome6lass includes the followin! function protot4pe.
bool #essThan0 )ome6lass another'bHect 19
/(ic( !- t(e -!''!.ing tests in t(e c'ient c!,e c!rrect'< c!6pares t.! c'ass !7Vects a'p(a
an, 7eta1

Y if 0alpha 8 beta1
Y if 0alpha.#essThan0beta11
Y if 0#essThan0alpha& beta11
Y if 0#essThan0alpha1.beta1
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
%n 6 what is the operation that 4ou can not do with primitive t4pes*
Y Assi!n a value to primitive t4pe usin! a literal
Y (eclare primitive t4pes to be constant usin! the 6onst ke4word
Y 6reate a new instance of primitive t4pe with =ew ke4word
Y =one of these
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for addin! an entr4 to a stack is traditionall4 called :
Y add
Y append
Y insert
Y push
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for removin! an entr4 from a stack is traditionall4 called:
Y delete
Y peek
Y pop
Y remove
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider the followin! se@uence of push operations in a stack:
stack.push0JIJ19
stack.push0J8J19
stack.push0J9J19
stack.push0J>0J19
stack.push0J>>J19
stack.push0J>;J19

Y I 8 9 >0 >> >;
Y 9 8 >> >0 I >;
Y 9 >0 8 >> >; I
Y 9 >0 8 >; I >>
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
77777777 is the ma,imum number of nodes that 4ou can have on a stack$linked list *
Y hero
Y ;n 0where n is the number of nodes in linked list1
Y An4 =umber
Y =one of these
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! can be used to reverse a strin! value&

Y )tack

Y +ueue

Y Both of these

Y =one of these

uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider the followin! tree&






Cow man4 leaves does it have*

Y ;
Y <
Y F
Y 9
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
AO# Tree is&

Y =on #inear data structure

Y #inear data structure

Y C4brid data structure 0Mi,ture of #inear and =on #inear1

Y =one of the !iven options.



uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
The followin! are statements related to @ueues.

0i1 The last item to be added to a @ueue is the first item to be removed
0ii1 A @ueue is a structure in which both ends are not used
0iii1 The last element hasnJt to wait until all elements precedin! it on the @ueue are removed
0iv1A @ueue is said to be a last$in$first$out list or #%F' data structure.

hich of the above isAare related to normal @ueues*

Y 0iii1 and 0ii1 onl4
Y 0i1& 0ii1 and 0iv1 onl4
Y 0ii1 and 0iv1 onl4
Y =one of the !iven options

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
An arra4 is a !roup of consecutive related memor4 locations.

Y True
Y False


uesti!n N!" 13 # Mar$s" 1 %
%n which of traversal method& recursion can not be applied.*

uesti!n N!" 14 # Mar$s" 1 %
hat is meant b4 an empt4 stack*

uesti!n N!" 15 # Mar$s" 2 %
%s the followin! statement correct* %f 4our answer is =o& then correct it.
SA tree is an AO# tree if at least half of the nodes fulfill the AO# conditionU


uesti!n N!" 20 # Mar$s" 3 %
The followin! function is performin! some operation on the elements of a sin!l4 link list please
tell what this functions is doin!&
A!i, Lin$List""6<ster<#%]
N!,e Z te6p > (ea,N!,eR
int resu't > 0R
.(i'e# te6p-[getNe8t#% J> NNLL %]
te6p > te6p-[getNe8t#%R
int Aa'ue > te6p-[get#%R
i-#Aa'ue ^ 2 >> 0%
] Aa'ue 99R
te6p-[set#Aa'ue%R
_
_
_


uesti!n N!" 21 # Mar$s" + %
)ee the code below & !ive comments a!ainst each line and identif4 which line will result in error*
>. void main0void1
;. 2
5. int actual G >;59
<. int Xother G actual9
5.
F. int natural G <5F9
I. other G Xnatural9
8. 3

uesti!n N!" 22 # Mar$s" 10 %
Dra. APL Tree 7< -!''!.ing ,igits 34? 21? 2+? 24? 34? 32? 3+ an, a's! per-!r6 necessar<
r!tati!n? .(i'e s(!.ing a'' t(e inter6e,iate trees 7eing create, in t(e pr!cess: In eac(
stage? t(e APL trans-!r6ati!n s(!u', 7e c!n,ucte, at a ,iscrepanc< t(at is -art(est -r!6
t(e r!!t:
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
?ef =o: >5<95IF
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


%n an arra4 we can store data elements of different t4pes.
) True
) False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


%n an arra4 list the current element is
) The first element
) The middle element
) The last element
) The element where the current pointer points to
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! callin! methods does not chan!e the ori!inal value of the ar!ument in the
callin! function*
) =one of the !iven options
) 6all b4 passin! the value of the ar!ument
) 6all b4 passin! reference of the ar!ument
) 6all b4 passin! the address of the ar!ument
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! statements is ='T correct*
) Arra4 siKe can be chan!ed after its creation.
) #ink #ist siKe can be chan!ed after its creation
) Binar4 )earch Tree siKe can be chan!ed after its creation
) AO# Tree siKe can be chan!ed after its creation
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


)uppose that the class declaration of )ome6lass includes the followin! function protot4pe.
bool #essThan0 )ome6lass another'bHect 19
/(ic( !- t(e -!''!.ing tests in t(e c'ient c!,e c!rrect'< c!6pares t.! c'ass !7Vects a'p(a an, 7eta1
) if 0alpha 8 beta1
) if 0alpha.#essThan0beta11
) if 0#essThan0alpha& beta11
) if 0#essThan0alpha1.beta1
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


A @ueue is a 77777777data structure& whereas a stack is a 77777777data structure.
) F%F'& #%F'
) #%F'&F%F'
) none of these
) both of these
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! operators has hi!her priorit4 than all of others *
) Multiplication operator
) Minus operator
) Elus operator
) -,ponentiation operator
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


-ach node in Binar4 )earch Tree has
) > pointer
) ; pointers
) 5 pointers
) < pointers
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


Four statements about trees are below. Three of them are correct. hich one is %=6'??-6T*
) Trees are recursivel4 defined multi$dimensional data structures
) The order of a tree indicates a ma,imum number of childen allowed at each node of the tree
) A search tree is a special t4pe of tree where all values 0i.e. ke4s1 are ordered
) %f Tree>_s siKe is !reater than Tree;_s siKe& then the hei!ht of Tree> must also be !reater than Tree;_s
hei!ht.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! is "T?D-" about arra4s&
) e can increase the siKe of arra4s after their creation.
) e can decrease the siKe of arra4s after their creation.
) e can increase but can_t decrease the siKe of arra4s after their creation.
) e can neither increase nor decrease the arra4 siKe after their creation.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


)earchin! an element in an AO# tree take ma,imum 7777777 time 0where n is no. of nodes in AO#
tree1&
) #o!;0n.>1
) #o!;0n.>1 $>
) >.<< #o!;n
) >.FF #o!;n
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


There isAare 77777777 caseAs for rotation in an AO# tree&
) >
) 5
) ;
) <
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! statements.
0v1 A binar4 tree can contain at least ;
#
=odes at level #.
0vi1 A complete binar4 tree of depth d is a binar4 tree that contains ;
#
=odes at each level # between 0
and d& both inclusive.
0vii1 The total number of nodes 0Tn 1 in a complete binar4 tree of depth d is ;
d.>
$ > .
0viii1 The hei!ht of the complete binar4 tree can be written as h G lo! ; 0Tn.>1$> where Tn is
Total number of =odes.
hich one of the followin! is correct in respect of the above statements re!ardin! the Binar4 trees*
) 0i1 and 0iii1 onl4
) 0i1& 0ii1 and 0iii1 onl4
) 0ii1 and 0iii1 onl4
) 0ii1& 0iii1 and 0iv1 onl4
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! infi, e,pression.
5 . FA;
%f one converts the above e,pression into postfi,& what would be the resultant e,pression*
) 5FA . ;
) 5 F ; A .
) 5 F A ; .
) AF; . 5
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is a non linear data structure*
) #inked #ist
) )tack
) +ueue
) Tree
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


X9\ is a EEEEEEEEEo!erator.
) Dnar4
) Binar4
) Ternar4
) =one of the above
uesti!n N!" 13 # Mar$s" 2 %


hich process places data at the back of the @ueue*
uesti!n N!" 14 # Mar$s" 2 %


Cow we can delete a node with two 6hilds in a binar4 search tree usin! its ri!ht sub tree.
uesti!n N!" 15 # Mar$s" 2 %


h4 we use ?eference Oariables. Live one e,ample.
uesti!n N!" 20 # Mar$s" 3 %


T(e n!,es !- a 7inar< tree (aAe ,ata 1? 2? 3? *: T(e in-!r,er traAersa' !- t(e tree <ie',s 2?1?*?3: T(e
p!st!r,er traAersa' is 2? *? 3? 1: T(e r!!t !- t(e tree is at 'eAe' 0:
3" /(ic( Aa'ue is in t(e rig(t c(i', !- t(e r!!t1 #1 &t%
0A1 > 0B1 ; 061 5 0(1 < 0-1 none
uesti!n N!" 21 # Mar$s" 3 %


hat normall4 is the se@uence of operations while constructin! an AO# tree*
uesti!n N!" 22 # Mar$s" + %


Cere is a small binar4 tree:
1*
T Y
2 11
T Y T Y
1 3 10 30
T T
3 *0
rite the order of the nodes visited in:
A. An in$order traversal:
B. A pre$order traversal:
uesti!n N!" 23 # Mar$s" + %


Is t(e giAen tree is an APL tree1 I- N!t t(en re,ra. is s! t(at it 7ec!6es APL
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! statement is ='T correct .
) %n linked list the elements are necessaril4 to be conti!uous
) In 'in$e, 'ist t(e e'e6ents 6a< '!cate at -ar p!siti!ns in t(e 6e6!r<
) %n linked list each element also has the ne,t to it
) %n an arra4 the elements are conti!uous
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


-ach operator in a postfi, e,pression refers to the previous 77777777 operand0s1.
) 'ne
) T.!
) Three
) Four
p23
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! callin! methods does not chan!e the ori!inal value of the ar!ument in the
callin! function*
) =one of the !iven options
) Ca'' 7< passing t(e Aa'ue !- t(e argu6ent
) 6all b4 passin! reference of the ar!ument
) 6all b4 passin! the address of the ar!ument
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


A tree is an AO# tree if
) An4 one node fulfills the AO# condition
) At least half of the nodes fulfill the AO# condition
) All the nodes fulfill the AO# condition
) N!ne !- t(e giAen !pti!ns
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member
variables called data and ne,t=ode1. hat statement chan!es current=ode so that it refers to the
ne,t node*
) current=ode ..9
) current=ode G ne,t=ode9
) current=ode .G ne,t=ode9
) currentN!,e > currentN!,e-[ne8tN!,eR
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


A @ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
) False
) True
p101
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one is a self$ referential data t4pe*
) )tack
) +ueue
) Lin$ 'ist
) All of these
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


-ach node in doubl4 link list has&
) > pointer
) 2 p!inters
) 5 pointers
) < pointers
p35
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


% have implemented the @ueue with a linked list& keepin! track of a front pointer and a rear pointer. hich
of these pointers will chan!e durin! an insertion into an E9#T: @ueue*
) =either chan!es
) 'nl4 front pointer chan!es.
) On'< rear p!inter c(anges:
) Both chan!e.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! tree.
Cow man4 of the nodes have at least one siblin!*
) 8
) I
) +
) F
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


The nodes with no successor are called 777777777
) ?oot =odes
) Lea- N!,es
) Both of these
) =one of these
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


AO# Tree is&
) N!n Linear ,ata structure
) #inear data structure
) C4brid data structure 0Mi,ture of #inear and =on #inear1
) =one of the !iven options.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


e access elements in AO# Tree in&
) #inear wa4 onl4
) N!n Linear .a< !n'<
) Both linear and non linear wa4s
) =one of the !iven options.
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


A binar4 search tree should have minimum of one 77777777 nodeAs at each level&
) One # n!t sure %
) Two
) Three
) Four
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! statements.
0i,1 A binar4 tree can contain at least ;
#
=odes at level #.
0,1 A complete binar4 tree of depth d is a binar4 tree that contains ;
#
=odes at each level #
between 0 and d& both inclusive.
0,i1 The total number of nodes 0Tn 1 in a complete binar4 tree of depth d is ;
d.>
$ > .
0,ii1 The hei!ht of the complete binar4 tree can be written as h G lo! ; 0Tn.>1$> where Tn is
Total number of =odes.
hich one of the followin! is correct in respect of the above statements re!ardin! the Binar4 trees*
) 0i1 and 0iii1 onl4
) 0i1& 0ii1 and 0iii1 onl4
) 0ii1 and 0iii1 onl4
) #ii%? #iii% an, #iA% !n'<
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


X9\ is a EEEEEEEEEo!erator.
) Dnar4
) ;inar<
) Ternar4
) =one of the above
uesti!n N!" 13 # Mar$s" 2 %


/(at .!u', t(e state !- a stac$ 7e a-ter t(e -!''!.ing !perati!ns1
create stack
push A onto stack
push F onto stack
push g onto stack
pop item from stack
push B onto stack
pop item from stack
pop item from stack
A Re6ening On T(e Stac$
uesti!n N!" 14 # Mar$s" 2 %


hat are the applications of Binar4 Tree.
uesti!n N!" 15 # Mar$s" 2 %


hat is difference between call b4 reference and call b4 value*
'ne application is to find duplicates in a list of numbers.
#et a !iven list be" >; 5< 5F 89 55 >> 89
the first number in the list is placed in a node that is established as the root of a binar4 tree. -ach
number is compared with the node in the root& if the number is lar!er& we search the ri!ht sub$
tree else we search the left sub$tree. %f the sub$tree is empt4& the number is not a duplicate and
this will be added as a new node.
;. Binar4 trees can be used for sortin! a !iven list such that& if we take the first number as root&
the numbers less than that number will be transfered to left sub$tree and the !reater numbers to
ri!ht sub$tree.
5. Binar4 trees are also used for developin! the huffman codes.
uesti!n N!" 20 # Mar$s" 3 %


hat is the functionalit4 of the followin! method of B)T class
Tree=ode8int:/ function0Tree=ode8int:/ tree1
2
if0 tree GG =D## 1
return =D##9
if0 tree$:!et#eft01 GG =D## 1
return tree9 AA this is it8
return function0 tree$:!et#eft01 19
3
uesti!n N!" 21 # Mar$s" 3 %


a1 rite a 6.. statement that declares a valid reference of int i9
b1 hat is the benefit of reference and where can we use it*
%n the last lecture we were discussin! about reference variables& we saw three e,amples9 call b4
value& call b4 reference and call b4 pointer. e saw the use of stack when a function is called b4
value& b4 reference or b4 pointer. The ar!uments passed to the function and local variables are
pushed on to the stack. There is one important point to note that in this course& we are usin! 6A6..
but the usa!e of stack is similar in most of the computer lan!ua!es like F'?T?A= and Mava . The
s4nta, we are usin! here is 6.. specific& like we are sendin! a parameter b4 pointer usin! ; si!n. %n
Mava& the native data t4pes like int& float are passed b4 value and the obHects are passed b4 reference.
%n F'?T?A=& ever4 parameter is passed b4 reference. %n EA)6A#& 4ou can pass a parameter b4
value or b4 reference like 6... Nou mi!ht have heard of A#L'#& this lan!ua!e had provided
another wa4 of passin! parameter ca
lled call by name. These kinds of topics are covered in subHects like
uesti!n N!" 22 # Mar$s" + %


Deter6ine .(at t(e -!''!.ing recursiAe X6<ster<\ -uncti!n c!6putes .(en giAen a p!inter t! t(e
r!!t n!,e !- a 7inar< tree:
struct bt7s 2 int ke49 struct bt7s /left& /ri!ht9 3 bt7t9
int MFunc 0bt7t /T1 2
int =>& =;9
if 0T GG =D##1 return $>9
=> G MFunc0T$:left19
=; G MFunc0T$:ri!ht19
return 0=> : =; * => : =;1 . >9
3
uesti!n N!" 23 # Mar$s" + %


Is t(e giAen tree is an APL tree1 I- N!t t(en re,ra. is s! t(at it 7ec!6es APL
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne

A
@ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
) False
) True
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
data of the problem is of ;LB and the hard disk is of >LB capacit4& to solve this problem we should
) Dse better data structures
) %ncrease the hard disk space
) Dse the better al!orithm
) Dse as much data as we can store on the hard disk
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the function g as under
int g 0intX Oalue1
2
return Oalue9
3
=ow a and b are inte!ers in a callin! function. hich one of the followin! is a valid call to the above
function g.
) a G g 0b1 9
) a G g 0Xb1 9
) a G g 0/b1 9
) =one of the !iven options
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


%n the call b4 value methodolo!4& a cop4 of the obHect is passed to the called function.
) False
) True
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


The tree data structure is a
) #inear data structure
) =on$linear data structure
) Lraphical data structure
) (ata structure like @ueue
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


hen should 4ou use a c!nst re-erence parameter*
) henever the parameter has hu!e siKe.
) henever the parameter has hu!e siKe& the function chan!es the parameter within its bod4& and
4ou do ='T want these chan!es to alter the actual ar!ument.
) henever the parameter has hu!e siKe& the function chan!es the parameter within its bod4& and
4ou (' want these chan!es to alter the actual ar!ument.
) henever the parameter has hu!e siKe& and the function does not chan!e the parameter within its
bod4.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


Cere is the start of a 6.. class declaration:
class foo
2
public:
void ,0foo f19
void 40const foo f19
void K0foo f1 const9
...
hich of the three member functions can alter the E?%OAT- member variables of the foo obHect that
activates the function*
) 'nl4 , can alter the private member variables of the obHect that activates the function.
) 'nl4 4 can alter the private member variables of the obHect that activates the function.
) 'nl4 K can alter the private member variables of the obHect that activates the function.
) Two of the functions can alter the private member variables of the obHect that activates the
function.
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


hat is the ma,imum depth of recursive calls a function ma4 make*
) >
) ;
) n 0where n is the ar!ument1
) There is no fi,ed ma,imum
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose n is the number of nodes in a complete Binar4 Tree then ma,imum steps re@uired for a
search operation are&
) #o!; 0n.>1 $>
) #o!; 0n.>1
) #o!; 0n1 P >
) #o!; 0n1
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


%n the linked list implementation of the stack class& where does the push member function places the new
entr4 on the linked list*
) At the head
) At the tail
) After all other entries that are !reater than the new entr4.
) After all other entries that are smaller than the new entr4.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose we have a circular arra4 implementation of the @ueue class& with ten items in the @ueue stored at
dataQ;R throu!h dataQ>>R. The 6AEA6%TN is <;& i.e.& the arra4 has been declared to be of siKe <;. here
does the push member function place the new entr4 in the arra4*
) dataQ>R
) dataQ;R
) dataQ>>R
) dataQ>;R
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


The e,pression AB.6/ is called *
) Erefi, e,pression
) Eostfi, e,pression
) %nfi, e,pression
) =one of these
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a binar4 tree where ever4 node has a value& ever4 node_s left subtree contains onl4 values
less than or e@ual to the node_s value& and ever4 node_s ri!ht subtree contains onl4 values that are !reater
then or e@ual *
) )trictl4 Binar4 Tree
) Binar4 )earch tree
) AO# tree
) All of these
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! binar4 search tree 0B)T1:
%f node A in the B)T is deleted& which two nodes are the candidates to take its place*
) M and %
) C and -
) ( and -
) # and M
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


LetMs ca'' t(e n!,e as a t(at reLuires re-7a'ancing: C!nsi,er t(e t.! cases giAen 7e'!."
>1 An insertion into left subtree of the left child of a
;1 An insertion into ri!ht subtree of the ri!ht child of a.
hich of the followin! statement is correct about these two cases.

>1 The insertion occurs outside 0i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation can fi, the
balance in these two cases.
;1 The insertion occurs inside 00i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation cannot fi, the
balance in these two cases
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


e access elements in AO# Tree in&
) #inear wa4 onl4
) =on #inear wa4 onl4
) Both linear and non linear wa4s
) =one of the !iven options.
uesti!n N!" 13 # Mar$s" 2 %


AO# Tree is&
) =on #inear data structure
) #inear data structure
) C4brid data structure 0Mi,ture of #inear and =on #inear1
) =one of the !iven options.
uesti!n N!" 14 # Mar$s" 2 %


Cow we can delete a node with two 6hilds in a binar4 search tree usin! its ri!ht sub tree.
uesti!n N!" 15 # Mar$s" 2 %

hat is Function 6all )tack Live short answer.
uesti!n N!" 20 # Mar$s" 3 %


,plain the two cases in which we appl4 double rotation in an AO# tree.
uesti!n N!" 21 # Mar$s" 3 %


Cere is a small binar4 tree.
/rite t(e !r,er !- t(e n!,es Aisite, in
c1 A Eost$order traversal
d1 A level$order traversal
uesti!n N!" 22 # Mar$s" + %


Elease consider the followin! AO# tree.
. %nsert new node 8I in this tree and make tree balance.
. rite balance factor of each node after and before insertin! node 8I.
uesti!n N!" 23 # Mar$s" + %


6onsider the followin! binar4 tree
)how the state of the tree after deletin! ;<.
MIDTERM EXAMINATION
Fa'' 2005
CS301- Data Structures #Sessi!n - +%
Re- N!" 44+*42
Ti6e" 20 6in
Mar$s" 34

uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! is a valid postfi, e,pression*
Y ab.c/d$
Y abc/.d$
Y abc./d$
Y 0abc/1.d$

uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
tree data structure is a
Y #inear data structure
Y =on$linear data structure
Y Lraphical data structure
Y (ata structure like @ueue

uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


A C!6p!un, Data Structure is the data structure which can have multiple data items of same t4pe
or of different t4pes. hich of the followin! can be considered compound data structure*
Y Arra4s
Y #ink#ists
Y Binar4 )earch Trees
Y All of the !iven options

uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


)uppose a pointer has been declared in main but has not assi!ned an4 variable address then
\\\\\\\Y\That pointer points to First b4te in main function
\\\\\\\Y\That pointer contains a =D## value
\\\\\\\Y\=one of these

\\\\\\\Y\That pointer points to an4 memor4 address

uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne

Cere
is the start of a 6.. class declaration:
class foo
2
public:
void ,0foo f19
void 40const foo f19
void K0foo f1 const9
...
hich of the three member functions can alter the E?%OAT- member variables of the foo obHect that
activates the function*
\\\\\\\Y\'nl4 , can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\'nl4 4 can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\'nl4 K can alter the private member variables of the obHect that activates the function.
\\\\\\\Y\Two of the functions can alter the private member variables of the obHect that activates the function.

uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne

The
operation for removin! an entr4 from a stack is traditionall4 called:
Y delete
Y peek
Y pop
Y remove

uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich statement of the followin! statements is incorrect*
Y #ists can be implemented b4 usin! arra4s or linked lists
Y A list is a se@uence of one or more data items
Y )tack is a special kind of list in which all insertions and deletions take place at one end
Y )tacks are easier to implement than lists

uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


Earameters in function call are passed usin!&
Y )tack
Y +ueue
Y Binar4 )earch Tree
Y AO# Tree

uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! se@uence of push operations in a stack:
stack.push0JIJ19
stack.push0J8J19
stack.push0J9J19
stack.push0J>0J19
stack.push0J>>J19
stack.push0J>;J19
\\\\\\\Y\I 8 9 >0 >> >;
\\\\\\\Y\9 8 >> >0 I >;
\\\\\\\Y\9 >0 8 >> >; I
\\\\\\\Y\9 >0 8 >; I >>

uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hat is the ma,imum depth of recursive calls a function ma4 make*
Y >
Y ;
Y n 0where n is the ar!ument1
Y There is no fi,ed ma,imum

uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! function:
void test7a0int n1
2
cout 88 n 88 " "9
if 0n:01
test7a0n$;19
3
hat is printed b4 the call test7a0<1*
Y < ;
Y 0 ; <
Y 0 ;
Y ; <

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


+ueue follows&
Y #ast in First out
Y First in #ast out
Y First in First out
Y =one of these

uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a binar4 tree where ever4 node has a value& ever4 node_s left subtree contains onl4 values
less than or e@ual to the node_s value& and ever4 node_s ri!ht subtree contains onl4 values that are !reater
then or e@ual *
\\\\\\\Y\)trictl4 Binar4 Tree
\\\\\\\Y\Binar4 )earch tree
\\\\\\\Y\AO# tree
\\\\\\\Y\All of these

uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne

Four
statements about trees are below. Three of them are correct. hich one is %=6'??-6T*
\\\\\\\Y\Trees are recursivel4 defined multi$dimensional data structures
\\\\\\\Y\The order of a tree indicates a ma,imum number of childen allowed at each node of the tree
\\\\\\\Y\A search tree is a special t4pe of tree where all values 0i.e. ke4s1 are ordered
\\\\\\\Y\%f Tree>_s siKe is !reater than Tree;_s siKe& then the hei!ht of Tree> must also be !reater than Tree;_s
hei!ht.

uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


Below is a binar4 search tree. %f we delete the value 50 usin! the al!orithm we discussed& what value will
be in the root of the remainin! tree*
Y 50
Y F0
Y I0
Y 80

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


777777777 is a data structure that can !row easil4 d4namicall4 at run time without havin! to cop4
e,istin! elements.
Y Arra4
Y #ist
Y Both of these
Y =one of these

uesti!n N!" 13 # Mar$s" 1 %

Live the names of basic +ueue 'perations
Ans:
(efinition: A collection of items in which onl4 the earliest added item ma4 be accessed. Basic operations
are add 0to the tail1 or en@ueue and delete 0from the head1 or de@ueue. (elete returns the item removed.
Also known as "first$in& first$out" or F%F'.

uesti!n N!" 14 # Mar$s" 1 %

Live
one benefit of usin! )tack.
%n computer science& a stack is a last in& first out 0#%F'1 abstract data t4pe and data structure. A stack can
have an4 abstract data t4pe as an element& but is characteriKed b4 onl4 two fundamental operations: push
and pop.the data structure itself enforces the proper order of calls.

uesti!n N!" 15 # Mar$s" 2 %

LetMs
ca'' t(e n!,e as a t(at reLuires re-7a'ancing: C!nsi,er t(e t.! cases giAen 7e'!."
>1 An insertion into left subtree of the left child of a
;1 An insertion into ri!ht subtree of the ri!ht child of a.
hich of the followin! statement is correct about these two cases.

>1 The insertion occurs outside 0i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation can fi, the
balance in these two cases.
;1 The insertion occurs inside 00i.e.& left$left or ri!ht$ri!ht1 in cases > and ;. sin!le rotation cannot fi, the
balance in these two cases

uesti!n N!" 20 # Mar$s" 3 %


6onsider the followin! se@uence of push operations in a stack:
stack.push0J>J19
stack.push0J;J19
stack.push0J5J19
stack.push0J<J19
stack.push0J5J19
stack.push0JFJ19
Nou can insert as man4 stack.pop01Js as 4ou like in the above se@uence of stack.pushJs to !et a desired
output. hich of the followin! cannot be an output*
A. >;5<5F
B. 5;5<>F
6. 5<;5F>
(. 5<;F>5
-. 5<;>F5

uesti!n N!" 21 # Mar$s" + %

FiAe
s(!rt ans.ers !- t(e -!''!.ing Luesti!ns"
5. h4 #ist wastes less memor4 as compared to Arra4s.
Ans:
>. #inked lists do not need conti!uous blocks of memor49 e,tremel4 lar!e data sets stored in an arra4
mi!ht not be able to fit in memor4.
;. #inked list stora!e does not need to be preallocated 0a!ain& due to arra4s needin! conti!uous memor4
blocks1.
5. %nsertin! or removin! an element into a linked list re@uires one data update& insertin! or removin! an
element into an arra4 re@uires n 0all elements after the modified inde, need to be shifted1.
Arra4 is a collection of same data t4pe. %n linked list there are two field one is address and other is
pointer. %n arra4 elements are arran!ed in a specific order
F. h4 we can chan!e the siKe of list after its creation when we can not do that in simple arra4s.
)ome how the answer will be same as part > because %nsertin! or removin! an element into a linked list
re@uires one data update& insertin! or removin! an element into an arra4 re@uires n 0all elements after the
modified inde, need to be shifted1.
Arra4 is a collection of same data t4pe. The siKe of arra4 is mentioned with its declaration. in arra4s the
elements are in conti!uous position. one must after another. while in linked list we !ave the address of
ne,t element in the ne,t part of node.

uesti!n N!" 22 # Mar$s" 10 %


6onvert the followin! infi, e,pression into postfi, e,pressions usin! stack 0)how complete steps1
>$; 55$0<.5/F1/I
111*1<1 1+1111*11 111111 1141 14M4144M1 1111
)tep > Eost fi, stack


I I
I
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne
/(ic( !ne !- t(e -!''!.ing state6ent is NOT c!rrect :
Y %n linked list the elements are necessaril4 to be conti!uous
Y %n linked list the elements ma4 locate at far positions in the memor4
Y %n linked list each element also has the address of the element ne,t to it
Y %n an arra4 the elements are conti!uous
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
In a pr!gra6 a re-erence Aaria7'e? sa< 8? can 7e ,ec'are, as
Y int X, 9
Y int /, 9
Y int , 9
Y =one of the !iven options
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
Lin$e, 'ists are c!''ecti!ns !- ,ata ite6s 0'ine, up in a r!.0 ? inserti!ns an, ,e'eti!ns can
7e 6a,e !n'< at t(e -r!nt an, t(e 7ac$ !- a 'in$e, 'ist:
Y True
Y False
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
A Linear Data Structure is t(e ,ata structure in .(ic( ,ata e'e6ents are arrange, in a
seLuence !r a 'inear 'ist: /(ic( !- t(e -!''!.ing is N!n Linear Data Structure1
Y Arra4s
Y #ink#ists
Y Binar4 )earch Trees
Y =one of these
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
A @ueue where the de$@ueue operation depends not on F%F'& is called a priorit4 @ueue
Y
Y True
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! statements is correct*
Y Arra4 siKe is fi,ed once it is created.
#ink #ist siKe is fi,ed Y once it is created.
Binar4 )earch Tree siKe is Y fi,ed once it is created
AO# Tree siKe is fi,ed Y once it is created
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is correct about pointers*
The4 alwa4s point to Y different memor4 locations
The4 ma4 point to a sin!le Y memor4 location
Y The address of two pointer variables is same
=one of these Y
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! abstract data t4pes are ='T used b4 %nte!er Abstract (ata t4pe !roup*
Y short
int Y
float Y
lon! Y
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for addin! an entr4 to a stack is traditionall4 called :
add Y
append Y
insert Y
Y push
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for removin! an entr4 from a stack is traditionall4 called:
delete Y
peek Y
Y pop
remove Y
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
e can add elements in +D-D- From 777777777
Front Y
Y ?ear
From Both ?are and Front Y
=one of these Y
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
The difference between a binar4 tree and a binar4 search tree is that &
a binar4 search tree has Y two children per node whereas a binar4 tree can have none& one&
or two children per node
Y in binar4 search tree nodes are inserted based on the values the4 contain
in binar4 tree nodes are Y inserted based on the values the4 contain
none of these Y
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose n is the number of nodes in a complete Binar4 Tree then ma,imum steps re@uired for a
search operation are&
Y #o!; 0n.>1 $>
#o! Y ; 0n.>1
#o! Y ; 0n1 P >
#o! Y ; 0n1
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
The followin! is a se!ment of a 6 pro!ram.
int p@r0Binar4=ode t1
2 if 0t GG null 1
return $>9
else
return >.ma,0p@r0t.left1&p@r0t.ri!ht11 3
%dentif4& what the above pro!ram intend0s1 to do*
6ompute the hei!ht of a Y binar4 tree usin! an in$order traversal
6ompute the hei!ht of a Y binar4 tree usin! a pre$order traversal
Y 6ompute the depth of a binar4 tree usin! a pre$order traversal
6ompute the depth of a Y binar4 tree usin! a post$order traversal
+uestion =o: >5 0 Marks: > 1 $ Elease choose one
6onsider the followin! infi, e,pression:
5 . 5 / F P I / 08 . 51
hich of the followin! is a correct e@uivalent e,pression0s1 for the above*
Y 5 F 5 . / I 5 8 . $ /
Y 5 F 5 I 5 8 . / . $ /
Y 5 5 F . / I 8 5 . $ /
Y 5 5 F / . I 8 5 . / $
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
An arra4 is a !roup of consecutive related memor4 locations.
Y True
Y False
uesti!n N!" 13 # Mar$s" 1 %
%s this a correct statement* Live answer in Nes or =o.
A node cannot be deleted& when the node to be deleted has both left and ri!ht subtrees.
=o& it can be deleted.
uesti!n N!" 14 # Mar$s" 1 %
(eletin! a leaf node in binar4 search tree involves settin! 777777 pointerAs of that nodes parent
as null.
>
;
5
<
uesti!n N!" 15 # Mar$s" 2 %
(escribe an4 two uses of priorit4 @ueues*
uesti!n N!" 20 # Mar$s" 3 %
Cow we evaluate postfi, e,pressions*
uesti!n N!" 21 # Mar$s" + %
Followin! is the while loop used in level$order traversal:
while0 ^@.empt401 1
2
tree=ode G @.de@ueue019
cout 88 /0tree=ode$:!et%nfo011 88 " "9
if0tree=ode$:!et#eft01 ^G =D## 1
@.en@ueue0 tree=ode$:!et#eft0119
if0tree=ode$:!et?i!ht01 ^G =D## 1
*
3
hat should be the statement to replace the @uestion mark in the loop above:
uesti!n N!" 22 # Mar$s" 10 %
rite a friend function for a #inked #ist class called mer!e#ists that takes two non$empt4 lists&
mer!e these two lists and return the mer!ed list.
Dse the followin! function protot4pe:
#ist mer!e#ists0#ist ,&#ist 41
111*1<1 1+1111*11 111111 1141 14M4144M1 11
11
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne
A subscript of an arra4 ma4 be an inte!er or an inte!er e,pression.
Y True
Y False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
(oubl4 #inked #ist alwa4s has one =D## pointer.

Y True
Y False
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne

%n which of the traversal method& the recursive calls can be used to traverse a binar4 tree *
Y %n preorder traversal onl4
Y %n inorder traversal onl4
Y %n postorder traversal onl4
Y All of the !iven options
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
A tree is an AO# tree if

Y An4 one node fulfills the AO# condition
Y At least half of the nodes fulfill the AO# condition
Y All the nodes fulfill the AO# condition
Y =one of the !iven options
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member
variables called data and ne,t=ode1. hat boolean e,pression will be true when cursor refers to
the tail node of the list*

Y 0current=ode GG null1
Y 0current=ode$:ne,t=ode GG null1
Y 0ne,t=ode.data GG null1
Y 0current=ode.data GG 0.01
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose that the class declaration of )ome6lass includes the followin! function protot4pe.
bool #essThan0 )ome6lass another'bHect 19
/(ic( !- t(e -!''!.ing tests in t(e c'ient c!,e c!rrect'< c!6pares t.! c'ass !7Vects a'p(a
an, 7eta1

Y if 0alpha 8 beta1
Y if 0alpha.#essThan0beta11
Y if 0#essThan0alpha& beta11
Y if 0#essThan0alpha1.beta1
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
%n 6 what is the operation that 4ou can not do with primitive t4pes*
Y Assi!n a value to primitive t4pe usin! a literal
Y (eclare primitive t4pes to be constant usin! the 6onst ke4word
Y 6reate a new instance of primitive t4pe with =ew ke4word
Y =one of these
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for addin! an entr4 to a stack is traditionall4 called :
Y add
Y append
Y insert
Y push
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
The operation for removin! an entr4 from a stack is traditionall4 called:
Y delete
Y peek
Y pop
Y remove
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider the followin! se@uence of push operations in a stack:
stack.push0JIJ19
stack.push0J8J19
stack.push0J9J19
stack.push0J>0J19
stack.push0J>>J19
stack.push0J>;J19

Y I 8 9 >0 >> >;
Y 9 8 >> >0 I >;
Y 9 >0 8 >> >; I
Y 9 >0 8 >; I >>
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
77777777 is the ma,imum number of nodes that 4ou can have on a stack$linked list *
Y hero
Y ;n 0where n is the number of nodes in linked list1
Y An4 =umber
Y =one of these
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! can be used to reverse a strin! value&

Y )tack

Y +ueue

Y Both of these

Y =one of these

uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
6onsider the followin! tree&






Cow man4 leaves does it have*

Y ;
Y <
Y F
Y 9
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
AO# Tree is&

Y =on #inear data structure

Y #inear data structure

Y C4brid data structure 0Mi,ture of #inear and =on #inear1

Y =one of the !iven options.



uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
The followin! are statements related to @ueues.

0i1 The last item to be added to a @ueue is the first item to be removed
0ii1 A @ueue is a structure in which both ends are not used
0iii1 The last element hasnJt to wait until all elements precedin! it on the @ueue are removed
0iv1A @ueue is said to be a last$in$first$out list or #%F' data structure.

hich of the above isAare related to normal @ueues*

Y 0iii1 and 0ii1 onl4
Y 0i1& 0ii1 and 0iv1 onl4
Y 0ii1 and 0iv1 onl4
Y =one of the !iven options

uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
An arra4 is a !roup of consecutive related memor4 locations.

Y True
Y False


uesti!n N!" 13 # Mar$s" 1 %
%n which of traversal method& recursion can not be applied.*

uesti!n N!" 14 # Mar$s" 1 %
hat is meant b4 an empt4 stack*

uesti!n N!" 15 # Mar$s" 2 %
%s the followin! statement correct* %f 4our answer is =o& then correct it.
SA tree is an AO# tree if at least half of the nodes fulfill the AO# conditionU


uesti!n N!" 20 # Mar$s" 3 %
The followin! function is performin! some operation on the elements of a sin!l4 link list please
tell what this functions is doin!&
A!i, Lin$List""6<ster<#%]
N!,e Z te6p > (ea,N!,eR
int resu't > 0R
.(i'e# te6p-[getNe8t#% J> NNLL %]
te6p > te6p-[getNe8t#%R
int Aa'ue > te6p-[get#%R
i-#Aa'ue ^ 2 >> 0%
] Aa'ue 99R
te6p-[set#Aa'ue%R
_
_
_


uesti!n N!" 21 # Mar$s" + %
)ee the code below & !ive comments a!ainst each line and identif4 which line will result in error*
>. void main0void1
;. 2
5. int actual G >;59
<. int Xother G actual9
5.
F. int natural G <5F9
I. other G Xnatural9
8. 3

uesti!n N!" 22 # Mar$s" 10 %
Dra. APL Tree 7< -!''!.ing ,igits 34? 21? 2+? 24? 34? 32? 3+ an, a's! per-!r6 necessar<
r!tati!n? .(i'e s(!.ing a'' t(e inter6e,iate trees 7eing create, in t(e pr!cess: In eac(
stage? t(e APL trans-!r6ati!n s(!u', 7e c!n,ucte, at a ,iscrepanc< t(at is -art(est -r!6
t(e r!!t:
MIDTERM EXAMINATION
)prin! ;0>0
6)50>$ (ata )tructures
?ef =o: >5<95IF
Time: F0 min
Marks: 58
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


%n an arra4 we can store data elements of different t4pes.
) True
) False
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


%n an arra4 list the current element is
) The first element
) The middle element
) The last element
) The element where the current pointer points to
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! callin! methods does not chan!e the ori!inal value of the ar!ument in the
callin! function*
) =one of the !iven options
) 6all b4 passin! the value of the ar!ument
) 6all b4 passin! reference of the ar!ument
) 6all b4 passin! the address of the ar!ument
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! statements is ='T correct*
) Arra4 siKe can be chan!ed after its creation.
) #ink #ist siKe can be chan!ed after its creation
) Binar4 )earch Tree siKe can be chan!ed after its creation
) AO# Tree siKe can be chan!ed after its creation
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


)uppose that the class declaration of )ome6lass includes the followin! function protot4pe.
bool #essThan0 )ome6lass another'bHect 19
/(ic( !- t(e -!''!.ing tests in t(e c'ient c!,e c!rrect'< c!6pares t.! c'ass !7Vects a'p(a an, 7eta1
) if 0alpha 8 beta1
) if 0alpha.#essThan0beta11
) if 0#essThan0alpha& beta11
) if 0#essThan0alpha1.beta1
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


A @ueue is a 77777777data structure& whereas a stack is a 77777777data structure.
) F%F'& #%F'
) #%F'&F%F'
) none of these
) both of these
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! operators has hi!her priorit4 than all of others *
) Multiplication operator
) Minus operator
) Elus operator
) -,ponentiation operator
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


-ach node in Binar4 )earch Tree has
) > pointer
) ; pointers
) 5 pointers
) < pointers
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


Four statements about trees are below. Three of them are correct. hich one is %=6'??-6T*
) Trees are recursivel4 defined multi$dimensional data structures
) The order of a tree indicates a ma,imum number of childen allowed at each node of the tree
) A search tree is a special t4pe of tree where all values 0i.e. ke4s1 are ordered
) %f Tree>_s siKe is !reater than Tree;_s siKe& then the hei!ht of Tree> must also be !reater than Tree;_s
hei!ht.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! is "T?D-" about arra4s&
) e can increase the siKe of arra4s after their creation.
) e can decrease the siKe of arra4s after their creation.
) e can increase but can_t decrease the siKe of arra4s after their creation.
) e can neither increase nor decrease the arra4 siKe after their creation.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


)earchin! an element in an AO# tree take ma,imum 7777777 time 0where n is no. of nodes in AO#
tree1&
) #o!;0n.>1
) #o!;0n.>1 $>
) >.<< #o!;n
) >.FF #o!;n
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


There isAare 77777777 caseAs for rotation in an AO# tree&
) >
) 5
) ;
) <
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! statements.
0,iii1 A binar4 tree can contain at least ;
#
=odes at level #.
0,iv1 A complete binar4 tree of depth d is a binar4 tree that contains ;
#
=odes at each level #
between 0 and d& both inclusive.
0,v1 The total number of nodes 0Tn 1 in a complete binar4 tree of depth d is ;
d.>
$ > .
0,vi1 The hei!ht of the complete binar4 tree can be written as h G lo! ; 0Tn.>1$> where Tn is
Total number of =odes.
hich one of the followin! is correct in respect of the above statements re!ardin! the Binar4 trees*
) 0i1 and 0iii1 onl4
) 0i1& 0ii1 and 0iii1 onl4
) 0ii1 and 0iii1 onl4
) 0ii1& 0iii1 and 0iv1 onl4
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! infi, e,pression.
5 . FA;
%f one converts the above e,pression into postfi,& what would be the resultant e,pression*
) 5FA . ;
) 5 F ; A .
) 5 F A ; .
) AF; . 5
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is a non linear data structure*
) #inked #ist
) )tack
) +ueue
) Tree
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


X9\ is a EEEEEEEEEo!erator.
) Dnar4
) Binar4
) Ternar4
) =one of the above
uesti!n N!" 13 # Mar$s" 2 %


hich process places data at the back of the @ueue*
uesti!n N!" 14 # Mar$s" 2 %


Cow we can delete a node with two 6hilds in a binar4 search tree usin! its ri!ht sub tree.
uesti!n N!" 15 # Mar$s" 2 %


h4 we use ?eference Oariables. Live one e,ample.
uesti!n N!" 20 # Mar$s" 3 %


T(e n!,es !- a 7inar< tree (aAe ,ata 1? 2? 3? *: T(e in-!r,er traAersa' !- t(e tree <ie',s 2?1?*?3: T(e
p!st!r,er traAersa' is 2? *? 3? 1: T(e r!!t !- t(e tree is at 'eAe' 0:
3" /(ic( Aa'ue is in t(e rig(t c(i', !- t(e r!!t1 #1 &t%
0A1 > 0B1 ; 061 5 0(1 < 0-1 none
uesti!n N!" 21 # Mar$s" 3 %


hat normall4 is the se@uence of operations while constructin! an AO# tree*
uesti!n N!" 22 # Mar$s" + %


Cere is a small binar4 tree:
1*
T Y
2 11
T Y T Y
1 3 10 30
T T
3 *0
rite the order of the nodes visited in:
A. An in$order traversal:
B. A pre$order traversal:
uesti!n N!" 23 # Mar$s" + %


Is t(e giAen tree is an APL tree1 I- N!t t(en re,ra. is s! t(at it 7ec!6es APL
<0 mc@_s mostl4 from past papers:
< @uestion havin! ; marks
< @uestion havin! 5 marks
< @uestions havin! 5 marks
a code was !iven and i had to correct the error0;1
hat is the >st step of huffman encodin! 051
% had to write the fre@uenc4 of the te,t "Cuffman -ncodin!" 051
Q; 9 I 5 8R i had to sort it usin! insertion sort. 051
an avl tree was !iven and i had to sort it after insertion of another di!it. 051
a min heap was !iven and i had to rearran!e it after deletion of the di!it at >st postition. 051
Eroperties of e@uivalent class. 051

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!/am


)ubHective
>.The relation : between real numbers is e@ualant relation or not** e,plain.
;.what are different applications of hashin!*
5.write down the function A method calls of heap that are used to increase or decrease the element _p_ with delta.
<.while makin! trees from fre@uenc4 of word in Cuffman encodin! scheme.
for smaller lists linear insertion sort but for lar!er lists @uick sort is better** Hustif4
5.threaded biner4 tree
F X I & @uestion disHoint me se the&
8 what is c.. templete *
9.6alculate Cuffman code of the characters A&B&6&(&-
>0.An e,pression tree is not a biner4 search tree or not ** !ive the reasons
>>.sortin! al!rithm me se tha& form sort Q>8 >5 >I ;5 >9R
>;.code for removin! an element from a linked list data structure if it is implimentation b4 usin! linked memor4
methods

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!/am


+uestion =o: > )uppose we have the followin! representation for a complete Binar4 )earch Tree& tell the #eft
and ?i!ht child nodes and Earent node of the node (
A B 6 ( - ( - F L C % M V # M = ' E + ? ) T
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9 ;0 ;> ;;
+uestion =o: 0; Cere is an arra4 with e,actl4 >5 elements: > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5. )uppose that we
are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4 e,aminin! two or fewer
numbers from the arra4.
+D-)T%'= =' 5.
(ecribe an4 use of heap*
+D-)T%'= =' <.rite one e,ample of hashin!*

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!>am


>: (ifferentiate followin! e,pression with the help of e,pression tree
f . d / s . b / m . t / n
0f . 0d/ s11 . 000b 8 m1 .t1/n
;: sort the list Q; 9 I 5 8R throu!h insertion sort al!orithm. )how each step
5: evaluate the followin! post fi, e,pression
F>F5$./<;>AAA
<: describe an4 one uses of _heap Sdata structure.
5: what is table abstract data t4pe*
F: what are the characteristics of a !ood hash function*

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!(am


>1 6onstruct Ma, heap from !iven arra4 5 makrs
;1 Cuffman codin! of a sentence table construct karna tha
51 Cuffman vale of AB6 and ( from a !iven tree
<1 Liven arra4 sat mode >> ki madad sa4 hash value maloom karna thi aor table banana tha
51 #inked list aor skip list ki ; characteristics likhna theen
>. define binar4 tree
;. when an item should be added in arra4
5. a level order& and post order
<. draw a new heap after removin! an4 element from !iven heap.
5. correct the code.
F. mer!e sort
I. characterstics of skip list.
8. name implementation techni@ue of disHoint set for sorted data.
+: hat is stack*
A: )tack is a collection of elements arran!ed in a linear orderU
+: what are the characteristic of a !ood hash function*
A: %f the ke4s are inte!ers& ke4TT is !enerall4 a !ood hash function& unless the data has some undesirable
features. For e,ample& if T G >0 and all ke4s end in Keros& then ke4TT G 0 for all ke4s. )uppose we have
emplo4ee %( i.e. an inte!er. The emplo4ee %( ma4 be in hundreds of thousand. Cere the table siKe is >0. %n this
case& we will take mod of the emplo4ee %( with the table siKe to !et the hash value. Cere& the entire emplo4ee
%(s end in Kero. hat will be the remainder when we divide this number with >0* %t will be 0 for all emplo4ees.
)o this hash function cannot work with this data. %n !eneral& to avoid situations like this& T should be a prime
number.
+: !ive an4 three facts about buildin! heap*
A: methods of heap
,ecreaseSe<#p? ,e'ta%
increaseSe<#p? ,e'ta%
re6!Ae#p%

+: wh4 binar4 search cannot be used for link list*
A: Because it store sorted data.

+: Cow can we appl4 F%=( operation on elements combined throu!h union operation*
Ans.er"- #&age 352%
e !ive an element to the find method and it returns the name of the set.

+: )ort the list Q; 9 I 5 8Rthrou!h insertion sort al!orithm show each step.
Ea!e 9 moaaK file

+: what is difference bAw AO# and binar4 tree*
A: A binar4 search tree has two children per node whereas a binar4 tree can have none& one& or two children per
node
" /(at are ,iAi,e n c!nLuer s!rting 6et(!,s1 N'!g 7ase 2 N
A" Three al!orithm fall under divide and con@uer
merge sort
uic7 sort
heap sort
" .(at are pr!perties !- eLuiAa'ence set
Ans" A binar4 relation ? over a set ) is called an e@uivalence relation if it has followin! properties`:
>. ?efle,ivit4: for all element , K )& , ? ,
;. )4mmetr4: for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
5. Transitivit4: for all elements ,& 4 and K& if , ? 4 and 4 ? K then , ? K
-,ample9 sets of peoples &electric circuit domain

" C!nAert t(e giAen in-i8 -!r6 t! p!st-i8 -!r6:
A9;TC-DOE-F
Ans.er" AB.6A($-F $Z
" G!. .e can i6p'e6ent Ta7'e ADT using Lin$e, List
A" #ist linked list is one choice to implement table abstract data t4pe. For unsorted elements& the insertion at
front operation will take constant time. But if the data inside the list is kept in sorted order then to insert a new
element in the list& the entire linked list is traversed throu!h to find the appropriate position for the element.
" I- .e a''!. assign6ent t! c!nstants .(at .i'' (appen1
A" )uppose aa` has the value number 5. =ow we assi!ned number ; the number 5 i.e. all the number ; will
become number 5 and the result of ; . ; will become F. Therefore it is not allowed.
" G!. (eap s!rt .!r$s t! s!rt a set !- ,ata:
A" Min heap and ma, heap are used to sort the data. Min heap convert the data in ascendin! sorted order and
ma, heap convert the in descendin! order.
" FiAe <!ur c!66ent !n t(e state6ent t(at (eap uses 'east 6e6!r< in arra< representati!n !- 7inar<
trees: Uusti-< <!ur ans.er in eit(er case:
A" A heap is a complete binar4 tree& so it is eas4 to be implemented usin! an arra4 representation %t is a binar4
tree with the followin! properties:$

9roperty !1 it is a complete binary tree

9roperty '1 the 2alue stored at a node is greater or eual to the 2alues stored at the
children

+rom property ' the largest 2alue of the heap is always stored at the root

" G!. .e can use c!ncept !- eLuiAa'ence re'ati!ns t! generate a MaDe:
A" Al!orithm is as follows
6andomly remo2e walls until the entrance and exit cells are in the same cell
6emo2al of the wall is the same as doing a union operation
*o not remo2e randomly chosen wall if the cells it separates are already I the same set.
&( 6 9 5 . 4 ) - 3 2 5how the 8rst 8ve merging steps %or +erge sort on this
array
Ea!e >5 moaaK file
" /(at is DisV!int Sets1 E8p'ain .it( an e8a6p'e:
Ans" DisV!int sets - Two sets are disHoint if the4 have no elements in common. -,ample:$)uppose there are
man4 people around 4ou. Cow can we separate those who are related to each other in this !atherin!* e make
!roups of people who are related to each other. The people in one !roup will sa4 that the4 are related to each
other. )imilarl4 we can have man4 !roups. )o ever4 !roup will sa4 that the4 are related to each other with famil4
relationship and there is no !roup that is related to an4 other !roup. The people in the !roup will sa4 that there is
not a sin!le person in the other !roup who is related to them.


" In t(e arra< representati!n !- uni!n .(at represents -11
A" This shows that this node has no parent. Moreover& this node will be a root that ma4 be a parent of some other
node
" /(ic( ,ata structure is 7est -!r pri!rit< Lueue1
A" The use of priorit4 @ueue with the help of heap is a maHor application. The priorit4 @ueue is itself a maHor data
structure& much$used in operatin! s4stems. )imilarl4 priorit4 @ueue data structure is used in network devices
especiall4 in routers. Ceap data structure is also emplo4ed in sortin! al!orithms
" G!. .e can app'< Nni!n !perati!n !n e'e6ents initia''< in ,i--erent sets1
A" To e,ecute the union operation in two sets& we mer!e the two trees of these sets in such a manner that the root
of one tree points to the root of other. )o there will be one root& resultin! in the mer!er of the trees.

" /(at is S$ip 'ist1
" /rite t.! c(aracteristics !- s$ip 'ist1 2 6ar$s
Ans.er"- #&age **21 A skip list for a set ) of distinct 0ke4& element1 items is a series of lists )0& )> & W & )h such
that
] -ach list )i contains the special ke4s .b and $b
] #ist )0 contains the ke4s of ) in non$decreasin! order
] -ach list is a subse@uence of the previous one& i.e.& )0 )> W )h
] #ist )h contains onl4 the two special ke4s

" /(at is t(e .!rst case !- W-in,M !perati!n !- t(e 'in$e, 'ist1
A: orst case of the find method is that it has to search the entire list from be!innin! to end.

" /(at is t(e ,ra.7ac$ !- using arra< t! st!re X;inar< Searc( TreesM1
A"- #&age 21% The drawback of usin! is the limitations that arra4 bein! of fi,ed siKe can onl4 store a fi,ed
number of elements. Therefore& no more elements can be stored after the siKe of the arra4 is reached.

" FiAe an< 3 c(aracteristics !- uni!n 7< .eig(t 6et(!,1
A"- #&age *04% Followin! are the salient characteristics of this method:

.aintain siGes 8number of nodes; of all trees, and during union.

.a7e smaller tree, the sub?tree of the larger one.

Implementation1 for each root node i, instead of setting parentLiM to ?!, set it to ?7 if tree
rooted at i has 7 nodes.


" Geig(t !- a tree is + -in, su6 !- (eig(ts1
A: Cei!ht G 5
=odes G ;Zh G ;Z5 G5;
)um of =odes G =$0h.>1G 5;$05.>1 G 5;$F G ;F

" G!. can .e searc( an e'e6ent in s$ip 'ist1
A: e search for a ke4 , in the followin! fashion:
e start at the first position of the top list
] At the current position p& we compare , with 4 ke40after0p11
] , G 4: we return element0after0p11
] , : 4: we cscan forward
] , 8 4: we cdrop down
] %f we tr4 to drop down past the bottom list& we return ='7)D6C7V-N
" /(en (as(ing is NOT suita7'e1
A" Cash tables are not so !ood if there are man4 insertions and deletions& or if table traversals are needed d in
this case& AO# trees are better
" FiAe an< t(ree i6p!rtant -acts a7!ut 7ui',ing a (eap:1
A" Followin! are some of the important facts about buildin! a heap.
e )uppose we are !iven as input = ke4s 0or items1 to build a heap of the ke4s.
e 'bviousl4& this can be done with = successive inserts.
e -ach call to insert will either take unit time 0leaf node1 or lo!;= 0if new ke4 percolates all the wa4 up to the
root1.
e The worst time for buildin! a heap of = ke4s could be =lo!;=.
e %t turns out that we can build a heap in linear time.
e )uppose we have a method percolate(own0p1 that moves down the ke4 in node p
downwards.
e This is what happens in deleteMin.e have used the word ke4s in the first point.

" E8p'ain t(e -!''!.ing ter6
ans.er"
>.. 6ollision
;.. #inear probin!
5.. +uadratic probin!..
C!''isi!n" hen two values hash to the same arra4 location& this is called a collision8.
Linear &r!7ing hen there is a collision& some other location in the arra4 is found. This is known as linear
probin!. %n linear probin!& at the time of collisions& we add one to the inde, and check that location. %f it is also
not empt4& we add ; and check that position. )uppose we keep on incrementin! the arra4 inde, and reach at the
end of the table. e were unable to find the space and reached the last location of the arra4.
ua,ratic &r!7ing %n the @uadratic probin! when a collision happens we tr4 to find the empt4 location at inde,
. >Z;. %f it is filled then we add ;Z; and so on.
+uadratic probin! uses different formula:
>. Dse F0i1 G i; 0s@uare of i1 to resolve collisions
;. %f hash function resolves to C and a search in cell C is inconclusive& tr4
C . >;& C . ;;& C . 5;

" FiAe !ne e8a6p'e !- Gas(ing
A" Cashin! can be used to store the data. )uppose we have a list of fruits. The names of Fruits are in strin!. The
ke4 is the name of the fruit. e will pass it to the hash Function to !et the hash ke4. Cash6ode 0"apple"1 G 5
e pass it to the strin! capple . ?esultantl4& it returns a number 5.

" /!rst case !- se'ecti!n s!rt1
A" worst case occurs if the arra4 is alread4 sorted in descendin! order. =onetheless& the time re@uire b4 selection
sort al!orithm is not ver4 sensitive to the ori!inal order of the arra4 to be sorted

" C99 c!,e -!r ,!u7'< 'in$ 'ist1 + 6ar$s
A" Ea!e ;5 moaaK file
" Gere is an arra< .it( e8act'< 1+ e'e6ents"
1 2 3 * + 2 3 4 5 10 11 12 13 1* 1+:
Supp!se t(at .e are ,!ing a 7inar< searc( -!r an e'e6ent: In,icate an< e'e6ents t(at .i'' 7e -!un, 7<
e8a6ining t.! !r -e.er nu67ers -r!6 t(e arra<: #Mar$s" +%
Ans.er"
e see the data in arra4 it is sorted so performin! a B) is !ood. =ow consider arra4
A G 2>& ;& 5& < & 5& F& I& 8& 9& >0& >>& >;& >5& ><& >53
As binar4 search starts first element we e,amine mid element which is at inde, arra4)iKeA;0i.e. >5A; G I1& which
is I. =ow if the element is to compare is less then I we will consider the left part of arra4 from the mid which is
2>& ;& 5& <& 5& F3. =ow a!ain choose the mid element& which is 5 and campare with it. %f less then divide the arra4
a!ain.
6ome to ?i!ht side we have the followin! arra428& 9& >0& >>& >;& >5& ><& >53 if we divide it in middle we !et the
element >;. Based on value a!ain comparison divide the arra4 a!ain and do the same steps a!ain
)o the possible numbers are if we e,amine the arra4 are
I& 5& >& >;& 9
For more clarit4 see e,ample from handout !iven on pa!e <5>.
" uni!n !perati!n: Fr!6 n!tes" E8a6p'e !n pageK *00

9ermalin7 6eply by 9rince on .arch $, '"!> at !'1>#pm


Thanks
Faisal (ar

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!(am


>.The relation : between real numbers is e@ualant relation or not** e,plain.
;.what are different applications of hashin!*
5.write down the function A method calls of heap that are used to increase or decrease the element _p_ with delta.
<.while makin! trees from fre@uenc4 of word in Cuffman encodin! scheme.
for smaller lists linear insertion sort but for lar!er lists @uick sort is better** Hustif4
5.threaded biner4 tree
F X I & @uestion disHoint me se the&
8 what is c.. templete *
9.6alculate Cuffman code of the characters A&B&6&(&-
>0.An e,pression tree is not a biner4 search tree or not ** !ive the reasons
>>.sortin! al!rithm me se tha& form sort Q>8 >5 >I ;5 >9R
>;.code for removin! an element from a linked list data structure if it is implimentation b4 usin! linked memor4
methods

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!(am


> : AO# tree me node del krke table banana tha ..
; : ?epresentation of B)T ..
5 : (efinations of 6ollision & line probin! & @uardatic probin! ..
< : Make correction in pro!ram 0 arra41 ..
< @uestion of 5 marks ...
> : 6ollision ..
; : -@uivalence relation . e,amples ..
5 : leaf and non$leaf nodes batane tha4 ..
< : 5 wa4s to build a heap ..
< @uestion of ; marks ..
> : mid usin! binar4 kch tha ..
; : huffman encodin! ..
5 : 6haracteristic of huffman encodin! ..
< : abt binar4 tree ...

9ermalin7 6eply by NCOPQRS TUVWOCN on .arch /, '"!> at !"1!$am


Already added888
http<33'ustudents8nin8com3roup3cs3-0datastructures3forum3topics3u888

9ermalin7 6eply by JJJ +aisal *ar JJJ on .arch /, '"!> at !"1!$am


+ =' > (ecribe an4 use of heap*
+ =' ; (ecribe the condition of second case of deletion in AO# tree*
+ =' 5 Cow we can search element in skip list*
+ =' < Dsin! union find data strecture.?elation is !iven below
union0o&A1 & union0B&M1&union0A&L1&union0o&=1union0M&C1 union0A&61
union0o&B1 &union0M&'1*
+ =' 5 hen hashin! is not suitable*
+ =' F Cow we !enerat MaKe*
+=' I Cow man4 leaf and non$leaf nodes are present in a
complete binar4 tree if its depth is I*
+ =' 8 rite 6.. al!orithm for Binar4 )earch
>.Live one e,ample of Cashin!. 0;1
;.wh4 threaded binar4 tree is effecient 0;1
5.effect of sorted data on Binar4 )earch0;1
<.how to find parent & left child and ri8 child of heap051
5.comparison between linear insertion sort nd @uick sort 051
F.hat is an -@uivalent relation* Live an4 two e,amples051
I.rite down the c.. code for selection sort 051
8.(ata dia !4a tha %nsertion sort find krna tha 051
9.AOl tree tha > node delete kr k rotation krni thi 051
onnl4 dua for m4 reslut needed... pllllllllK
6)<05 EAE-? >. 6?-AT- view name student list on customer table to show onl4 6)T7%( in asc of those
customer of !uHranwala cit4 customer06)T7%( &6)T $=AM- &cit4 1 ;. insert value cs;>> operatin! s4stem &
<&mcs in course table with s@l command 5. Hustif4 correct or in correct that !ood approach to create on non ke4
attribute 5. deadlock e,ample <. demoraliKation benefit n !ive two real world e,mple 5. transaction n ;
properties

cs50> <0 mc@s th4 Ho k past ma sa >0T a4 th4.
; marks k @uestion past ma sa th4
>1 aik tha k tree ki hie!ht di hui thi sum of hei!ht of nodes nikalna tha .
hei!ht of a tree is 5 find sum of hei!hts 0;1
Answer:$
Cei!ht G 5
=odes G ;Zh G ;Z5 G5;
)um of =odes G =$0h.>1G 5;$05.>1 G 5;$F G ;F
;1 find and remove ka @uestion tha hashin! ma.
51 biultinheap pa @uestion tha k a!r apko aik list di ho uss sa heap kes4 bna4 !4 uska Hust procedure likhna tha
<1min heap bnani thi .
51 remove ka c.. code likhna tha.
F1 buble sort ka @uestion tha .

<0 mc@_s mostl4 from past papers:
< @uestion havin! ; marks
< @uestion havin! 5 marks
< @uestions havin! 5 marks
a code was !iven and i had to correct the error0;1
hat is the >st step of huffman encodin! 051
% had to write the fre@uenc4 of the te,t "Cuffman -ncodin!" 051
Q; 9 I 5 8R i had to sort it usin! insertion sort. 051
%f we insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish balance* Mustif4
4our answer.
Answer:$
=o& one rotation is not alwa4s sufficient to re$establish balance. For e,ample& consider the insertion of the shaded
node in the followin! AO# tree:
Thou!h the ori!inal tree was balanced& more than one rotation is needed to restore balance followin! the
insertion.

This can be seen b4 an e,haustive enumeration of the rotation possibilities.
The problem asks for a tree of hei!ht <& so we can e,tend the above e,ample into a lar!er tree:


a min heap was !iven and i had to rearran!e it after deletion of the di!it at >st postition. 051
Eroperties of e@uivalent class. 05
corect form is

>.The relation : between real numbers is e@ualant relation or not** e,plain.
it is not because it is not based on e@uilance relationship. we can prove it b4 usin! e@uilnt properties refla,iv :
since , 8 , , should be e@ual to ,
transative : , 8 4 and 48 K thn K8,
smmetr4: , 8 4 N8g so its prooved it is not e@ulince relation
;.what are different applications of hashin!*
6ompilers use hash tables to keep track of declared variables 0s4mbol table1.
A hash table can be used for on$line spellin! checkers d if misspellin! detection 0rather than
correction1 is important& an entire dictionar4 can be hashed and words checked in constant time.
Lame pla4in! pro!rams use hash tables to store seen positions& thereb4 savin! computation time if the
position is encountered a!ain.
5.write down the function A method calls of heap that are used to increase or decrease the element _p_ with delta.
decreaske4 0E& delta1
inceraske40p& delta1
<.while makin! trees from fre@uenc4 of word in Cuffman encodin! scheme.for smaller lists linear insertion sort
but for lar!er lists @uick sort is better** Hustif4
@uik sort al!orithum is ver4 eli!nt and it can sort an arr4 of ann4 siKe efficntl4 and it is concedred as one of the
most best !enral perpos al!orithum. huffman codin! is efficnt for cmpressin! data but insersion and deletation
can make it cmple,. and liniar probln! is also makes collession&
5.threaded biner4 tree
A binar4 tree is threaded b4 makin! all ri!ht child pointers that would normall4 be null point to the inorder
successor of the node& and all left child pointers that would normall4 be null point to the inorder predecessor of
the node.

F X I & @uestion disHoint me se the&
8 what is c.. templete *
Templates are a feature of the 6.. pro!rammin! lan!ua!e that allow functions and classes to operate with
!eneric t4pes. This allows a function or class to work on man4 different data t4pes without bein! rewritten for
each one. This is effectivel4 a Turin!$complete lan!ua!e. ...
9.6alculate Cuffman code of the characters A&B&6&(&-
codes are
A:00
B:>0
6:0>
(:>>
>0.An e,pression tree is not a biner4 search tree or not ** !ive the reasons
e,presson tres are ma4 binar4 trees but the4 are not B)T because in B)T its left child vlue nodes are small and
ri!ht sub tre values are !reater.
>>.sortin! al!rithm me se tha& form sort Q>8 >5 >I ;5 >9R
>;.code for removin! an element from a linked list data structure if it is implementation b4 usin! linked memor4
methods
void remove01 2
if0 current=ode ^G =D## XX current=ode ^G head=ode1 2
last6urrent=ode$:set=e,t0current=ode$:!et=e,t0119
delete current=ode9
current=ode G last6urrent=ode$:!et=e,t019
siKe$$9
3
39
+uestion =o: > )uppose we have the followin! representation for a complete Binar4 )earch Tree& tell the #eft
and ?i!ht child nodes and Earent node of the node (
A B 6 ( - ( - F L C % M V # M = ' E + ? ) T
0 > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5 >F >I >8 >9 ;0 ;> ;;

parent: B usin! formula0iA;1
left child:$C ;iG;/<G8GC
?i!ht child:$% ;i.>G8.>G9G%

+uestion =o: 0; Cere is an arra4 with e,actl4 >5 elements: > ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5. )uppose that we
are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4 e,aminin! two or fewer
numbers from the arra4.

%f there is an arra4 of >5 elements& 2>& ;& 5& <& 5& F& I& 8& 9& >0& >>& >;& >5& ><& >53
it wants to know which elements can be discovered b4 e,aminin! two or fewer elements. % want assume the
divide and con@uer aspect of a binar4 search& so that leads me to think these elements will be found
>& ;& ><& >5& I& 5
rather9 >& ;& 5& <& F& 8& ><& >5
> and >5 for heads and tails
;& and >< for ne,t elements 0followin! or precedin!1
>A; of >5 is either F& or 8& from I.5
and >A; of F G 5
>A; 8 G <
+D-)T%'= =' 5.
(escribe an4 use of heap
it is a data strcture which is used in specil4 in preort4 @ue.
+D-)T%'= =' <.rite one e,ample of hashin!*
Cashin! can be used to store the data. )uppose we have a list of fruits. The names of Fruits are in strin!. The
ke4 is the name of the fruit. e will pass it to the hash Function to !et the hash ke4.
Cash6ode 0"apple"1 G 5
e pass it to the strin! capple . ?esultantl4& it returns a number 5

>: (ifferentiate followin! e,pression with the help of e,pression tree
f . d / s . b / m . t / n
0f . 0d/ s11 . 000b 8 m1 .t1/n
;: sort the list Q; 9 I 5 8R throu!h insertion sort al!orithm. )how each step
5: evaluate the followin! post fi, e,pression
F>F5$./<;>AAA





5: what is table abstract data t4pe*
The table& an abstract data t4pe& is a collection of rows and columns of information.
%mplementation of Table
o Dnsorted )e@uential Arra4
o )orted )e@uential Arra4
F: what are the characteristics of a !ood hash function*
it !ives one step insertion and deletation
hash al!orithum is based on hash function
it uses A)6%% code for strin!s
it is not !ood for serchin!
it is constent time opration
if ke4s are inte!r it is !enrall4 a !ood function
>1 6onstruct Ma, heap from !iven arra4 5 makrs
<1 Liven arra4 sat mode >> ki madad sa4 hash value maloom karna thi aor table banana tha
51 #inked list aor skip list ki ; characteristics likhna theen
skip list: fast searchin!
: provide alternative of Binar4 serch tree
lin7 list1 remo2e frst element
X8!; remo2e last element for doubly?lin7ed listsY X8N; for singly?lin7ed lists
X8N; getZsetZinsertZremo2e using an arbitrary index
X8!; insertZremo2e gi2en a pointer to a list node which is ad=acent to the insertion andZor
remo2al site
X8N; to iterate through 2alues from beginning of seuence to end
X8N; to iterate bac7wards through 2alues 8end to beginning; for doubly?lin7ed lists only

>. define binar4 tree
;. when an item should be added in arra4
5. a level order& and post order
<. draw a new heap after removin! an4 element from !iven heap.
5. correct the code.
F. mer!e sort
I. characterstics of skip list.
8. name implementation techni@ue of disHoint set for sorted data.
+: hat is stack*
A: )tack is a collection of elements arran!ed in a linear orderU
+: what are the characteristic of a !ood hash function*
A: %f the ke4s are inte!ers& ke4TT is !enerall4 a !ood hash function& unless the data has some undesirable
features. For e,ample& if T G >0 and all ke4s end in Keros& then ke4TT G 0 for all ke4s. )uppose we have
emplo4ee %( i.e. an inte!er. The emplo4ee %( ma4 be in hundreds of thousand. Cere the table siKe is >0. %n this
case& we will take mod of the emplo4ee %( with the table siKe to !et the hash value. Cere& the entire emplo4ee
%(s end in Kero. hat will be the remainder when we divide this number with >0* %t will be 0 for all emplo4ees.
)o this hash function cannot work with this data. %n !eneral& to avoid situations like this& T should be a prime
number.
+: !ive an4 three facts about buildin! heap*
A: methods of heap
,ecreaseSe<#p? ,e'ta%
increaseSe<#p? ,e'ta%
re6!Ae#p%

+: wh4 binar4 search cannot be used for link list*
A: Because it store sorted data.

+: Cow can we appl4 F%=( operation on elements combined throu!h union operation*
Ans.er"- #&age 352%
e !ive an element to the find method and it returns the name of the set.

+: )ort the list Q; 9 I 5 8Rthrou!h insertion sort al!orithm show each step.
Ea!e 9 moaaK file

+: what is difference bAw AO# and binar4 tree*
A: A binar4 search tree has two children per node whereas a binar4 tree can have none& one& or two children per
node
" /(at are ,iAi,e n c!nLuer s!rting 6et(!,s1 N'!g 7ase 2 N
A" Three al!orithm fall under divide and con@uer
merge sort
uic7 sort
heap sort
" .(at are pr!perties !- eLuiAa'ence set
Ans" A binar4 relation ? over a set ) is called an e@uivalence relation if it has followin! properties`:
>. ?efle,ivit4: for all element , K )& , ? ,
;. )4mmetr4: for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
5. Transitivit4: for all elements ,& 4 and K& if , ? 4 and 4 ? K then , ? K
-,ample9 sets of peoples &electric circuit domain

" C!nAert t(e giAen in-i8 -!r6 t! p!st-i8 -!r6:
A9;TC-DOE-F
Ans.er" AB.6A($-F $Z
" G!. .e can i6p'e6ent Ta7'e ADT using Lin$e, List
A" #ist linked list is one choice to implement table abstract data t4pe. For unsorted elements& the insertion at
front operation will take constant time. But if the data inside the list is kept in sorted order then to insert a new
element in the list& the entire linked list is traversed throu!h to find the appropriate position for the element.
" I- .e a''!. assign6ent t! c!nstants .(at .i'' (appen1
A" )uppose aa` has the value number 5. =ow we assi!ned number ; the number 5 i.e. all the number ; will
become number 5 and the result of ; . ; will become F. Therefore it is not allowed.
" G!. (eap s!rt .!r$s t! s!rt a set !- ,ata:
A" Min heap and ma, heap are used to sort the data. Min heap convert the data in ascendin! sorted order and
ma, heap convert the in descendin! order.
" FiAe <!ur c!66ent !n t(e state6ent t(at (eap uses 'east 6e6!r< in arra< representati!n !- 7inar<
trees: Uusti-< <!ur ans.er in eit(er case:
A" A heap is a complete binar4 tree& so it is eas4 to be implemented usin! an arra4 representation %t is a binar4
tree with the followin! properties:$

9roperty !1 it is a complete binary tree

9roperty '1 the 2alue stored at a node is greater or eual to the 2alues stored at the
children

+rom property ' the largest 2alue of the heap is always stored at the root

" G!. .e can use c!ncept !- eLuiAa'ence re'ati!ns t! generate a MaDe:
A" Al!orithm is as follows
6andomly remo2e walls until the entrance and exit cells are in the same cell
6emo2al of the wall is the same as doing a union operation
*o not remo2e randomly chosen wall if the cells it separates are already I the same set.
&( 6 9 5 . 4 ) - 3 2 5how the 8rst 8ve merging steps %or +erge sort on this
array
Ea!e >5 moaaK file
" /(at is DisV!int Sets1 E8p'ain .it( an e8a6p'e:
Ans" DisV!int sets - Two sets are disHoint if the4 have no elements in common. -,ample:$)uppose there are
man4 people around 4ou. Cow can we separate those who are related to each other in this !atherin!* e make
!roups of people who are related to each other. The people in one !roup will sa4 that the4 are related to each
other. )imilarl4 we can have man4 !roups. )o ever4 !roup will sa4 that the4 are related to each other with famil4
relationship and there is no !roup that is related to an4 other !roup. The people in the !roup will sa4 that there is
not a sin!le person in the other !roup who is related to them.


" In t(e arra< representati!n !- uni!n .(at represents -11
A" This shows that this node has no parent. Moreover& this node will be a root that ma4 be a parent of some other
node
" /(ic( ,ata structure is 7est -!r pri!rit< Lueue1
A" The use of priorit4 @ueue with the help of heap is a maHor application. The priorit4 @ueue is itself a maHor data
structure& much$used in operatin! s4stems. )imilarl4 priorit4 @ueue data structure is used in network devices
especiall4 in routers. Ceap data structure is also emplo4ed in sortin! al!orithms
" G!. .e can app'< Nni!n !perati!n !n e'e6ents initia''< in ,i--erent sets1
A" To e,ecute the union operation in two sets& we mer!e the two trees of these sets in such a manner that the root
of one tree points to the root of other. )o there will be one root& resultin! in the mer!er of the trees.

" /(at is S$ip 'ist1
" /rite t.! c(aracteristics !- s$ip 'ist1 2 6ar$s
Ans.er"- #&age **21 A skip list for a set ) of distinct 0ke4& element1 items is a series of lists )0& )> & W & )h such
that
] -ach list )i contains the special ke4s .b and $b
] #ist )0 contains the ke4s of ) in non$decreasin! order
] -ach list is a subse@uence of the previous one& i.e.& )0 )> W )h
] #ist )h contains onl4 the two special ke4s

" /(at is t(e .!rst case !- W-in,M !perati!n !- t(e 'in$e, 'ist1
A: orst case of the find method is that it has to search the entire list from be!innin! to end.

" /(at is t(e ,ra.7ac$ !- using arra< t! st!re X;inar< Searc( TreesM1
A"- #&age 21% The drawback of usin! is the limitations that arra4 bein! of fi,ed siKe can onl4 store a fi,ed
number of elements. Therefore& no more elements can be stored after the siKe of the arra4 is reached.

" FiAe an< 3 c(aracteristics !- uni!n 7< .eig(t 6et(!,1
A"- #&age *04% Followin! are the salient characteristics of this method:

.aintain siGes 8number of nodes; of all trees, and during union.

.a7e smaller tree, the sub?tree of the larger one.

Implementation1 for each root node i, instead of setting parentLiM to ?!, set it to ?7 if tree
rooted at i has 7 nodes.


" Geig(t !- a tree is + -in, su6 !- (eig(ts1
A: Cei!ht G 5
=odes G ;Zh G ;Z5 G5;
)um of =odes G =$0h.>1G 5;$05.>1 G 5;$F G ;F

" G!. can .e searc( an e'e6ent in s$ip 'ist1
A: e search for a ke4 , in the followin! fashion:
e start at the first position of the top list
] At the current position p& we compare , with 4 ke40after0p11
] , G 4: we return element0after0p11
] , : 4: we cscan forward
] , 8 4: we cdrop down
] %f we tr4 to drop down past the bottom list& we return ='7)D6C7V-N
" /(en (as(ing is NOT suita7'e1
A" Cash tables are not so !ood if there are man4 insertions and deletions& or if table traversals are needed d in
this case& AO# trees are better
" FiAe an< t(ree i6p!rtant -acts a7!ut 7ui',ing a (eap:1
A" Followin! are some of the important facts about buildin! a heap.
e )uppose we are !iven as input = ke4s 0or items1 to build a heap of the ke4s.
e 'bviousl4& this can be done with = successive inserts.
e -ach call to insert will either take unit time 0leaf node1 or lo!;= 0if new ke4 percolates all the wa4 up to the
root1.
e The worst time for buildin! a heap of = ke4s could be =lo!;=.
e %t turns out that we can build a heap in linear time.
e )uppose we have a method percolate(own0p1 that moves down the ke4 in node p
downwards.
e This is what happens in deleteMin.e have used the word ke4s in the first point.

" E8p'ain t(e -!''!.ing ter6
ans.er"
>.. 6ollision
;.. #inear probin!
5.. +uadratic probin!..
C!''isi!n" hen two values hash to the same arra4 location& this is called a collision8.
Linear &r!7ing hen there is a collision& some other location in the arra4 is found. This is known as linear
probin!. %n linear probin!& at the time of collisions& we add one to the inde, and check that location. %f it is also
not empt4& we add ; and check that position. )uppose we keep on incrementin! the arra4 inde, and reach at the
end of the table. e were unable to find the space and reached the last location of the arra4.
ua,ratic &r!7ing %n the @uadratic probin! when a collision happens we tr4 to find the empt4 location at inde,
. >Z;. %f it is filled then we add ;Z; and so on.
+uadratic probin! uses different formula:
>. Dse F0i1 G i; 0s@uare of i1 to resolve collisions
;. %f hash function resolves to C and a search in cell C is inconclusive& tr4
C . >;& C . ;;& C . 5;

" FiAe !ne e8a6p'e !- Gas(ing
A" Cashin! can be used to store the data. )uppose we have a list of fruits. The names of Fruits are in strin!. The
ke4 is the name of the fruit. e will pass it to the hash Function to !et the hash ke4. Cash6ode 0"apple"1 G 5
e pass it to the strin! capple . ?esultantl4& it returns a number 5.

" /!rst case !- se'ecti!n s!rt1
A" worst case occurs if the arra4 is alread4 sorted in descendin! order. =onetheless& the time re@uire b4 selection
sort al!orithm is not ver4 sensitive to the ori!inal order of the arra4 to be sorted

" C99 c!,e -!r ,!u7'< 'in$ 'ist1 + 6ar$s
A" Ea!e ;5 moaaK file
" Gere is an arra< .it( e8act'< 1+ e'e6ents"
1 2 3 * + 2 3 4 5 10 11 12 13 1* 1+:
Supp!se t(at .e are ,!ing a 7inar< searc( -!r an e'e6ent: In,icate an< e'e6ents t(at .i'' 7e -!un, 7<
e8a6ining t.! !r -e.er nu67ers -r!6 t(e arra<: #Mar$s" +%
Ans.er"
e see the data in arra4 it is sorted so performin! a B) is !ood. =ow consider arra4
A G 2>& ;& 5& < & 5& F& I& 8& 9& >0& >>& >;& >5& ><& >53
As binar4 search starts first element we e,amine mid element which is at inde, arra4)iKeA;0i.e. >5A; G I1& which
is I. =ow if the element is to compare is less then I we will consider the left part of arra4 from the mid which is
2>& ;& 5& <& 5& F3. =ow a!ain choose the mid element& which is 5 and campare with it. %f less then divide the arra4
a!ain.
6ome to ?i!ht side we have the followin! arra428& 9& >0& >>& >;& >5& ><& >53 if we divide it in middle we !et the
element >;. Based on value a!ain comparison divide the arra4 a!ain and do the same steps a!ain
)o the possible numbers are if we e,amine the arra4 are
I& 5& >& >;& 9
For more clarit4 see e,ample from handout !iven on pa!e <5>.
" uni!n !perati!n: Fr!6 n!tes" E8a6p'e !n pageK *00
element _p_ with delta.
<.while makin! trees from fre@uenc4 of word in Cuffman encodin! scheme.
for smaller lists linear insertion sort but for lar!er lists @uick sort is better** Hustif4
5.threaded biner4 tree
F X I & @uestion disHoint me se the&
8 what is c.. templete *
9.6alculate Cuffman code of the characters A&B&6&(&-
>0.An e,pression tree is not a biner4 search tree or not ** !ive the reasons
>>.sortin! al!rithm me se tha& form sort Q>8 >5 >I ;5 >9R
>;.code for removin! an element from a linked list data structure if it is implimentation b4 usin! linked memor4
methods

> : AO# tree me node del krke table banana tha ..
; : ?epresentation of B)T ..
5 : (efinations of 6ollision & line probin! & @uardatic probin! ..
< : Make correction in pro!ram 0 arra41 ..
< @uestion of 5 marks ...
> : 6ollision ..
; : -@uivalence relation . e,amples ..
5 : leaf and non$leaf nodes batane tha4 ..
< : 5 wa4s to build a heap ..
< @uestion of ; marks ..
> : mid usin! binar4 kch tha ..
; : huffman encodin! ..
5 : 6haracteristic of huffman encodin! ..
< : abt binar4 tree ...
+ =' > (ecribe an4 use of heap*
+ =' ; (ecribe the condition of second case of deletion in AO# tree*
+ =' 5 Cow we can search element in skip list*
+ =' < Dsin! union find data strecture.?elation is !iven below
union0o&A1 & union0B&M1&union0A&L1&union0o&=1union0M&C1 union0A&61
union0o&B1 &union0M&'1*
+ =' 5 hen hashin! is not suitable*
+ =' F Cow we !enerat MaKe*
+=' I Cow man4 leaf and non$leaf nodes are present in a
complete binar4 tree if its depth is I*
+ =' 8 rite 6.. al!orithm for Binar4 )earch
>.Live one e,ample of Cashin!. 0;1
;.wh4 threaded binar4 tree is effecient 0;1
5.effect of sorted data on Binar4 )earch0;1
<.how to find parent & left child and ri8 child of heap051
5.comparison between linear insertion sort nd @uick sort 051
F.hat is an -@uivalent relation* Live an4 two e,amples051
I.rite down the c.. code for selection sort 051
8.(ata dia !4a tha %nsertion sort find krna tha 051
9.AOl tree tha > node delete kr k rotation krni thi 051
m4 toda4 paper 6)50< ''E50 percent M6+s mous ki file se th4.
Aur Kiada$tar M6@s inheritance aur templates mein se th4.
Oirtual inheritance& multiple class inheritance
=on$paramter template
Ak template function bana tha arra4 ka Ho avera!e nikalta ho.
-,ception handlin! ka code likhna tha.
Vuch class di !ain thi un main se 4e batana tha k in mein se abstract aur concrete class kon kon c ha.
Baki 5 @uestion as4 th4 Hin ka code check karna tha k in mein koe error ha.
Ak @uestion e,ception handlin! ka tha code likha howa tha aur 4e batna tha k us ki output kia ho !i aur 4e kis
block mein throw kar !a.

9ermalin7 6eply by [\] ^_ on .arch (, '"!> at !1"$pm


M< t!,a< paper Cs301:
*0 6cLs +0^ in 6!aaD paper Q su7VectiAe :
*1% Data ,ia g<a t(a 1st Inserti!n !- t(e 6ain '!!p #+%
*2% t.! use !- (as( -uncti!n 1#2%
*3% (u--6an enc!,ing ::#2%
**% s!rting a'grit(6 6e se t(a? -!r6 s!rt H14 13 13 2+ 15I #2%
*+%Ca'cu'ate Gu--6an c!,e !- t(e c(aracters ta7'e 7e'!.1#3%
*2% Dra. t(e uni!n !- -ina' Arra< giAen ,ata 1 #3%
*3% A7!ut 6in (eap an, 6a8 (eap c!rrect $arna (a ,ata ,ia t(a1 #2%
*4% s!rt 'ist .it( a'' steps 1 FiAen ,ata #3%
*5% Ma$e c!rrecti!n in pr!gra6 #+%
+0% C!nsi,er t(e -!''!.ing T(rea,e, ;inar< Tree? n!,e 33 #+%
+1% n!,e ,e'et $arna t(a !r 7'ance $arna t(a tree #+%
+2% r!!t ,e'et $arna t(a AA' tree 6ai sa #3%
onnly dua for my reslut needed... pllllllllG
)S>"/ 9-9E6 !. )6E-TE 2iew name student list on customer table to show only
)ST_I* in asc of those customer of gu=ranwala city customer8)ST_I* ,)ST ?N-.E
,city ; '. insert 2alue cs'!! operating system ,>,mcs in course table with sl
command /. =ustify correct or in correct that good approach to create on non 7ey
attribute /. deadloc7 example >. demoraliGation beneft n gi2e two real world
exmple (. transaction n ' properties
cs/"! >" mcs thy =o 7 past ma sa !"F ay thy.
' mar7s 7 uestion past ma sa thy
!; ai7 tha 7 tree 7i hieght di hui thi sum of height of nodes ni7alna tha .
height of a tree is ( fnd sum of heights 8';
-nswer1?
Aeight ` (
Nodes ` 'ah ` 'a( `/'
Sum of Nodes ` N?8hN!;` /'?8(N!; ` /'?$ ` '$
'; fnd and remo2e 7a uestion tha hashing ma.
/; biultinheap pa uestion tha 7 agr ap7o ai7 list di ho uss sa heap 7esy bnay gy
us7a =ust procedure li7hna tha
>;min heap bnani thi .
(; remo2e 7a cNN code li7hna tha.
$; buble sort 7a uestion tha .
<0 mc@_s mostl4 from past papers:
< @uestion havin! ; marks
< @uestion havin! 5 marks
< @uestions havin! 5 marks
a code was !iven and i had to correct the error0;1
hat is the >st step of huffman encodin! 051
% had to write the fre@uenc4 of the te,t "Cuffman -ncodin!" 051
Q; 9 I 5 8R i had to sort it usin! insertion sort. 051
%f we insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish
balance* Mustif4 4our answer.
Answer:$
=o& one rotation is not alwa4s sufficient to re$establish balance. For e,ample& consider the
insertion of the shaded
node in the followin! AO# tree:
Thou!h the ori!inal tree was balanced& more than one rotation is needed to restore balance
followin! the insertion.
This can be seen b4 an e,haustive enumeration of the rotation possibilities.
The problem asks for a tree of hei!ht <& so we can e,tend the above e,ample into a lar!er tree:
a min heap was !iven and i had to rearran!e it after deletion of the di!it at >st postition. 051
Eroperties of e@uivalent class. 05
corect form is
!.The relation b between real numbers is eualant relation or not44 explain.
it is not because it is not based on euilance relationship. we can pro2e it by using
euilnt properties re5axi2 1 since x c x x should be eual to x
transati2e 1 x c y and yc G thn Gcx
smmetry1 x c y <cd so its proo2ed it is not eulince relation
'.what are diBerent applications of hashing4
)ompilers use hash tables to 7eep trac7 of declared 2ariables 8symbol table;.
- hash table can be used for on?line spelling chec7ers e if misspelling
detection 8rather than
correction; is important, an entire dictionary can be hashed and words chec7ed in
constant time.
fame playing programs use hash tables to store seen positions, thereby sa2ing
computation time if the
position is encountered again.
/.write down the function Z method calls of heap that are used to increase or
decrease the element gpg with delta.
decreas7ey 89, delta;
inceras7ey8p, delta;
>.while ma7ing trees from freuency of word in AuBman encoding scheme.for
smaller lists linear insertion sort but for larger lists uic7 sort is better44 =ustify
ui7 sort algorithum is 2ery elignt and it can sort an arry of anny siGe ehcntly and it
is concedred as one of the most best genral perpos algorithum. huBman coding is
ehcnt for cmpressing data but insersion and deletation can ma7e it cmplex. and
liniar problng is also ma7es collession,
(.threaded binery tree
A binar tree is threaded b ma!in" all ri"ht child #ointers that would normall be null #oint to the inorder
successor of the node, and all left child #ointers that would normall be null #oint to the inorder
#redecessor of the node$
$ i # , uestion dis=oint me se the,
% what is cNN templete 4
%em#lates are a feature of the &'' #ro"rammin" lan"ua"e that allow functions and classes to
o#erate with "eneric t#es$ %his allows a function or class to wor! on man different data t#es
without bein" rewritten for each one$ %his is effectivel a %urin"(com#lete lan"ua"e$ $$$
:.)alculate AuBman code of the characters -,B,),*,E
codes are
-1""
B1!"
)1"!
*1!!
!".-n expression tree is not a binery search tree or not 44 gi2e the reasons
expresson tres are may binary trees but they are not BST because in BST its left
child 2lue nodes are small and right sub tre 2alues are greater.
!!.sorting algrithm me se tha, form sort L!% !/ !# '( !:M
!'.code for remo2ing an element from a lin7ed list data structure if it is
implementation by using lin7ed memory methods
2oid remo2e8; j
if8 currentNode k` Nl&& ii currentNode k` headNode; j
last)urrentNode?bsetNext8currentNode?bgetNext8;;Y
delete currentNodeY
currentNode ` last)urrentNode?bgetNext8;Y
siGe??Y
m
mY
0uestion No1 ! Suppose we ha2e the following representation for a complete Binary
Search Tree, tell the &eft and 6ight child nodes and 9arent node of the node *
- B ) * E * E + f A I D n & . N X 9 0 6 S T
" ! ' / > ( $ # % : !" !! !' !/ !> !( !$ !# !% !: '" '! ''
parent1 B using formula8iZ';
left child1?A 'i`'o>`%`A
6ight child1?I 'iN!`%N!`:`I
0uestion No1 "' Aere is an array with exactly !( elements1 ! ' / > ( $ # % : !" !!
!' !/ !> !(. Suppose that we are doing a binary search for an element. Indicate
any elements that will be found by examining two or fewer numbers from the array.
If there is an array of !( elements, j!, ', /, >, (, $, #, %, :, !", !!, !', !/, !>, !(m
it wants to 7now which elements can be disco2ered by examining two or fewer
elements. I want assume the
di2ide and conuer aspect of a binary search, so that leads me to thin7 these
elements will be found
!, ', !>, !(, #, /
ratherY !, ', /, >, $, %, !>, !(
! and !( for heads and tails
', and !> for next elements 8following or preceding;
!Z' of !( is either $, or %, from #.(
and !Z' of $ ` /
!Z' % ` >
0lESTIXN NX /.
*escribe any use of heap
it is a data strcture which is used in specily in preorty ue.
0lESTIXN NX >.@rite one example of hashing4
Aashing can be used to store the data. Suppose we ha2e a list of fruits. The names
of +ruits are in string. The
7ey is the name of the fruit. @e will pass it to the hash +unction to get the hash 7ey.
Aash)ode 8CappleC; ` (
@e pass it to the string pappleq. 6esultantly, it returns a number (
>: (ifferentiate followin! e,pression with the help of e,pression tree
f . d / s . b / m . t / n
0f . 0d/ s11 . 000b 8 m1 .t1/n
;: sort the list Q; 9 I 5 8R throu!h insertion sort al!orithm. )how each step
5: evaluate the followin! post fi, e,pression
F>F5$./<;>AAA
5: what is table abstract data t4pe*
The table& an abstract data t4pe& is a collection of rows and columns of information.
%mplementation of Table
o Dnsorted )e@uential Arra4
o )orted )e@uential Arra4
F: what are the characteristics of a !ood hash function*
it !ives one step insertion and deletation
hash al!orithum is based on hash function
it uses A)6%% code for strin!s
it is not !ood for serchin!
it is constent time opration
if ke4s are inte!r it is !enrall4 a !ood function
>1 6onstruct Ma, heap from !iven arra4 5 makrs
<1 Liven arra4 sat mode >> ki madad sa4 hash value maloom karna thi aor table banana tha
51 #inked list aor skip list ki ; characteristics likhna theen
skip list: fast searchin!
: provide alternative of Binar4 serch tree
link list: remove first element
'0>1 remove last element for doubl4$linked lists9 '0=1 for sin!l4$linked lists
'0=1 !etAsetAinsertAremove usin! an arbitrar4 inde,
'0>1 insertAremove !iven a pointer to a list node which is adHacent to the
insertion andAor removal site
'0=1 to iterate throu!h values from be!innin! of se@uence to end
'0=1 to iterate backwards throu!h values 0end to be!innin!1 for doubl4$linked
lists onl4
>. define binar4 tree
;. when an item should be added in arra4
5. a level order& and post order
<. draw a new heap after removin! an4 element from !iven heap.
5. correct the code.
F. mer!e sort
I. characterstics of skip list.
8. name implementation techni@ue of disHoint set for sorted data.
+: hat is stack*
A: )tack is a collection of elements arran!ed in a linear orderU
+: what are the characteristic of a !ood hash function*
A: %f the ke4s are inte!ers& ke4TT is !enerall4 a !ood hash function& unless the data has some
undesirable features. For e,ample& if T G >0 and all ke4s end in Keros& then ke4TT G 0 for all
ke4s. )uppose we have emplo4ee %( i.e. an inte!er. The emplo4ee %( ma4 be in hundreds of
thousand. Cere the table siKe is >0. %n this case& we will take mod of the emplo4ee %( with the
table siKe to !et the hash value. Cere& the entire emplo4ee %(s end in Kero. hat will be the
remainder when we divide this number with >0* %t will be 0 for all emplo4ees. )o this hash
function cannot work with this data. %n !eneral& to avoid situations like this& T should be a prime
number.
+: !ive an4 three facts about buildin! heap*
A: methods of heap
,ecreaseSe<#p? ,e'ta%
increaseSe<#p? ,e'ta%
re6!Ae#p%

+: wh4 binar4 search cannot be used for link list*
A: Because it store sorted data.

+: Cow can we appl4 F%=( operation on elements combined throu!h union operation*
Ans.er"- #&age 352%
e !ive an element to the find method and it returns the name of the set.

+: )ort the list Q; 9 I 5 8Rthrou!h insertion sort al!orithm show each step.
Ea!e 9 moaaK file

+: what is difference bAw AO# and binar4 tree*
A: A binar4 search tree has two children per node whereas a binar4 tree can have none& one& or
two children per node
" /(at are ,iAi,e n c!nLuer s!rting 6et(!,s1 N'!g 7ase 2 N
A" Three al!orithm fall under divide and con@uer
mer!e sort
@uick sort
heap sort
" .(at are pr!perties !- eLuiAa'ence set
Ans" A binar4 relation ? over a set ) is called an e@uivalence relation if it has followin!
properties`:
>. ?efle,ivit4: for all element , )& , ? ,
;. )4mmetr4: for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
5. Transitivit4: for all elements ,& 4 and K& if , ? 4 and 4 ? K then , ? K
-,ample9 sets of peoples &electric circuit domain

" C!nAert t(e giAen in-i8 -!r6 t! p!st-i8 -!r6:
A9;TC-DOE-F
Ans.er" AB.6A($-F $Z
" G!. .e can i6p'e6ent Ta7'e ADT using Lin$e, List
A" #ist linked list is one choice to implement table abstract data t4pe. For unsorted elements& the
insertion at front operation will take constant time. But if the data inside the list is kept in sorted
order then to insert a new element in the list& the entire linked list is traversed throu!h to find the
appropriate position for the element.
" I- .e a''!. assign6ent t! c!nstants .(at .i'' (appen1
A" )uppose aa` has the value number 5. =ow we assi!ned number ; the number 5 i.e. all the
number ; will become number 5 and the result of ; . ; will become F. Therefore it is not
allowed.
" G!. (eap s!rt .!r$s t! s!rt a set !- ,ata:
A" Min heap and ma, heap are used to sort the data. Min heap convert the data in ascendin!
sorted order and ma, heap convert the in descendin! order.
" FiAe <!ur c!66ent !n t(e state6ent t(at (eap uses 'east 6e6!r< in arra<
representati!n !- 7inar< trees: Uusti-< <!ur ans.er in eit(er case:
A" A heap is a complete binar4 tree& so it is eas4 to be implemented usin! an arra4 representation
%t is a binar4 tree with the followin! properties:$

Eropert4 >: it is a complete binar4 tree

Eropert4 ;: the value stored at a node is !reater or e@ual to the values stored at the
children

From propert4 ; the lar!est value of the heap is alwa4s stored at the root

" G!. .e can use c!ncept !- eLuiAa'ence re'ati!ns t! generate a MaDe:
A" Al!orithm is as follows
?andoml4 remove walls until the entrance and e,it cells are in the same cell
?emoval of the wall is the same as doin! a union operation
(o not remove randoml4 chosen wall if the cells it separates are alread4 % the same set.
" 2 5 + 0 * 1 3 3 2 S(!. t(e -irst -iAe 6erging steps -!r Merge s!rt !n t(is arra<:
Ea!e >5 moaaK file
" /(at is DisV!int Sets1 E8p'ain .it( an e8a6p'e:
Ans" DisV!int sets - Two sets are disHoint if the4 have no elements in common. -,ample:$
)uppose there are man4 people around 4ou. Cow can we separate those who are related to each
other in this !atherin!* e make !roups of people who are related to each other. The people in
one !roup will sa4 that the4 are related to each other. )imilarl4 we can have man4 !roups. )o
ever4 !roup will sa4 that the4 are related to each other with famil4 relationship and there is no
!roup that is related to an4 other !roup. The people in the !roup will sa4 that there is not a sin!le
person in the other !roup who is related to them.


" In t(e arra< representati!n !- uni!n .(at represents -11
A" This shows that this node has no parent. Moreover& this node will be a root that ma4 be a
parent of some other node
" /(ic( ,ata structure is 7est -!r pri!rit< Lueue1
A" The use of priorit4 @ueue with the help of heap is a maHor application. The priorit4 @ueue is
itself a maHor data structure& much$used in operatin! s4stems. )imilarl4 priorit4 @ueue data
structure is used in network devices especiall4 in routers. Ceap data structure is also emplo4ed in
sortin! al!orithms
" G!. .e can app'< Nni!n !perati!n !n e'e6ents initia''< in ,i--erent sets1
A" To e,ecute the union operation in two sets& we mer!e the two trees of these sets in such a
manner that the root of one tree points to the root of other. )o there will be one root& resultin! in
the mer!er of the trees.

" /(at is S$ip 'ist1
" /rite t.! c(aracteristics !- s$ip 'ist1 2 6ar$s
Ans.er"- #&age **21 A skip list for a set ) of distinct 0ke4& element1 items is a series of lists )0&
)> & W & )h such that
] -ach list )i contains the special ke4s .b and $b
] #ist )0 contains the ke4s of ) in non$decreasin! order
] -ach list is a subse@uence of the previous one& i.e.& )0 H )> H W H )h
] #ist )h contains onl4 the two special ke4s

" /(at is t(e .!rst case !- W-in,M !perati!n !- t(e 'in$e, 'ist1
A: orst case of the find method is that it has to search the entire list from be!innin! to end.

" /(at is t(e ,ra.7ac$ !- using arra< t! st!re X;inar< Searc( TreesM1
A"- #&age 21% The drawback of usin! is the limitations that arra4 bein! of fi,ed siKe can onl4
store a fi,ed number of elements. Therefore& no more elements can be stored after the siKe of the
arra4 is reached.

" FiAe an< 3 c(aracteristics !- uni!n 7< .eig(t 6et(!,1
A"- #&age *04% Followin! are the salient characteristics of this method:

Maintain siKes 0number of nodes1 of all trees& and durin! union.

Make smaller tree& the sub$tree of the lar!er one.

%mplementation: for each root node i& instead of settin! parentQiR to $>& set it to $k if tree
rooted at i has k nodes.


" Geig(t !- a tree is + -in, su6 !- (eig(ts1
A: Cei!ht G 5
=odes G ;Zh G ;Z5 G5;
)um of =odes G =$0h.>1G 5;$05.>1 G 5;$F G ;F

" G!. can .e searc( an e'e6ent in s$ip 'ist1
A: e search for a ke4 , in the followin! fashion:
e start at the first position of the top list
] At the current position p& we compare , with 4 ke40after0p11
] , G 4: we return element0after0p11
] , : 4: we cscan forward
] , 8 4: we cdrop down
] %f we tr4 to drop down past the bottom list& we return ='7)D6C7V-N
" /(en (as(ing is NOT suita7'e1
A" Cash tables are not so !ood if there are man4 insertions and deletions& or if table traversals
are needed d in this case& AO# trees are better
" FiAe an< t(ree i6p!rtant -acts a7!ut 7ui',ing a (eap:1
A" Followin! are some of the important facts about buildin! a heap.
e )uppose we are !iven as input = ke4s 0or items1 to build a heap of the ke4s.
e 'bviousl4& this can be done with = successive inserts.
e -ach call to insert will either take unit time 0leaf node1 or lo!;= 0if new ke4 percolates all the
wa4 up to the root1.
e The worst time for buildin! a heap of = ke4s could be =lo!;=.
e %t turns out that we can build a heap in linear time.
e )uppose we have a method percolate(own0p1 that moves down the ke4 in node p
downwards.
e This is what happens in deleteMin.e have used the word ke4s in the first point.

" E8p'ain t(e -!''!.ing ter6
ans.er"
>.. 6ollision
;.. #inear probin!
5.. +uadratic probin!..
C!''isi!n" hen two values hash to the same arra4 location& this is called a collision8.
Linear &r!7ing hen there is a collision& some other location in the arra4 is found. This is
known as linear probin!. %n linear probin!& at the time of collisions& we add one to the inde, and
check that location. %f it is also not empt4& we add ; and check that position. )uppose we keep on
incrementin! the arra4 inde, and reach at the end of the table. e were unable to find the space
and reached the last location of the arra4.
ua,ratic &r!7ing %n the @uadratic probin! when a collision happens we tr4 to find the empt4
location at inde, . >Z;. %f it is filled then we add ;Z; and so on.
+uadratic probin! uses different formula:
>. Dse F0i1 G i; 0s@uare of i1 to resolve collisions
;. %f hash function resolves to C and a search in cell C is inconclusive& tr4
C . >;& C . ;;& C . 5;

" FiAe !ne e8a6p'e !- Gas(ing
A" Cashin! can be used to store the data. )uppose we have a list of fruits. The names of Fruits
are in strin!. The ke4 is the name of the fruit. e will pass it to the hash Function to !et the hash
ke4. Cash6ode 0"apple"1 G 5
e pass it to the strin! capple . ?esultantl4& it returns a number 5.

" /!rst case !- se'ecti!n s!rt1
A" worst case occurs if the arra4 is alread4 sorted in descendin! order. =onetheless& the time
re@uire b4 selection sort al!orithm is not ver4 sensitive to the ori!inal order of the arra4 to be
sorted

" C99 c!,e -!r ,!u7'< 'in$ 'ist1 + 6ar$s
A" Ea!e ;5 moaaK file
" Gere is an arra< .it( e8act'< 1+ e'e6ents"
1 2 3 * + 2 3 4 5 10 11 12 13 1* 1+:
Supp!se t(at .e are ,!ing a 7inar< searc( -!r an e'e6ent: In,icate an< e'e6ents t(at .i''
7e -!un, 7<
e8a6ining t.! !r -e.er nu67ers -r!6 t(e arra<: #Mar$s" +%
Ans.er"
e see the data in arra4 it is sorted so performin! a B) is !ood. =ow consider arra4
A G 2>& ;& 5& < & 5& F& I& 8& 9& >0& >>& >;& >5& ><& >53
As binar4 search starts first element we e,amine mid element which is at inde, arra4)iKeA;0i.e.
>5A; G I1& which is I. =ow if the element is to compare is less then I we will consider the left
part of arra4 from the mid which is 2>& ;& 5& <& 5& F3. =ow a!ain choose the mid element& which
is 5 and campare with it. %f less then divide the arra4 a!ain.
6ome to ?i!ht side we have the followin! arra428& 9& >0& >>& >;& >5& ><& >53 if we divide it in
middle we !et the element >;. Based on value a!ain comparison divide the arra4 a!ain and do
the same steps a!ain
)o the possible numbers are if we e,amine the arra4 are
I& 5& >& >;& 9
For more clarit4 see e,ample from handout !iven on pa!e <5>.
" uni!n !perati!n: Fr!6 n!tes" E8a6p'e !n pageK *00
element gpg with delta.
>.while ma7ing trees from freuency of word in AuBman encoding scheme.
for smaller lists linear insertion sort but for larger lists uic7 sort is better44 =ustify
(.threaded binery tree
$ i # , uestion dis=oint me se the,
% what is cNN templete 4
:.)alculate AuBman code of the characters -,B,),*,E
!".-n expression tree is not a binery search tree or not 44 gi2e the reasons
!!.sorting algrithm me se tha, form sort L!% !/ !# '( !:M
!'.code for remo2ing an element from a lin7ed list data structure if it is
implimentation by using lin7ed memory methods
> : AO# tree me node del krke table banana tha ..
; : ?epresentation of B)T ..
5 : (efinations of 6ollision & line probin! & @uardatic probin! ..
< : Make correction in pro!ram 0 arra41 ..
< @uestion of 5 marks ...
> : 6ollision ..
; : -@uivalence relation . e,amples ..
5 : leaf and non$leaf nodes batane tha4 ..
< : 5 wa4s to build a heap ..
< @uestion of ; marks ..
> : mid usin! binar4 kch tha ..
; : huffman encodin! ..
5 : 6haracteristic of huffman encodin! ..
< : abt binar4 tree ...
+ =' > (ecribe an4 use of heap*
+ =' ; (ecribe the condition of second case of deletion in AO# tree*
+ =' 5 Cow we can search element in skip list*
+ =' < Dsin! union find data strecture.?elation is !iven below
union0o&A1 & union0B&M1&union0A&L1&union0o&=1union0M&C1 union0A&61
union0o&B1 &union0M&'1*
+ =' 5 hen hashin! is not suitable*
+ =' F Cow we !enerat MaKe*
+=' I Cow man4 leaf and non$leaf nodes are present in a
complete binar4 tree if its depth is I*
+ =' 8 rite 6.. al!orithm for Binar4 )earch
>.Live one e,ample of Cashin!. 0;1
;.wh4 threaded binar4 tree is effecient 0;1
5.effect of sorted data on Binar4 )earch0;1
<.how to find parent & left child and ri8 child of heap051
5.comparison between linear insertion sort nd @uick sort 051
F.hat is an -@uivalent relation* Live an4 two e,amples051
I.rite down the c.. code for selection sort 051
8.(ata dia !4a tha %nsertion sort find krna tha 051
9.AOl tree tha > node delete kr k rotation krni thi 051
my today paper )S/"> XX9(" percent .)0s mous 7i fle se thy.
-ur Giada?tar .)s inheritance aur templates mein se thy.
3irtual inheritance, multiple class inheritance
Non?paramter template
-7 template function bana tha array 7a =o a2erage ni7alta ho.
Exception handling 7a code li7hna tha.
nuch class di gain thi un main se ye batana tha 7 in mein se abstract aur concrete
class 7on 7on c ha.
Ba7i / uestion asy thy =in 7a code chec7 7arna tha 7 in mein 7oe error ha.
-7 uestion exception handling 7a tha code li7ha howa tha aur ye batna tha 7 us 7i
output 7ia ho gi aur ye 7is bloc7 mein throw 7ar ga.
+uestion [ > of >0
%f we want to find median of 50 elements& then after appl4in! buildCeap method& how man4 times deleteMin
method will be called *
)elect correct option:
5
'(
55
50
+uestion [ ; of >0
%f Ahmed is cousin of Ali and Ali is cousin of Asad then Ahmed is also cousin of Asad. This statement has the
followin! propert4
)elect correct option:
?efle,ivit4
)4mmetr4
Transiti2ity
All of the above
+uestion [ 5 of >0
%f we want to find 5rd minimum element from an arra4 of elements& then after appl4in! buildCeap method& how
man4 times deleteMin method will be called *
)elect correct option:
>
;
/
<
+uestion [ < of >0
The preculate(own procedure will move the smaller value77 and bi!!er value7777.
)elect correct option:
left&ri!ht
ri!ht&left
up&down
down,up
+uestion [ 5 of >0
%f the hei!ht of a perfect binar4 tree is <. hat will be the total number of nodes in it*
)elect correct option:
!(
>F
5>
5;
+uestion [ F of >0
The worst case of buildin! a heap of = ke4s is 77777 .
)elect correct option:
=
=Z;
NlogN
;Z=
+uestion [ I of >0
hich of the followin! method is helpful in creatin! the heap at once*
)elect correct option:
insert
add
update
preculate(own
+uestion [ 8 of >0
6onsider a min heap& represented b4 the followin! arra4: >>&;;&55&<<&55 After insertin! a node with value
FF.hich of the followin! is the updated min heap*
)elect correct option:
!!,'',//,>>,((,$$
>>&;;&55&<<&FF&55
>>&;;&55&FF&<<&55
>>&;;&FF&55&<<&55
+uestion [ 9 of >0
hich of the followin! heap method lowers the value of ke4 at position `pJ b4 the amount `deltaJ*
)elect correct option:
increaseVe40p&delta1
decreaseney8p,delta;
preculate(own0p&delta1
remove0p&delta1
+uestion [ >0 of >0
6onsider a min heap& represented b4 the followin! arra4: 5&<&F&I&5 After callin! the function deleteMin01.hich
of the followin! is the updated min heap*
)elect correct option:
<&F&I&5
$,#,(,>
<&5&F&I
<&F&5&I&

9ermalin7 6eply by -dnan -li on Danuary !%, '"!> at %1(#am


thank,

9ermalin7 6eply by r s U tu U v w U x s w U y r on Danuary '!, '"!> at #1//pm


>.
The main reason of usin! heap in priorit4 @ueue is
i6pr!Ae per-!r6ance
code is readable
less code
heap can_t be used in priorit4 @ueues

2:
/e i6p'e6ent t(e (eap 7< ____________
Threaded Tree
AO# tree
C!6p'ete 7inar< tree
-,pression

5.
A simple sortin! al!orithm like selection sort or bubble sort has a worst$case of
'0>1 time because all lists take the same amount of time to sort
'0n1 time because it has to perform n swaps to order the list.
O#n2% ti6e 7ecause s!rting 1 e'e6ent ta$es O#n% ti6e - A-ter 1 pass t(r!ug( t(e 'ist?
eit(er !- t(ese a'g!rit(6s can guarantee t(at 1 e'e6ent is s!rte,:
'0n51 time& because the worst case has reall4 random input which takes lon!er to.
<.
%f we want to find median of 50 elements& then after appl4in! buildCeap method& how man4 times deleteMin
method will be called *
)elect correct option:
5
2+
55
50




5.
hich one of the followin! is ='T true re!ardin! the skip list*
-ach list )i contains the special ke4s . infinit4 and $ infinit4.
#ist )0 contains the ke4s of ) in non$decreasin! order.
-ach list is a subse@uence of the previous one.
List S( c!ntains !n'< t(e n specia' $e<s:
F.
hich of the followin! is not true re!ardin! the maKe !eneration*
?andoml4 remove walls until the entrance and e,it cells are in the same set.
?emovin! a wall is the same as doin! a union operation.
Re6!Ae a ran,!6'< c(!sen .a'' i- t(e ce''s it separates are a'rea,< in t(e sa6e set:
(o not remove a randoml4 chosen wall if the cells it separates are alread4 in the same set.
I.
hich propert4 of e@uivalence relation is satisfied if we sa4: Ahmad ?0is related to1 Ahmad
?efle,ivit4
S<66etr<
Transitivit4
8.
The e,pression if 0 ^ heap$:is-mpt401 1 checks
Ceap is empt4
Ceap is full
Ceap is not empt4
N!t a Aa'i, e8pressi!n #n!t c!n-ir6%




5:
e implement the heap b4
Threaded Tree
AO# tree
C!6p'ete 7inar< tree
-,pression
>0.
/(ic( !- t(e -!''!.ing state6ent c!ncerning (eaps is NOT true1
TraAersing a (eap in !r,er pr!Ai,es access t! t(e ,ata in nu6eric !r a'p(a7etica' !r,er:
?emovin! the item at the top provides immediate access to the ke4 value with hi!hest 0or lowest1 priorit4.
%nsertin! an item is alwa4s done at the end of the arra4& but re@uires maintainin! the heap propert4.
A heap ma4 be stored in an arra4.

hich propert4 of relation is satisdied if we sa4: Ahmad ?0is related to1Ahmad
?efle,ivit4
S<66etr<
Transitvit4
All of the !iven
Ceap can be use to implement
)tack
#ink list
+ueue
&ri!rit< ueue
hich one of the followin! is not true re!ardin! skip list.
-ach list )i contain the special ke4 . infinit4 and Pinfinit4
#ist )' contain the ke4 of ) is non$decreasin! order
List S( c!ntain !n'< t(e n specia' $e<s
-ach list in a sub se@uence of previous list one
%f Ahmad is cousin of Ali and Ali is cousin of Asad then Ahmad is also cousin of Asad
the statement has the followin! propert4.
?efle,ivit4
)4mmetr4
TransitiAit<
All of the above
The e,pression of 0^ heap$: is full01 1 check
Ceap is empt4
Ceap is full
Ceap is not empt4
Geap is n!t -u''#n!t c!n-er6%
hich one of the followin! is not the propert4 of e@uivalence relation
?efle,ive
)4mmetric
Transitive
Ass!ciatiAe
hich of the followin! is not and implementation of table A(T
)orted se@uentiall4 arra4
)tack
#ink list
S$ip 'ist
hich one of the followin! is not an open addressin! techni@ue to resolve collection
+uadratic probin!
(ouble hashin!
Cu7ic pr!7ing
#iner probin!
hat is the best definition of a collision on a hash table*
Two entries are identical e,cept for their ke4s.
T.! entries .it( ,i--erent ,ata (aAe t(e e8act sa6e $e<:
Two entries with different ke4s have the e,act has value
Two entries with the e,act same ke4s have different hash value.

9ermalin7 6eply by r s U tu U v w U x s w U y r on Danuary '', '"!> at !!1>$am


A 7inar< re'ati!n R !Aer S is ca''e, an eLuiAa'ence re'ati!n i- it (as -!''!.ing pr!pert<#s%
?efle,ivit4
)4mmetr4
Transitivit4
All of the !iven options
T(e precu'ateD!.n pr!ce,ure .i'' 6!Ae t(e s6a''er Aa'ueEEEE an, 7igger Aa'ueEEEEEE:
left&ri!ht
ri!ht&left
up&down
down&up
I- t(e (eig(t !- a per-ect 7inar< tree is *: /(at .i'' 7e t(e t!ta' nu67er !- n!,es in it1
>5
>F
5>
5;
/(ic( !ne !- t(e -!''!.ing is NOT t(e pr!pert< !- eLuiAa'ence re'ati!n1
?efle,ive
)4mmetric
Transitive
Associative
/(ic( !- t(e -!''!.ing (eap 6et(!, '!.ers t(e Aa'ue !- $e< at p!siti!n WpM 7< t(e a6!unt W,e'taM1
)elect correct option:
increaseVe40p&delta1
decreaseVe40p&delta1
preculate(own0p&delta1
remove0p&delta1
(eap can 7e use, t! i6p'e6ent
stack
linked list
@ueue
priort4 @ueue
.(ic( !- -!''!.ing 6et(!, is (e'p-u' in creating (eap at !nce
insert
add
pecular down
update

9ermalin7 6eply by r s U tu U v w U x s w U y r on Danuary '', '"!> at !!1('am


T(e precu'ateD!.n pr!ce,ure .i'' 6!Ae t(e s6a''erAa'ueEEEE an, 7igger Aa'ueEEEEEE:
Se'ect c!rrect !pti!n"
left&ri!ht
ri!ht&left
up&down
,!.n?up
T(ere are EEEEEEEEEcases !- R!tati!n in APLtree:
Se'ect c!rrect !pti!n"
;
5
A complete binar4 tree of hei!ht 5 has between 77777777nodes.
)elect correct option:
8 to ><
4 t! 1+
8 to >F
8 to >I
In case !- inserti!n !- rig(t inner n!,e in ;ST?
)elect correct option:
we need to appl4 sin!le left rotation to make it AO# tree.
we need to appl4 sin!le ri!ht rotationto make it AO# tree.
sin!le left rotation first and then sin!le ri!ht rotation tomake it AO# tree.
sin!le ri!ht rotation first and then sin!le left
;inar< Searc( Tree A!i'ates t(e c!n,iti!n !- APL tree .(en an<n!,e (as 7a'ance eLua' t!
)elect correct option:
2 !r -2
> or $>
0
=one of the options.
Supp!se .e (aAe t(e -!''!.ing Aa'ues t! 7e inserte, inc!nstructing APL tree?
20?23?2+?10?12?13 Te'' .(en -irst r!tati!n.i'' ta$e p'ace?
)elect correct option:
a-ter inserting n!,e 2+
after insertin! node ;5
after insertin! node >0
after insertin! node >;

9ermalin7 6eply by ..Tari .ali7 on Danuary '', '"!> at $1"!pm


hich of the followin! statement concernin! heaps is ='T true*
)elect correct option:
e implement the heap b4 77777777777777 .
)elect correct option:
complete binar4 tree
hile buildin! Cuffman encodin! tree the new node that is the result of Hoinin! two nodes has the fre@uenc4.
)elect correct option:
sum of fre@uenc4 of both children nodes
The statement "The insertion operation in avl tree& !enerall4 take_s more time than insertion operation in simple
binar4 search tree" is
)elect correct option:
%s alwa4s incorrect
%n which case of insertion sin!le rotation can make the AO# tree balanced.
)elect correct option:
none of the !iven
%f the bottom level of a binar4 tree is ='T completel4 filled& depicts that the tree is ='T a $$$$$$$$$$
)elect correct option:
complete binar4 tree
A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a ri!ht child has a TC?-A( 0in
actual sense& a link1 to its 7777777777 successor
)elect correct option:
inorder
%f there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
)elect correct option:
;;
hich one of the followin! traversals !ive the mathematical e,pression of an e,pression tree&
)elect correct option:
inorder

9ermalin7 6eply by ..Tari .ali7 on Danuary '', '"!> at $1"!pm

9ermalin7 6eply by ..Tari .ali7 on Danuary '', '"!> at $1"'pm

9ermalin7 6eply by ..Tari .ali7 on Danuary '', '"!> at $1"'pm


>.
The main reason of usin! heap in priorit4 @ueue is
i6pr!Ae per-!r6ance
code is readable
less code
heap can_t be used in priorit4 @ueues
;.
e implement the heap b4 777777777777
Threaded Tree
AO# tree
=omplete binary tree
-,pression
5.
A simple sortin! al!orithm like selection sort or bubble sort has a worst$case of
'0>1 time because all lists take the same amount of time to sort
'0n1 time because it has to perform n swaps to order the list.
O#n2% ti6e 7ecause s!rting 1 e'e6ent ta$es O#n% ti6e - A-ter 1 pass t(r!ug( t(e 'ist?
either of these al!orithms can !uarantee that > element is sorted.
'0n51 time& because the worst case has reall4 random input which takes lon!er to.
<.
%f we want to find median of 50 elements& then after appl4in! buildCeap method& how man4 times deleteMin
method will be called *
)elect correct option:
5
2+
55
50
5.
hich one of the followin! is ='T true re!ardin! the skip list*
-ach list )i contains the special ke4s . infinit4 and $ infinit4.
#ist )0 contains the ke4s of ) in non$decreasin! order.
-ach list is a subse@uence of the previous one.
List S( c!ntains !n'< t(e n specia' $e<s:
F.
hich of the followin! is not true re!ardin! the maKe !eneration*
?andoml4 remove walls until the entrance and e,it cells are in the same set.
?emovin! a wall is the same as doin! a union operation.
Re6!Ae a ran,!6'< c(!sen .a'' i- t(e ce''s it separates are a'rea,< in t(e sa6e set:
(o not remove a randoml4 chosen wall if the cells it separates are alread4 in the same set.
I.
hich propert4 of e@uivalence relation is satisfied if we sa4: Ahmad ?0is related to1 Ahmad
?efle,ivit4
S<66etr<
Transitivit4
8.
The e,pression if 0 ^ heap$:is-mpt401 1 checks
Ceap is empt4
Ceap is full
Ceap is not empt4
N!t a Aa'i, e8pressi!n #n!t c!n-ir6%
9.
e implement the heap b4
Threaded Tree
AO# tree
C!6p'ete 7inar< tree
-,pression
>0.
hich of the followin! statement concernin! heaps is ='T true*
TraAersing a (eap in !r,er pr!Ai,es access t! t(e ,ata in nu6eric !r a'p(a7etica' !r,er:
?emovin! the item at the top provides immediate access to the ke4 value with hi!hest 0or lowest1 priorit4.
%nsertin! an item is alwa4s done at the end of the arra4& but re@uires maintainin! the heap propert4.
A heap ma4 be stored in an arra4.
hich propert4 of relation is satisdied if we sa4: Ahmad ?0is related to1Ahmad
?efle,ivit4
S<66etr<
Transitvit4
All of the !iven
Ceap can be use to implement
)tack
#ink list
+ueue
&ri!rit< ueue
hich one of the followin! is not true re!ardin! skip list.
-ach list )i contain the special ke4 . infinit4 and Pinfinit4
#ist )' contain the ke4 of ) is non$decreasin! order
List S( c!ntain !n'< t(e n specia' $e<s
-ach list in a sub se@uence of previous list on
%f Ahmad is cousin of Ali and Ali is cousin of Asad then Ahmad is also cousin of Asad
the statement has the followin! propert4.
?efle,ivit4
)4mmetr4
TransitiAit<
All of the above
The e,pression of 0^ heap$: is full01 1 check
Ceap is empt4
Ceap is full
Ceap is not empt4
Geap is n!t -u''#n!t c!n-er6%
hich one of the followin! is not the propert4 of e@uivalence relation
?efle,ive
)4mmetric
Transitive
Associative
hich of the followin! is not and implementation of table A
)orted se@uentiall4 arra4
)tack
#ink list
S$ip 'ist
hich one of the followin! is not an open addressin! techni@ue to resolve collection
+uadratic probin!
(ouble hashin!
Cu7ic pr!7ing
#iner probin!
hat is the best definition of a collision on a hash table*
Two entries are identical e,cept for their ke4s.
Two entries with different data have the e,act same ke4.
T.! entries .it( ,i--erent $e<s (aAe t(e e8act (as Aa'ue
Two entries with the e,act same ke4s have different hash value.
9ermalin7 6eply by ..Tari .ali7 on Danuary '', '"!> at $1"'pm
*ear Student,

@e are going to extend the due date of uiG /. 9lease 7eep eyes on announcements.
Than7s
b< )S/"! Instructor
uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !
hich one of the followin! operations returns top value of the stack*
) Eush
) &!p
) Top
) First
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
6ompiler uses which one of the followin! in Function calls&
) )tack
) +ueue
) ;inar< Searc( Tree
) AO# Tree
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
-ver4 AO# is 77777777777777777
) Binar4 Tree
) 6omplete Binar4 Tree
) =one of these
) ;inar< Searc( Tree
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne
%f there are 5F internal nodes in a binar4 tree then how man4 e,ternal nodes this binar4 tree will have*
) 5<
) 55
) 5F
) +3
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne
%f there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) ;5
) ;<
) ;>
) 22
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is not an e,ample of e@uivalence relation*
) -lectrical connectivit4
) )et of people
) => re'ati!n
) )et of pi,els
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne
Binar4 )earch is an al!orithm of searchin!& used with the 777777 data.
) S!rte,
) Dnsorted
) Cetero!eneous
) ?andom
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne
hich one of the followin! is ='T true re!ardin! the skip list*
) -ach list )i contains the special ke4s . infinit4 and $ infinit4.
) #ist )0 contains the ke4s of ) in non$decreasin! order.
) -ach list is a subse@uence of the previous one.
) List S( c!ntains !n'< t(e n specia' $e<s:
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne
A simple sortin! al!orithm like selection sort or bubble sort has a worst$case of
) '0>1 time because all lists take the same amount of time to sort
) '0n1 time because it has to perform n swaps to order the list.
) O#n2% ti6e 7ecause s!rting 1 e'e6ent ta$es O#n% ti6e - A-ter 1 pass t(r!ug( t(e 'ist?
eit(er !- t(ese a'g!rit(6s can guarantee t(at 1 e'e6ent is s!rte,:
) '0n51 time& because the worst case has reall4 random input which takes lon!er to
sort.
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is a propert4 of binar4 tree*
) A binar4 tree of = e,ternal nodes has = internal node.
) A 7inar< tree !- N interna' n!,es (as N9 1 e8terna' n!,e:
) A binar4 tree of = e,ternal nodes has =. > internal node.
) A binar4 tree of = internal nodes has =$ > e,ternal node.
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne
B4 usin! 7777777777we avoid the recursive method of traversin! a Tree& which makes use of stacks and
consumes a lot of memor4 and time.
) Binar4 tree onl4
) T(rea,e, 7inar< tree
) Ceap data structure
) Cuffman encodin!
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! statement is true about dumm4 node of threaded binar4 tree*
) This dumm4 node never has a value.
) This dumm4 node has alwa4s some dumm4 value.
) T(is ,u66< n!,e (as eit(er n! Aa'ue !r s!6e ,u66< Aa'ue:
) This dumm4 node has alwa4s some inte!er value.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
For a perfect binar4 tree of hei!ht h& havin! = nodes& the sum of hei!hts of nodes is
) = P 0h P >1
) N B #( 9 1%
) = P >
) = P > . h
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne
hat is the best definition of a collision in a hash table*
) Two entries are identical e,cept for their ke4s.
) T.! entries .it( ,i--erent ,ata (aAe t(e e8act sa6e $e<
) Two entries with different ke4s have the same e,act hash value.
) Two entries with the e,act same ke4 have different hash values.
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne
hich formula is the best appro,imation for the depth of a heap with n nodes*
) '!g #7ase 2% !- n
) The number of di!its in n 0base >01& e.!.& ><5 has three di!its
) The s@uare root of n
) n
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! statement is ='T correct about find operation:
) %t is not a re@uirement that a find operation returns an4 specific name& Hust that finds on two elements
return the same answer if and onl4 if the4 are in the same set.

) 'ne idea mi!ht be to use a tree to represent each set& since each element in a tree has the same root& thus
the root can be used to name the set.
) %nitiall4 each set contains one element.
) Initia''< eac( set c!ntains !ne e'e6ent an, it ,!es n!t 6a$e sense t! 6a$e a tree !- !ne n!,e !n'<:
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the followin! is not true re!ardin! the maKe !eneration*
) ?andoml4 remove walls until the entrance and e,it cells are in the same set.
) ?emovin! a wall is the same as doin! a union operation.
) Re6!Ae a ran,!6'< c(!sen .a'' i- t(e ce''s it separates are a'rea,< in t(e sa6e set:
) (o not remove a randoml4 chosen wall if the cells it separates are alread4 in the same set.
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne
%n threaded binar4 tree the =D## pointers are replaced b4 &
) preorder successor or predecessor
) in!r,er success!r !r pre,ecess!r
) postorder successor or predecessor
) =D## pointers are not replaced
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne
hich of the !iven option is ='T a factor in Dnion b4 )iKe:
) Maintain siKes 0number of nodes1 of all trees& and durin! union.
) Make smaller tree& the subtree of the lar!er one.
) Ma$e t(e 'arger tree? t(e su7tree !- t(e s6a''er !ne:
) %mplementation: for each root node i& instead of settin! parentQiR to $>& set it to $k if tree rooted at i has k
nodes.
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !ne
)uppose we had a hash table whose hash function is Sn T >;U& if the number 55 is alread4 in the hash table&
which of the followin! numbers would cause a collision*
) ><<
) ><5
) 1*3
) ><8
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !
hat re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4*
) The arra4 elements must form a heap.
) The arra4 must have at least ; entries.
) T(e arra< 6ust 7e s!rte,.
) The arra4Js siKe must be a power of two
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
A binar4 tree with ;< internal nodes has 777777 e,ternal nodes.
) ;;
) ;5
) <8
) 2+
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !n
%n case of deletin! a node from AO# tree& rotation could be prolon! to the root node.
) Ces
) =o
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne
.(en .e (aAe ,ec'are, t(e siDe !- t(e arra<? it is n!t p!ssi7'e t! increase !r ,ecrease it ,uring t(e
EEEEEEEE!- t(e pr!gra6:
) (eclaration

) E8ecuti!n
) (efinin!
) =one of the abov
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne
it .i'' 7e e--icient t! p'ace stac$ e'e6ents at t(e start !- t(e 'ist 7ecause inserti!n an, re6!Aa' ta$e
EEEEEEEti6e:
) Oariable
) C!nstant
) %nconsistent
) =one of the above
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne
_______ is t(e stac$ c(aracteristic 7ut EEEEEEE.as i6p'e6ente, 7ecause !- t(e siDe 'i6itati!n !- t(e
arra<:
) isFull01&is-mpt401
) pop01& push01
) isE6pt<#% ? isFu''#%
) push01&pop01

9ermalin7 6eply by r s U tu U v w U x s w U y r on +ebruary !%, '"!> at (1>$pm


uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne
6ompiler uses which one of the followin! in Function calls&
) Stac$
) +ueue
) Binar4 )earch Tree
Y AO# Tree

9ermalin7 6eply by [\] ^_ on +ebruary !:, '"!> at !"1>!am


Thank u so much

9ermalin7 6eply by asifali on +ebruary !:, '"!> at >1>"pm

9ermalin7 6eply by Nr z {GU tu U{ z r on +ebruary !%, '"!> at >1"$pm


T(e precu'ateD!.n pr!ce,ure .i'' 6!Ae t(e s6a''erAa'ueEEEE an, 7igger Aa'ueEEEEEE:
Se'ect c!rrect !pti!n"
left&ri!ht
ri!ht&left
up&down
,!.n?up
T(ere are EEEEEEEEEcases !- R!tati!n in APLtree:
Se'ect c!rrect !pti!n"
;
5
*
5
.
A complete binar4 tree of hei!ht 5 has between 77777777nodes.
)elect correct option:
8 to ><
4 t! 1+
8 to >F
8 to >I
In case !- inserti!n !- rig(t inner n!,e in ;ST?
)elect correct option:
we need to appl4 sin!le left rotation to make it AO# tree.
we need to appl4 sin!le ri!ht rotationto make it AO# tree.
sin!le left rotation first and then sin!le ri!ht rotation tomake it AO# tree.
sin!le ri!ht rotation first and then sin!le left
;inar< Searc( Tree A!i'ates t(e c!n,iti!n !- APL tree .(en an<n!,e (as 7a'ance eLua' t!
)elect correct option:
2 !r -2
> or $>
0
=one of the options.
Supp!se .e (aAe t(e -!''!.ing Aa'ues t! 7e inserte, inc!nstructing APL tree?
20?23?2+?10?12?13 Te'' .(en -irst r!tati!n.i'' ta$e p'ace?
)elect correct option:
a-ter inserting n!,e 2+
after insertin! node ;5
after insertin! node >0
after insertin! node >;

9ermalin7 6eply by Nr z {GU tu U{ z r on +ebruary !%, '"!> at >1"$pm


A 7inar< re'ati!n R !Aer S is ca''e, an eLuiAa'ence re'ati!n i- it (as -!''!.ing pr!pert<#s%
?efle,ivit4
)4mmetr4
Transitivit4
All of the !iven options
T(e precu'ateD!.n pr!ce,ure .i'' 6!Ae t(e s6a''er Aa'ueEEEE an, 7igger Aa'ueEEEEEE:
left&ri!ht
ri!ht&left
up&down
down&up
I- t(e (eig(t !- a per-ect 7inar< tree is *: /(at .i'' 7e t(e t!ta' nu67er !- n!,es in it1
>5
>F
5>
5;
/(ic( !ne !- t(e -!''!.ing is NOT t(e pr!pert< !- eLuiAa'ence re'ati!n1
?efle,ive
)4mmetric
Transitive
Associative
/(ic( !- t(e -!''!.ing (eap 6et(!, '!.ers t(e Aa'ue !- $e< at p!siti!n WpM 7< t(e a6!unt W,e'taM1
)elect correct option:
increaseVe40p&delta1
decreaseVe40p&delta1
preculate(own0p&delta1
remove0p&delta1
(eap can 7e use, t! i6p'e6ent
stack
linked list
@ueue
priort4 @ueue
.(ic( !- -!''!.ing 6et(!, is (e'p-u' in creating (eap at !nce
insert
add
pecular down
update

9ermalin7 6eply by Nr z {GU tu U{ z r on +ebruary !%, '"!> at >1!/pm


>.
The main reason of usin! heap in priorit4 @ueue is
i6pr!Ae per-!r6ance
code is readable
less code
heap can_t be used in priorit4 @ueues

2:
/e i6p'e6ent t(e (eap 7< ____________
Threaded Tree
AO# tree
C!6p'ete 7inar< tree
-,pression

5.
A simple sortin! al!orithm like selection sort or bubble sort has a worst$case of
'0>1 time because all lists take the same amount of time to sort
'0n1 time because it has to perform n swaps to order the list.
O#n2% ti6e 7ecause s!rting 1 e'e6ent ta$es O#n% ti6e - A-ter 1 pass t(r!ug( t(e 'ist?
eit(er !- t(ese a'g!rit(6s can guarantee t(at 1 e'e6ent is s!rte,:
'0n51 time& because the worst case has reall4 random input which takes lon!er to.
<.
%f we want to find median of 50 elements& then after appl4in! buildCeap method& how man4 times deleteMin
method will be called *
)elect correct option:
5
2+
55
50




5.
hich one of the followin! is ='T true re!ardin! the skip list*
-ach list )i contains the special ke4s . infinit4 and $ infinit4.
#ist )0 contains the ke4s of ) in non$decreasin! order.
-ach list is a subse@uence of the previous one.
List S( c!ntains !n'< t(e n specia' $e<s:
F.
hich of the followin! is not true re!ardin! the maKe !eneration*
?andoml4 remove walls until the entrance and e,it cells are in the same set.
?emovin! a wall is the same as doin! a union operation.
Re6!Ae a ran,!6'< c(!sen .a'' i- t(e ce''s it separates are a'rea,< in t(e sa6e set:
(o not remove a randoml4 chosen wall if the cells it separates are alread4 in the same set.
I.
hich propert4 of e@uivalence relation is satisfied if we sa4: Ahmad ?0is related to1 Ahmad
?efle,ivit4
S<66etr<
Transitivit4
8.
The e,pression if 0 ^ heap$:is-mpt401 1 checks
Ceap is empt4
Ceap is full
Ceap is not empt4
N!t a Aa'i, e8pressi!n #n!t c!n-ir6%




5:
e implement the heap b4
Threaded Tree
AO# tree
C!6p'ete 7inar< tree
-,pression
>0.
/(ic( !- t(e -!''!.ing state6ent c!ncerning (eaps is NOT true1
TraAersing a (eap in !r,er pr!Ai,es access t! t(e ,ata in nu6eric !r a'p(a7etica' !r,er:
?emovin! the item at the top provides immediate access to the ke4 value with hi!hest 0or lowest1 priorit4.
%nsertin! an item is alwa4s done at the end of the arra4& but re@uires maintainin! the heap propert4.
A heap ma4 be stored in an arra4.

hich propert4 of relation is satisdied if we sa4: Ahmad ?0is related to1Ahmad
?efle,ivit4
S<66etr<
Transitvit4
All of the !iven
Ceap can be use to implement
)tack
#ink list
+ueue
&ri!rit< ueue
hich one of the followin! is not true re!ardin! skip list.
-ach list )i contain the special ke4 . infinit4 and Pinfinit4
#ist )' contain the ke4 of ) is non$decreasin! order
List S( c!ntain !n'< t(e n specia' $e<s
-ach list in a sub se@uence of previous list one
%f Ahmad is cousin of Ali and Ali is cousin of Asad then Ahmad is also cousin of Asad
the statement has the followin! propert4.
?efle,ivit4
)4mmetr4
TransitiAit<
All of the above
The e,pression of 0^ heap$: is full01 1 check
Ceap is empt4
Ceap is full
Ceap is not empt4
Geap is n!t -u''#n!t c!n-er6%
hich one of the followin! is not the propert4 of e@uivalence relation
?efle,ive
)4mmetric
Transitive
Ass!ciatiAe
hich of the followin! is not and implementation of table A(T
)orted se@uentiall4 arra4
)tack
#ink list
S$ip 'ist
hich one of the followin! is not an open addressin! techni@ue to resolve collection
+uadratic probin!
(ouble hashin!
Cu7ic pr!7ing
#iner probin!
hat is the best definition of a collision on a hash table*
Two entries are identical e,cept for their ke4s.
T.! entries .it( ,i--erent ,ata (aAe t(e e8act sa6e $e<:
Two entries with different ke4s have the e,act has value
Two entries with the e,act same ke4s have different hash value.
uestion =o:0> 0 Marks: > 1 $ Elease choose one The easiest case of deletin! a node from B)T is the case in which the node
to be deleted 77777777777. Y %s a leaf node 0Ea!e >I51 Y Cas left subtree onl4 Y Cas ri!ht subtree onl4 Y Cas both
left and ri!ht subtree
+uestion =o:0; 0 Marks: > 1 $ Elease choose one hat is the best definition of a collision in a hash table* Y Two entries
are identical e,cept for their ke4s. Y Two entries with different data have the e,act same ke4 Y Two entries with different
ke4s have the same e,act hash value. 0pa!e <F<1 YTwo entries with the e,act same ke4 have different hash values.
+uestion =o:05 0 Marks: > 1 $ Elease choose one hich one of the followin! is ='T true re!ardin! the skip list* Y -ach
list )i contains the special ke4s . infinit4 and $ infinit4. Y #ist )0 contains the ke4s of ) in non$decreasin! order. Y -ach
list is a subse@uence of the previous one. Y #ist )h contains onl4 the n special ke4s.
+uestion =o: 0<0 Marks: > 1 $ Elease choose one hich formula is the best appro,imation for the depth of a heap with n
nodes* Y lo! 0base ;1 of n 0pa!e 5551 Y The number of di!its in n 0base >01& e.!.& ><5 has three di!its Y The s@uare root
of n Y n
+uestion =o: 050 Marks: > 1 $ Elease choose one A complete binar4 tree of hei!ht 7777 has nodes between >F to 5> . Y ;
Y 5 Y < 0pa!e 5I51 Y 5
+uestion =o 0F 0 Marks: > 1 $ Elease choose one S.U is a 777777777operator. Y Dnar4 Y Binar4 0pa!e F<1 Y Ternar4 Y
=one of the above
+uestion =o:0I 0 Marks: > 1 $ Elease choose one There isAare 77777777 caseAs for rotation in an AO# tree& Y > Y 5 Y ;
Y < 0pa!e ;;91
+uestion =o: 080 Marks: > 1 $ Elease choose one hich of the followin! is ='T a correct statement about Table A(T. Y
%n a table& the t4pe of information in columns ma4 be different. Y A table consists of several columns& known as entities.
0pa!e <081 Y The row of a table is called a record. Y A maHor use of table is in databases where we build and use tables
for keepin! information.
+uestion =o: 090 Marks: > 1 $ Elease choose one %f there are = elements in an arra4 then the number of ma,imum steps
needed to find an element usin! Binar4 )earch is 7777777 . Y = Y =; Y =lo!;= Y lo!;= 0pa!e <<01
+uestion =o: >00 Marks: > 1 $ Elease choose one A binar4 tree with 55 internal nodes has 7777777 links to internal nodes.
Y 5> Y 5; 0Ea!e 50<1 Y 55 Y FF +uestion =o: ;0
+uestion =o:>> 0 Marks: > 1 $ Elease choose one %f there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of
internal nodes in this binar4 tree* Y ;5 Y ;< Y ;> Y ;; 0n$>1 0Ea!e 50<1
+uestion =o: >; 0 Marks: > 1 $ Elease choose one A complete binar4 tree of hei!ht 5 has between 77777777 nodes. Y 8 to
>< Y 8 to >5 0Ea!e >;<1 Y 8 to >F Y 8 to >I ;Z0d.>1 $ > G ;Z05.>1 $> G ;Z< $> G >F$> G >5
+uestion =o: >5 0 Marks: > 1 $ Elease choose one 6onsider a min heap& represented b4 the followin! arra4:
>0&50&;0&I0&<0&50&80&F0 After insertin! a node with value 5>.hich of the followin! is the updated min heap* Y
>0&50&;0&5>&<0&50&80&F0&I0 0pa!e 55I1 Y >0&50&;0&I0&<0&50&80&F0&5> Y >0&5>&;0&50&<0&50&80&F0&5> Y
5>&>0&50&;0&I0&<0&50&80&F0
+uestion =o: >< 0 Marks: > 1 $ Elease choose one e are !iven = items to build a heap& this can be done with 77777
successive inserts. Y =$> Y = 0Ea!e 5551 Y =.> Y =Z;
+uestion =o: >5 0 Marks: > 1 $ Elease choose one 7777777777 onl4 removes items in reverse order as the4 were entered.
Y )tack 0Ea!e 8>1 Y +ueue Y Both of these Y =one of these
+uestion =o: >F 0 Marks: > 1 $ Elease choose one %f a ma, heap is implemented usin! a partiall4 filled arra4 called data&
and the arra4 contains n elements 0n : 01& where is the entr4 with the !reatest value* (ataQ0R is correct YdataQ>R YdataQn$
>R YdataQnR YdataQ;/n.>R
+uestion =o: >I 0 Marks: > 1 $ Elease choose one %n a selection sort of n elements& how man4 times the swap function is
called to complete the e,ecution of the al!orithm*
Y n$> Y n lo! n Y n; Y >
+uestion =o: >8 0 Marks: > 1 $ Elease choose one %n threaded binar4 tree the =D## pointers are replaced b4 & Y preorder
successor or predecessor Y inorder successor or predecessor 0Ea!e 50I1 Y postorder successor or predecessor Y =D##
pointers are not replaced
+uestion =o: >9 0 Marks: > 1 $ Elease choose one hich one of the followin! al!orithms is most widel4 used due to its
!ood avera!e time& Y Bubble )ort Y %nsertion )ort
Y +uick )ort Y Mer!e )ort
FINALTERM EXAMINATION
Fall ;009
6)50>$ (ata )tructures

uesti!n N!" 1 # Mar$s" 1 % - &'ease c(!!se !ne


7777777777 onl4 removes items in reverse order as the4 were entered.
) Stac$
) +ueue
) Both of these
) =one of these
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


Cere is a small function definition:
void f0int i& int Xk1
2
i G >9
k G ;9
3
)uppose that a main pro!ram has two inte!er variables , and 4& which are !iven the value 0. Then the
main pro!ram calls f0,&419 hat are the values of , and 4 after the function f finishes*
) Both , and 4 are still 0.
) , is now >& but 4 is still 0.
) 8 is sti'' 0? 7ut < is n!. 2:
) , is now >& and 4 is now ;.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


)elect the one FALSE statement about binar4 trees:
) EAer< 7inar< tree (as at 'east !ne n!,e:
) -ver4 non$empt4 tree has e,actl4 one root node.
) -ver4 node has at most two children.
) -ver4 non$root node has e,actl4 one parent.
uesti!n N!" * # Mar$s" 1 % - &'ease c(!!se !ne


-ver4 AO# is 77777777777777777
) Binar4 Tree
) 6omplete Binar4 Tree
) =one of these
) ;inar< Searc( Tree
uesti!n N!" + # Mar$s" 1 % - &'ease c(!!se !ne


)earchin! an element in an AO# tree take ma,imum 7777777 time 0where n is no. of nodes in AO#
tree1&
) #o!;0n.>1
) #o!;0n.>1 $>
) 1:** L!g2n
) >.FF #o!;n
uesti!n N!" 2 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose that we have implemented a priority queue b4 storin! the items in a heap. e are now e,ecutin!
a reheapification downward and the out$of$place node has priorit4 of <;. The nodeJs parent has a priorit4
of I;& the left child has priorit4 5; and the nodeJs ri!ht child has priorit4 F;. hich statement best
describes the status of the reheapification.
) The reheapification is done.
) The ne,t step will interchan!e the two children of the out$of$place node.
) The ne,t step will swap the out$of$place node with its parent.
) The ne,t step will swap the out$of$place node with its left child.
uesti!n N!" 3 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose 4ou implement a heap 0with the lar!est element on top1 in an arra4. 6onsider the different arra4s
below& determine the one that cannot possibl4 be a heap:
) I F 5 < 5 ; >
) I 5 F ; > < 5
) I F < 5 5 ; >
) I 5 F < ; 5 >
uesti!n N!" 4 # Mar$s" 1 % - &'ease c(!!se !ne


%f there are ;5 e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4
tree*
) ;5
) ;<
) ;>
) 22
uesti!n N!" 5 # Mar$s" 1 % - &'ease c(!!se !ne


%f there are = e,ternal nodes in a binar4 tree then what will be the no. of internal nodes in this binar4 tree*
) N -1
) =.>
) =.;
) =
uesti!n N!" 10 # Mar$s" 1 % - &'ease c(!!se !ne


hich one of the followin! is ='T the propert4 of e@uivalence relation:
) ?efle,ive
) )4mmetric
) Transitive
) Ass!ciatiAe
uesti!n N!" 11 # Mar$s" 1 % - &'ease c(!!se !ne


The definition of Transitivit4 propert4 is
) For all element , member of )& , ? ,
) For all elements , and 4& , ? 4 if and onl4 if 4 ? ,
) F!r a'' e'e6ents 8? < an, D? i- 8 R < an, < R D t(en 8 R D
) For all elements w& ,& 4 and K& if , ? 4 and w ? K then , ? K
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


Dnion is a 7777777 time operation.
) C!nstant
) Eol4nomial
) -,ponential
) =one of the !iven options
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! is ='T a correct statement about Table A(T.
) %n a table& the t4pe of information in columns ma4 be different.
) A table consists of several columns& known as entities.
) The row of a table is called a record.
) A maHor use of table is in databases where we build and use tables for keepin! information.
uesti!n N!" 1* # Mar$s" 1 % - &'ease c(!!se !ne


%n the worst case of deletion in AO# tree re@uires 777777777.
) 'nl4 one rotation
) ?otation at each non$leaf node
) ?otation at each leaf node
) R!tati!ns eLua' t! '!g2 N
uesti!n N!" 1+ # Mar$s" 1 % - &'ease c(!!se !ne


Binar4 )earch is an al!orithm of searchin!& used with the 777777 data.
) S!rte,
) Dnsorted
) Cetero!eneous
) ?andom
uesti!n N!" 12 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! statement is correct*
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a left child has a
TC?-A( 0in actual sense& a link1 to its %='?(-? successor.
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a ri!ht child has a
TC?-A( 0in actual sense& a link1 to its E?-'?-(? successor.
) A T(rea,e, ;inar< Tree is a 7inar< tree in .(ic( eAer< n!,e t(at ,!es n!t (aAe a rig(t c(i',
(as a TGREAD #in actua' sense? a 'in$% t! its INORDER success!r:
) A Threaded Binar4 Tree is a binar4 tree in which ever4 node that does not have a ri!ht child has a
TC?-A( 0in actual sense& a link1 to its E')T'?(-? successor.
uesti!n N!" 13 # Mar$s" 1 % - &'ease c(!!se !ne


B4 usin! 7777777777we avoid the recursive method of traversin! a Tree& which makes use of stacks and
consumes a lot of memor4 and time.
) Binar4 tree onl4
) T(rea,e, 7inar< tree
) Ceap data structure
) Cuffman encodin!
uesti!n N!" 14 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! statement is ='T true about threaded binar4 tree*
) ?i!ht thread of the ri!ht$most node points to the dummy node.
) #eft thread of the left$most node points to the dummy node.
) The left pointer of dumm4 node points to the root node of the tree.
) #eft thread of the ri!ht$most node points to the dummy node.
uesti!n N!" 15 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider a min heap& represented b4 the followin! arra4:
>>&;;&55&<<&55
After insertin! a node with value FF.hich of the followin! is the updated min heap*
) >>&;;&55&<<&55&FF
) >>&;;&55&<<&FF&55
) >>&;;&55&FF&<<&55
) >>&;;&FF&55&<<&55
uesti!n N!" 20 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider a min heap& represented b4 the followin! arra4:
5&<&F&I&5
After callin! the function deleteMin01.hich of the followin! is the updated min heap*
) <&F&I&5
) F&I&5&<
) <&5&F&I
) <&F&5&I
uesti!n N!" 21 # Mar$s" 1 % - &'ease c(!!se !ne


e can build a heap in 77777777 time.
) Linear
) -,ponential
) Eol4nomial
) =one of the !iven options
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne


)uppose we are sortin! an arra4 of ei!ht inte!ers usin! @uick sort& and we have Hust finished the first
partitionin! with the arra4 lookin! like this:
; 5 > I 9 >; >> >0
hich statement is correct*
) T(e piA!t c!u', 7e eit(er t(e 3 !r t(e 5:
) The pivot could be the I& but it is not the 9.
) The pivot is not the I& but it could be the 9.
) =either the I nor the 9 is the pivot.
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne


hich formula is the best appro,imation for the depth of a heap with n nodes*
) '!g #7ase 2% !- n
) The number of di!its in n 0base >01& e.!.& ><5 has three di!its
) The s@uare root of n
) n
uesti!n N!" 2* # Mar$s" 1 % - &'ease c(!!se !ne


)uppose 4ou implement a Min heap 0with the smallest element on top1 in an arra4. 6onsider the different
arra4s below9 determine the one that cannot possibl4 be a heap:
) >F& >8& ;0& ;;& ;<& ;8& 50
) >F& ;0& >8& ;<& ;;& 50& ;8
) >F& ;<& >8& ;8& 50& ;0& ;;
) >F& ;<& ;0& 50& ;8& >8& ;;
uesti!n N!" 2+ # Mar$s" 1 % - &'ease c(!!se !ne


hile Hoinin! nodes in the buildin! of Cuffman encodin! tree if there are more nodes with same
fre@uenc4& we choose the nodes 7777777.
) Ran,!6'<
) That occur first in the te,t messa!e
) That are le,icall4 smaller amon! others.
) That are le,icall4 !reater amon! others
uesti!n N!" 22 # Mar$s" 1 % - &'ease c(!!se !ne


6onsider the followin! para!raph with blanks.
A WW.WW.. is a linear list where WWWWW and WWWW take place at the
same end . This end is called the WW.WWW.
hat would be the correct fillin! the above blank positions*
) 0i1 @ueue 0ii1 insertion 0iii1 removals 0iv1 top
) 0i1 stack 0ii1 insertion 0iii1 removals 0iv1 bottom
) #i% stac$ #ii% inserti!n #iii% re6!Aa's #iA% t!p
) 0i1 tree 0ii1 insertion 0iii1 removals 0iv1 top
uesti!n N!" 23 # Mar$s" 1 % - &'ease c(!!se !ne


A binar4 tree with 55 internal nodes has 7777777 links to internal nodes.
) 5>
) 32
) 55
) FF
uesti!n N!" 24 # Mar$s" 1 % - &'ease c(!!se !ne


hich traversal !ives a decreasin! order of elements in a heap where the ma, element is stored at the
top*
) post$order
) level$order
) inorder
) =one of the !iven options
uesti!n N!" 25 # Mar$s" 1 % - &'ease c(!!se !ne


hat re@uirement is placed on an arra4& so that binary search ma4 be used to locate an entr4*
) The arra4 elements must form a heap.
) The arra4 must have at least ; entries.
) The arra4 must be sorted.
) The arra4Js siKe must be a power of two.
uesti!n N!" 30 # Mar$s" 1 % - &'ease c(!!se !ne


hich of the followin! is a non linear data structure*
) #inked #ist
) )tack
) +ueue
) Tree
uesti!n N!" 31 # Mar$s" 1 %


%f a Binar4 Tree has = internal nodes what are the no. of e,ternal nodes in it.
)ol. The =o. of e,ternal nodes will be N91
uesti!n N!" 32 # Mar$s" 1 %


hat is meant b4 )4mmetr4 in e@uivalence relations*
S!': )4mmetr4 in e@uivalence relations mean for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
uesti!n N!" 33 # Mar$s" 2 %


Cow heap sort works to sort a set of data.
uesti!n N!" 3* # Mar$s" 2 %


Cow we can appl4 Find operation on elements combined throu!h Dnion operation.
uesti!n N!" 3+ # Mar$s" 3 %


Cow we can use concept of e@uivalence relations to !enerate a MaKe.
uesti!n N!" 32 # Mar$s" 3 %


Supp!se .e are s!rting an arra< !- eig(t integers using a s!6e Lua,ratic s!rting a'g!rit(6: A-ter
-!ur iterati!ns !- t(e a'g!rit(6Ms 6ain '!!p? t(e arra< e'e6ents are !r,ere, as s(!.n (ere"
2 * + 3 4 1 3 2
/(ic( state6ent is c!rrect1 #N!te" Our se'ecti!ns!rt pic$s 'argest ite6s -irst:%
A: T(e a'g!rit(6 6ig(t 7e eit(er se'ecti!ns!rt !r inserti!ns!rt:
;: T(e a'g!rit(6 6ig(t 7e se'ecti!ns!rt? 7ut it is n!t inserti!ns!rt:
C: T(e a'g!rit(6 is n!t se'ecti!ns!rt? 7ut it 6ig(t 7e inserti!ns!rt: #C!rrect%
D: T(e a'g!rit(6 is neit(er se'ecti!ns!rt n!r inserti!ns!rt:
E: N!ne !- t(ese:
uesti!n N!" 33 # Mar$s" 3 %


Cow man4 leaf and non$leaf nodes are present in a complete binar4 tree if its depth is I *
uesti!n N!" 34 # Mar$s" + %


%f we insert a new element into an AO# tree of hei!ht <& is one rotation sufficient to re$establish balance*
Mustif4 4our answer.
uesti!n N!" 35 # Mar$s" + %


/rite ,!.n t(e C99 c!,e -r!6 Se'ecti!n S!rt A'g!rit(6:
uesti!n N!" *0 # Mar$s" 10 %


6onsider the followin! data:
t(e cat in t(e (at
a1 Build fre@uenc4 table for the above data.
b1 6reate a Cuffman tree to determine the binar4 codes for each character.
c1 hat will be the code of each letter*
uesti!n N!" *1 # Mar$s" 10 %


)uppose we have build a )kip list .=ow we want to add and remove items from the list .Live Al!orithms
for insert #ite6% and ,e'ete #ite6% methods of the )kip #ist.
FINALTERM EXAMINATION
Fa'' 2005
CS301- Data Structures #Sessi!n - 1%
&uestion 'o( ) * +arks( ) , 9 Flease choose one

The
data of the problem is of ;LB and the hard disk is of >LB capacit4& to solve this problem we should
) lse better data structures
) Increase the hard dis7 space
Cse the better algorithm
) lse as much data as we can store on the hard dis7

&uestion 'o( 2 * +arks( ) , 9 Flease choose one

%n
an arra4 list the current element is
) The frst element
) The middle element
) The last element
0he element where the current pointer points to

&uestion 'o( 3 * +arks( ) , 9 Flease choose one


hich one of the followin! is a valid postfi, e,pression*
) abNcod?
abcHEd9
) abcNod?
) 8abco;Nd?

&uestion 'o( 4 * +arks( ) , 9 Flease choose one

%n
se@uential access data structure& accessin! an4 element in the data structure takes different amount of
time. Tell which one of the followin! is se@uential access data structure& Lin$e, 'ist
) Arra4s
) #ists
) Both of these
N!ne !- t(ese

&uestion 'o( 5 * +arks( ) , 9 Flease choose one

%
have implemented the @ueue with a circular arra4. %f data is a circular arra4 of 6AEA6%TN elements& and
last is an inde, into that arra4& what is the formula for the inde, after last*
) 0last T >1 . 6AEA6%TN
) last T 0> . 6AEA6%TN1
#'ast 9 1% ^ CA&ACITC
) last . 0> T 6AEA6%TN1

&uestion 'o( 6 * +arks( ) , 9 Flease choose one


hich one of the followin! is T?D- about recursion*
) ?ecursion e,tensivel4 uses stack memor4.
) Threaded Binar4 Trees use the concept of recursion.
RecursiAe -uncti!n ca''s c!nsu6e a '!t !- 6e6!r<:
) %teration is more efficient than iteration.

&uestion 'o( - * +arks( ) , 9 Flease choose one


6ompiler uses which one of the followin! to evaluate a mathematical e@uation&
)Binar4 Tree
)Binar4 )earch Tree
&arse Tree
)AO# Tree

&uestion 'o( 8 * +arks( ) , 9 Flease choose one


hich one of the followin! is T?D- about iteration*
)%teration e,tensivel4 uses stack memor4.
)Threaded Binar4 Trees use the concept of iteration.
)%terative function calls consumes a lot of memor4.
Recursi!n is 6!re e--icient t(an iterati!n:

&uestion 'o( 9 * +arks( ) , 9 Flease choose one

%f a
ma, heap is implemented usin! a partiall4 filled arra4 called data& and the arra4 contains n elements 8n
b ";& where is the entr4 with the !reatest value* DataH0I
dataQ>R
dataLn?!M
dataLnM
dataL'onN!M

&uestion 'o( ). * +arks( ) , 9 Flease choose one

%f
there are 5F internal nodes in a binar4 tree then how man4 e,ternal nodes this binar4 tree will have*
) (>
) ((
) ($
5-

&uestion 'o( )) * +arks( ) , 9 Flease choose one


hich of the followin! heap method increase the value of ke4 at position `pJ b4 the amount `deltaJ*
increaseGey*p,delta,
) decreaseney8p,delta;
) preculate*own8p,delta;
) remo2e8p,delta;

&uestion 'o( )2 * +arks( ) , 9 Flease choose one

If
we ha2e !""" sets each containing a single diBerent person. @hich of the following
relation will be true on each set1
2eIe7ive
) Symmetric
) Transiti2e
) -ssociati2e

&uestion 'o( )3 * +arks( ) , 9 Flease choose one


@hich one of the following is not an example of eui2alence relation1
Electrical connecti2ity
Set of people
JK relation
Set of pixels

&uestion 'o( )4 * +arks( ) , 9 Flease choose one

A
binar4 tree of = nodes has 7777777.
) #o!>0 = levels
L!g2 N 'eAe's
) = A ; levels
) = , ; levels

&uestion 'o( )5 * +arks( ) , 9 Flease choose one


Binar4 )earch is an al!orithm of searchin!& used with the 777777 data.
S!rte,
) Dnsorted
) Cetero!eneous
) ?andom

&uestion 'o( )6 * +arks( ) , 9 Flease choose one


6onsider te followin! arra4
;5 >5 5 >; <0 >0 I
After the first pass of a particular al!orithm& the arra4 looks like
>. 5 >; ;5 >0 I <0
=ame the al!orithm used
) Ceap sort
Se'ecti!n s!rt
) %nsertion sort
) Bubble sort

&uestion 'o( )- * +arks( ) , 9 Flease choose one


hich of the followin! statements is correct propert4 of binar4 trees*
) A binar4 tree with = internal nodes has =.> internal links.
) A binar4 tree with = e,ternal nodes has ;= internal nodes.
A 7inar< tree .it( N interna' n!,es (as N91 e8terna' n!,es:
) =one of above statement is a propert4 of the binar4 tree.

&uestion 'o( )8 * +arks( ) , 9 Flease choose one


hich of the followin! is a propert4 of binar4 tree*
) A binar4 tree of = e,ternal nodes has = internal node.
A 7inar< tree !- N interna' n!,es (as N9 1 e8terna' n!,e:
) A binar4 tree of = e,ternal nodes has =. > internal node.
) A binar4 tree of = internal nodes has =$ > e,ternal node.

&uestion 'o( )9 * +arks( ) , 9 Flease choose one


hich of the followin! statement is true about dumm4 node of threaded binar4 tree*
) The left pointer of dumm4 node points to the itself while the ri!ht pointer points to the root of
tree.
T(e 'e-t p!inter !- ,u66< n!,e p!ints t! t(e r!!t n!,e !- t(e tree .(i'e t(e rig(t p!inter
p!ints itse'- i:e: t! dummy n!,e
) The left pointer of dumm4 node points to the root node of the tree while the ri!ht pointer is
alwa4s =D##.
) The ri!ht pointer of dumm4 node points to the itself while the left pointer is alwa4s =D##.

&uestion 'o( 2. * +arks( ) , 9 Flease choose one

%f
the bottom level of a binar4 tree is ='T completel4 filled& depicts that the tree is ='T a
) -,pression tree
) Threaded binar4 tree
) complete Binar4 tree
&er-ect'< c!6p'ete ;inar< tree

&uestion 'o( 2) * +arks( ) , 9 Flease choose one

%n a
selection sort of n elements& how man4 times the swap function is called to complete the e,ecution of the
al!orithm*
L n9)
| n lo! n
| n
'
| !

&uestion 'o( 22 * +arks( ) , 9 Flease choose one


@hich of the following statement is correct about fnd8x; operation1
L " 8nd*7, on element 7 is per%ormed by returning e7actly the same
node that is %ound
| - fnd8x; on element x is performed by returning the root of the tree
containing x.
| - fnd8x; on element x is performed by returning the whole tree itself
containing x.
| - fnd8x; on element x is performed by returning T6lE.

&uestion 'o( 23 * +arks( ) , 9 Flease choose one


@hich of the following statement is NXT correct about fnd operation1
) It is not a reuirement that a fnd operation returns any specifc name, =ust
that fnds on two elements return the same answer if and only if they are in the
same set.
) Xne idea might be to use a tree to represent each set, since each element in
a tree has the same root, thus the root can be used to name the set.
) Initially each set contains one element.
/nitially each set contains one element and it does not make sense
to make a tree o% one node only

&uestion 'o( 24 * +arks( ) , 9 Flease choose one


6onsider the followin! postfi, e,pression ) and the initial values of the variables.
) G A B $ 6 . ( - F $ . Z
Assume that AG5& BG;& 6G>& (G>& -G;& FG5
hat would be the final output of the stack*
) !
) '
) "
9)

&uestion 'o( 25 * +arks( ) , 9 Flease choose one

The
ma,imum number of e,ternal nodes 0leaves1 for a binar4 tree of hei!ht C is EEEEEEEEE
2
A
) '
A
N!
) '
A
?!
) '
A
N'

&uestion 'o( 26 * +arks( ) , 9 Flease choose one

%n
threaded binar4 tree the =D## pointers are replaced b4 &
) preorder successor or predecessor
in!r,er success!r !r pre,ecess!r
) postorder successor or predecessor
) =D## pointers are not replaced

&uestion 'o( 2- * +arks( ) , 9 Flease choose one

%n a
min heap & preculate(own procedure will move smaller value777777 and bi!!er value777777.
) left,right
) right,left
up,down
) down,up

&uestion 'o( 28 * +arks( ) , 9 Flease choose one


hich of the followin! statement is correct about union:
0o per%orm Cnion o% two sets, we merge the two trees by making
the root o% one tree point to the root o% the other
) To perform lnion of two sets, we merge the two trees by ma7ing the leaf
node of one tree point to the root of the other.
) To perform lnion of two sets, merging operation of trees in not reuired at
all.
) None of the gi2en options.

&uestion 'o( 29 * +arks( ) , 9 Flease choose one

)uppose A is an arra4 containin! numbers in increasin! order& but some numbers occur more than once
when usin! a binar4 search for a value& the binar4 search alwa4s finds 777777777777
) the first occurrence of a value.
) the second occurrence of a value.
) ma4 find first or second occurrence of a value.
N!ne !- t(e giAen !pti!ns.

&uestion 'o( 3. * +arks( ) , 9 Flease choose one

&et
heap stored in an array as A ` L(", >", /#, /', '%, '', /$, !/M. In other words, the
root of the heap contains the maximum element. @hat is the result of deleting >"
from this heap
M5.,32, 3-,)3, 28, 22, 36N
) L/#, '%, /', '', /$, !/M
) L/#, /$, /', '%, !/, ''M
) L/#, /', /$, !/, '%, ''M

&uestion 'o( 3) * +arks( ) ,

(escribe the conditions for second case of deletion in AO# Trees.
"nswer(
The node to be deleted has either left child 0subtree1 or ri!ht child 0subtree1. %n this case we b4pass the
node in such a wa4 that we find the inorder successor of this node and then link the parent of the node to
be deleted to this successor node.Thus the node was deleted.

&uestion 'o( 32 * +arks( ) ,

hat is Table abstract data t4pe.
"nswer(
An abstract data structure is a mathematical model for a certain class of data structures that have
similar behavior9 or for certain data types of one or more programming languages that have
similar semantics.

&uestion 'o( 33 * +arks( 2 ,

Cow
we can !enerate a maKe .Live an al!orithm.
Ans.er"
A maKe can be !enerated b4 startin! with a predetermined arran!ement of cells 0most commonl4 a
rectan!ular !rid but other arran!ements are possible1 with wall sites between them. This predetermined
arran!ement can be considered as a connected graph with the ed!es representin! possible wall sites
and the nodes representin! cells.
The al!orithm is as follows:
{ ?andoml4 remove walls until the entrance and e,it cells are in the same set.
{ ?emoval of the wall is the same as doin! a union operation.
{ (o not remove a randoml4 chosen wall if the cells it separates are alread4 in
the same set.

&uestion 'o( 34 * +arks( 2 ,


?epresent the followin! Binar4 tree usin! arra4 representation.
- B ) * E
" ! ' / > ( $ #

&uestion 'o( 35 * +arks( 3 ,


hat is an -@uivalent relation* Live an4 two e,amples.
A binar4 relation ? over a set ) is called an equi'alence relation if it has followin!
Eroperties
>.?efle,ivit4: for all element , } )& , ? ,
;. )4mmetr4: for all elements , and 4& , ? 4 if and onl4 if 4 ? ,
5. Transitivit4: for all elements ,& 4 and K& if , ? 4 and 4 ? K then , ? K

&uestion 'o( 36 * +arks( 3 ,

"For
smaller lists& linear insertion sort performs well& but for lar!er lists& @uick sort is suitable to appl4." Mustif4
wh4*
+uicksort sorts b4 emplo4in! a divide and con@uer strate!4 to divide a list into two sub$lists.
Full e,ample of @uicksort on a random set of numbers. The bo,ed element is the pivot. %t is alwa4s
chosen as the last element of the partition.The steps are:
>.Eick an element& called a pivot& from the list.
;.?eorder the list so that all elements which are less than the pivot come before the pivot and so that all
elements !reater than the pivot come after it 0e@ual values can !o either wa41. After this partitionin!& the
pivot is in its final position. This is called the partition operation.
5.?ecursivel4 sort the sub$list of lesser elements and the sub$list of !reater elements

&uestion 'o( 3- * +arks( 3 ,

Cow
man4 leaf and non$leaf nodes are present in a complete binar4 tree if its depth is I *
e know that the total number of nodes 0leaf and non$leaf1 of a complete binar4 tree
of depth d is e@ual to ;d2> P >.
%t can be calculated as
;
I
G>< nodes

&uestion 'o( 38 * +arks( 5 ,


Re6!Ae t(e s6a''est e'e6ent -r!6 t(e -!''!.ing arra< .(ic( represents a 6in-(eap:
!rigina' 6in-(eap 1 3 2 + * 4 5 10 3
an, s(!. t(e resu'tant (eap in t(e -!r6 !- arra< as s(!.n 7e'!.?
a-ter re6!Aa' 2 3 4 + * 5 10 3

&uestion 'o( 39 * +arks( 5 ,

Cere
is an arra4 with e,actl4 >5 elements:
> ; 5 < 5 F I 8 9 >0 >> >; >5 >< >5.
)uppose that we are doin! a binar4 search for an element. %ndicate an4 elements that will be found b4
e,aminin! two or fewer numbers from the arra4.

&uestion 'o( 4. * +arks( ). ,

a1
rite 6.. al!orithm for Binar4 )earch
int is#resent$int %arr& int 'al& int ()
*
int lo+ , -.
int hih , ( / 0.
int mid.
+hile $ lo+ 1, hih )
*
mid , $ lo+ 2 hih )32.
if $arr4mid5 ,, 'al)
return 0. 33 found6
else if $arr4mid5 1 'al)
lo+ , mid 2 0.
else
hih , mid / 0.
7
return -. 33 not found
E8a6p'e
int binar4)earch0int sortedArra4QR& int first& int last& int ke41 2
AA function:
AA )earches sortedArra4QfirstR..sortedArra4QlastR for ke4.
AA returns: inde, of the matchin! element if it finds ke4&
AA otherwise $0inde, where it could be inserted1$>.
AA parameters:
AA sortedArra4 in arra4 of sorted 0ascendin!1 values.
AA first& last in lower and upper subscript bounds
AA ke4 in value to search for.
AA returns:
AA inde, of ke4& or $insertion7position $> if ke4 is not
AA in the arra4. This value can easil4 be
AA transformed into the position to insert it.

while 0first 8G last1 2
int mid G 0first . last1 A ;9 AA compute mid point.
if 0ke4 : sortedArra4QmidR1
first G mid . >9 AA repeat search in top half.
else if 0ke4 8 sortedArra4QmidR1
last G mid $ >9 AA repeat search in bottom half.
else
return mid9 AA found it. return position AAAAA
3
return $0first . >19 AA failed to find ke4
3
b1 6onsider the followin! arra4 of values9 show how the binar4 search al!orithm would find the value -/.
6learl4 showAe,plain 4our work9 that is& show the values of start& end& etc. for each step of the al!orithm.

&uestion 'o( 4) * +arks( ). ,


)how the result of followin! se@uence of instructions
Dnion0>&;1
Dnion05&<1
Dnion05&51
Dnion0>&I1
Dnion05&F1
Dnion08&91
Dnion0>&81
Dnion05&>01
Dnion05&>>1
Dnion05&>;1
Dnion05&>51
Dnion0><&>51
Dnion0>F&>I1
Dnion0><&>F1
Dnion0>&51
Dnion0>&><1
hen the unions are performed b4 hei!ht
N!te" Nou have to show onl4 Final tree& =o need to show all steps.
%
!
$
:
!
# '
!
/
!
'
/
>
(
!
!
!
"
$
!
#
!
>
!
(
F/'"$012+ 13"+/'"0/4'
+all '"":
)S/"!? *ata Structures
&uestion 'o( ) * +arks( ) , 9 Flease choose one


The arguments passed to a function should match in number, type and order with
the parameters in the function defnition.
| True
L +alse
&uestion 'o( 2 * +arks( ) , 9 Flease choose one


%f numbers 5& ;;;& <& <8 are inserted in a @ueue& which one will be removed first*
L >%
L 4
L '''
L (
&uestion 'o( 3 * +arks( ) , 9 Flease choose one


)uppose current=ode refers to a node in a linked list 0usin! the =ode class with member
variables called data and ne,t=ode1. hat statement chan!es current=ode so that it refers to the
ne,t node*
L currentNode NNY
L currentNode ` nextNodeY
L currentNode N` nextNodeY
L current'ode K current'ode9One7t'odeP
&uestion 'o( 4 * +arks( ) , 9 Flease choose one


- <ompound =ata 5tructure is the data structure which can ha2e multiple
data items of same type or of diBerent types. @hich of the following can be
considered compound data structure4
L -rrays
L $ink$ists
L Binary Search Trees
L -ll of the gi2en options
&uestion 'o( 5 * +arks( ) , 9 Flease choose one


Aere is a small function defnition1
void f(int i, int &k)
{
i = 1;
k = 2;
}
Suppose that a main program has two integer 2ariables x and y, which are gi2en
the 2alue ". Then the main program calls f(x,y); @hat are the 2alues of x and y
after the function f fnishes4
L ;oth x and y are still .
L x is now !, but y is still ".
L x is still ", but y is now '.
L x is now !, and y is now '.
&uestion 'o( 6 * +arks( ) , 9 Flease choose one


The diBerence between a binary tree and a binary search tree is that ,
L a binary search tree has two children per node whereas a binary tree can
ha2e none, one, or two children per node
L in binary search tree nodes are inserted based on the values they
contain
L in binary tree nodes are inserted based on the 2alues they contain
L none of these
&uestion 'o( - * +arks( ) , 9 Flease choose one


)ompiler uses which one of the following to e2aluate a mathematical euation,
L Binary Tree
L Binary Search Tree
L Farse 0ree
L -3& Tree
&uestion 'o( 8 * +arks( ) , 9 Flease choose one


If there are ($ internal nodes in a binary tree then how many external nodes this
binary tree will ha2e4
L (>
L ((
L ($
L 5-
&uestion 'o( 9 * +arks( ) , 9 Flease choose one


If there are '/ external nodes in a binary tree then what will be the no. of internal
nodes in this binary tree4
L '/
L 24
L '!
L ''
&uestion 'o( ). * +arks( ) , 9 Flease choose one


@hich of the following method is helpful in creating the heap at once4
L insert
L add
L update
L preculate*own
&uestion 'o( )) * +arks( ) , 9 Flease choose one


The defnition of Transiti2ity property is
L +or all element x member of S, x 6 x
L For all elements 7 and y, 7 2 y i% and only i% y 2 7
L +or all elements x, y and G, if x 6 y and y 6 G then x 6 G
L +or all elements w, x, y and G, if x 6 y and w 6 G then x 6 G
&uestion 'o( )2 * +arks( ) , 9 Flease choose one


- binary tree of N nodes has _______.
L &og!" N le2els
L $og2 ' levels
L N Z ' le2els
L N x ' le2els
&uestion 'o( )3 * +arks( ) , 9 Flease choose one


%f there are = elements in an arra4 then the number of ma,imum steps needed to find an element
usin! Binar4 )earch is 7777777 .
) =
) N
2
) =lo!;=
) lo!;=
&uestion 'o( )4 * +arks( ) , 9 Flease choose one


6onsider te followin! arra4
;5 >5 5 >; <0 >0 I
After the first pass of a particular al!orithm& the arra4 looks like
>F 5 >; ;5 >0 I <0
=ame the al!orithm used
) Ceap sort
) Se'ecti!n s!rt
) %nsertion sort
) Bubble sort
&uestion 'o( )5 * +arks( ) , 9 Flease choose one


If both pointers of the node in a binary tree are Nl&& then it will be aZan _______ .
L Inner node
L $ea% node
L 6oot node
L None of the gi2en options
&uestion 'o( )6 * +arks( ) , 9 Flease choose one


By using __________we a2oid the recursi2e method of tra2ersing a Tree, which ma7es
use of stac7s and consumes a lot of memory and time.
L Binary tree only
L 0hreaded binary tree
L Aeap data structure
L AuBman encoding
&uestion 'o( )- * +arks( ) , 9 Flease choose one


- complete binary tree of height 3 has between ________ nodes.
L % to !>
L % to !(
L 8 to )6
L % to !#
&uestion 'o( )8 * +arks( ) , 9 Flease choose one


)onsider a min heap, represented by the following array1
/,>,$,#,(,!"
-fter inserting a node with 2alue !.@hich of the following is the updated min heap4
L /,>,$,#,(,!",!
L /,>,$,#,(,!,!"
L /,>,!,(,#,!",$
L ),4,3,5,-,).,6
&uestion 'o( )9 * +arks( ) , 9 Flease choose one


)onsider a min heap, represented by the following array1
!",/",'",#",>",(",%",$"
-fter inserting a node with 2alue /!.@hich of the following is the updated min heap4
L ).,3.,2.,3),4.,5.,8.,6.,-.
L !",/",'",#",>",(",%",$",/!
L !",/!,'",/",>",(",%",$",/!
L /!,!",/",'",#",>",(",%",$"
&uestion 'o( 2. * +arks( ) , 9 Flease choose one


@hich one of the following algorithms is most widely used due to its good a2erage
time,
L Bubble Sort
L Insertion Sort
L &uick 5ort
L .erge Sort
&uestion 'o( 2) * +arks( ) , 9 Flease choose one


@hich of the following statement is correct about fnd8x; operation1
L " 8nd*7, on element 7 is per%ormed by returning e7actly the
same node that is %ound
L - fnd8x; on element x is performed by returning the root of the tree
containing x.
L - fnd8x; on element x is performed by returning the whole tree itself
containing x.
L - fnd8x; on element x is performed by returning T6lE.
&uestion 'o( 22 * +arks( ) , 9 Flease choose one


@hich of the following statement is NXT correct about fnd operation1
L It is not a reuirement that a fnd operation returns any specifc name, =ust
that fnds on two elements return the same answer if and only if they are in the
same set.
L Xne idea might be to use a tree to represent each set, since each element in
a tree has the same root, thus the root can be used to name the set.
L Initially each set contains one element.
L /nitially each set contains one element and it does not make sense
to make a tree o% one node only
&uestion 'o( 23 * +arks( ) , 9 Flease choose one


The followin! are statements related to @ueues.
0v1 The last item to be added to a @ueue is the first item to be removed
0vi1 A @ueue is a structure in which both ends are not used
0vii1 The last element hasnJt to wait until all elements precedin! it on the @ueue are
removed
0viii1 A @ueue is said to be a last$in$first$out list or #%F' data structure.
hich of the above isAare related to normal @ueues*
L 8iii; and 8ii; only
L 8i;, 8ii; and 8i2; only
L 8ii; and 8i2; only
L 'one o% the given options
&uestion 'o( 24 * +arks( ) , 9 Flease choose one


The maximum number of external nodes 8lea2es; for a binary tree of height A is
BBBBBBBBB
L 2
A
L '
A
N!
L '
A
?!
L '
A
N'
&uestion 'o( 25 * +arks( ) , 9 Flease choose one


In complete binary tree the bottom le2el is flled from ________
L $e%t to right
L 6ight to left
L Not flled at all
L None of the gi2en options
&uestion 'o( 26 * +arks( ) , 9 Flease choose one


@e are gi2en N items to build a heap , this can be done with _____ successi2e
inserts.
L N?!
L N
L 'E)
L Na'
&uestion 'o( 2- * +arks( ) , 9 Flease choose one


Suppose we had a hash table whose hash function is ~n F !', if the number /( is
already in the hash table, which of the following numbers would cause a collision4
L !>>
L )45
L !>/
L !>%
&uestion 'o( 28 * +arks( ) , 9 Flease choose one


Aere is an array of ten integers1
( / % : ! # " ' $ >
The array after the +I6ST iteration of the large loop in a selection sort 8sorting from
smallest to largest;.
L . 3 8 9 ) - 5 2 6 4
L ' $ > " / % : ! # (
L ' $ > : ! # " / % (
L " / % ' $ > : ! # (
&uestion 'o( 29 * +arks( ) , 9 Flease choose one


@hat reuirement is placed on an array, so that binary search may be used to
locate an entry4
L The array elements must form a heap.
L The array must ha2e at least ' entries.
L 0he array must be sorted
L The arrays siGe must be a power of two.
&uestion 'o( 3. * +arks( ) , 9 Flease choose one


In case of deleting a node from -3& tree, rotation could be prolong to the root node.
L Des
L No
&uestion 'o( 3) * +arks( ) ,


In merge sort do we need to ha2e extra memory, =ustify your answer in either
case.
-ns1
.erge sort reuires additional memory proportional to the siGe of the input
for scratch space, but, unli7e heap sort, merge sort is stable, meaning that
CeualC elements are ordered the same once sorting is complete
.erge sort wor7s using the principle that if you ha2e two sorted lists, you can
merge them together to form another sorted list. )onseuently, sorting a
large list can be thought of as a problem of sorting two smaller lists and then
merging those two lists together
&uestion 'o( 32 * +arks( ) ,


@here is Inorder 9redecessor of a non leaf node is present in a Binary Search
Tree4
-ns1
Inorder 9redecessor of a non leaf node is present at rightmost child of left
subtree present in a Binary Search Tree.
&uestion 'o( 33 * +arks( 2 ,


Aow we can search an element in S7ip &ist.
-ns1
s7ip list can be used as the underlying storage for a sorted set data structure. But,
s7ip list can be directly used to implement some operations that are not ehcient on
a typical sorted set1
+ind the element in the set that is closest to some gi2en 2alue, in X8log N;
time.
+ind the 7?th largest element in the set, in X8log N; time. 6euires a simple
augmentation of the the s7ip list with partial counts.
)ount the number of elements in the set whose 2alues fall into a gi2en range,
in X8log N; time. -lso reuires a simple augmentation of the s7ip list.
&uestion 'o( 34 * +arks( 2 ,


@hat is the drawbac7 of using arrays to store Binary Search Trees.
-ns1
@e used the binary search algorithm to fnd data stored in an array. This
method is 2ery eBecti2e as each iteration reduced the number of items to
search by one?half. Aowe2er since data was stored in an array insertions and
deletions were not ehcient. Binary search trees store data in nodes that are
lin7ed in a tree?li7e fashion. +or randomly inserted data search time is X8lg n;.
@orst?case beha2ior occurs when ordered data is inserted. In this case the
search time is X8n;.
&uestion 'o( 35 * +arks( 3 ,


)alculate the codes of the following characters in table below using the hoBman
encoding tree,
charact
er
code
N&
S9
o
b
i
r
"ns(
charac
ter
code
'$ )
5F 3
o 3
b 2
i 2
r 5
&uestion 'o( 36 * +arks( 3 ,


C+or smaller lists, linear insertion sort performs well, but for larger lists, uic7 sort is
suitable to apply.C Dustify why4
-ns1
Some di2ide?and?conuer algorithms such as uic7 sort and merge sort sort
by recursi2ely di2iding the list into smaller sublists which are then sorted.
- useful optimiGation in practice for these algorithms is to use insertion sort
for sorting small sublists, as insertion sort outperforms these more complex
algorithms. The siGe of list for which insertion sort has the ad2antage 2aries
by en2ironment and implementation, but is typically between eight and
twenty elements.
uic7sort is signifcantly faster in practice than other 8nlogn; algorithms,
because its inner loop can be ehciently implemented on most architectures,
and in most real?world data, it is possible to ma7e design choices which
minimiGe the probability of reuiring uadratic time. -dditionally, uic7sort
tends to ma7e excellent usage of the memory hierarchy, ta7ing perfect
ad2antage of 2irtual memory and a2ailable caches.
&uestion 'o( 3- * +arks( 3 ,


5uppose that we have implemented a priority 6ueue by storing the items
in a heap !e are now e7ecuting a reheapi8cation downward and the out9
o%9place node has priority o% 42 0he node:s parent has a priority o% -2, the
le%t child has priority 52 and the node:s right child has priority 62 !hich
statement best describes the status o% the reheapi8cation
" 0he reheapi8cation is done
; 0he ne7t step will swap the out9o%9place node with its parent
< 0he ne7t step will swap the out9o%9place node with its le%t child
= 0he ne7t step will swap the out9o%9place node with its right child
1 'one o% these
&uestion 'o( 38 * +arks( 5 ,


>ive two di?erent reasons to e7plain why the %ollowing binary tree is not a
heap(

The shape property1 the tree is a complete binary treeY that is, all le2els of the
tree, except possibly the last one 8deepest; are fully flled, and, if the last
le2el of the tree is not complete, the nodes of that le2el are flled from left to
right.8not satisfed here in it;
The heap property1 each node is greater than or eual to each of its children
according to some comparison predicate which is fxed for the entire data
structure. .8not satisfed here in it;
&uestion 'o( 39 * +arks( 5 ,


Aere is an array of ten integers1
( / % : ! # " ' $ >
Sort the array by using selection sort algorithm and show content of array after
each step.
"ns(
const int nSize = 10
int an!rra"#nSize$ = % ( ,/, %, :, !, # ,", ', $, >&

'' Ste( throu)h each ele*ent o+ the arra"
+or (int nStart,n-e. = 0 nStart,n-e. / nSize nStart,n-e.00)
%
'' nS*allest,n-e. is the in-e. o+ the s*allest
ele*ent
'' 1e23e encountere- so +ar4
int nS*allest,n-e. = nStart,n-e.

'' Search throu)h e3er" ele*ent startin) at
nStart,n-e.01
+or (int n5urrent,n-e. = nStart,n-e. 0 1 n5urrent,n-e. / nSize
n5urrent,n-e.00)
%
'' ,+ the current ele*ent is s*aller than our
(re3iousl" +oun- s*allest
i+ (an!rra"#n5urrent,n-e.$ / an!rra"#nS*allest,n-e.$)
'' Store the in-e. in nS*allest,n-e.
nS*allest,n-e. = n5urrent,n-e.
&

'' S1a( our start ele*ent 1ith our s*allest ele*ent
s1a((an!rra"#nStart,n-e.$6 an!rra"#nS*allest,n-e.$)
&
&uestion 'o( 4. * +arks( ). ,


" long se6uence o% vowels needs to be transmitted e@ciently so a
programmer decides to use Au?man encoding to encode the vowels "
distribution count study o% typical data yielded the %ollowing %re6uency
table
Fre6uency 0able
character %re6uency Au?man code
" 339-8 B B B B B B B
1 2.6-6 B B B B B B B
/ )58)4 B B B B B B B
4 2)552 B B B B B B B
C ).324 B B B B B B B
D 49-5 B B B B B B B
", <reate a Au?man tree to determine the binary codes %or each
character
;, Fill the codes into the table above
<, 1ncode the %ollowing se6uence 1/D4C"
"ns(
Table1 ?
character fre@uenc4 Cuffman 6ode
A 50FIF 00
- <5000 0>
% >>55; >>0
' ;58>< >0
D >05;< >>>0
< >:#( !!!!
AuBman Tree1 ?
&uestion 'o( 4) * +arks( ). ,


)onsider the following tree.
g; Show that either it is a heap or not.
h; If it is a heap then what type of heap is it4
i; -dd >" in the heap and con2ert it in max heap.
-ns
a; It is a heap tree as
specifying the conditions of
heap
b; .ax heap because the root
2alue is greater than its
children.
c;
FINALTERM EXAMINATION
Spring 2010
CS301- Data Structures

Time: 90 min
M a r k s: 58
CS301 Question No: 1 ( M a r k s: 1 )

Which one o the o!!o"ing operations returns top #a!ue o the stack$
%ush
o!
Top
&irst
CS301 Question No: " ( M a r k s: 1 )

Compi!er uses "hich one o the o!!o"ing in &unction ca!!s'
Stack
(ueue
#inar$ Sear%& Tree
)*+ Tree
CS301 Question No: 3 ( M a r k s: 1 )

,#er- )*+ is .................
/inar- Tree
Comp!ete /inar- Tree
0one o these
#inar$ Sear%& Tree

CS301 Question No: ' ( M a r k s: 1 )

1 there are 52 interna! no3es in a 4inar- tree then ho" man- e5terna! no3es this
4inar- tree "i!! ha#e$
56
55
52
()
CS301 Question No: ( ( M a r k s: 1 )

1 there are 23 e5terna! no3es in a 4inar- tree then "hat "i!! 4e the no7 o interna!
no3es in this 4inar- tree$
23
26
21
""
CS301 Question No: * ( M a r k s: 1 )

Which one o the o!!o"ing is not an e5amp!e o e8ui#a!ence re!ation$
,!ectrica! connecti#it-
Set o peop!e

Set o pi5e!s

CS301 Question No: ) ( M a r k s: 1 )

/inar- Search is an a!gorithm o searching' use3 "ith the ...... 3ata7
Sorte+
9nsorte3
:eterogeneous
;an3om
CS301 Question No: , ( M a r k s: 1 )

Which one o the o!!o"ing is 0<T true regar3ing the skip !ist$
,ach !ist Si contains the specia! ke-s = ininit- an3 - ininit-7
+ist S0 contains the ke-s o S in non-3ecreasing or3er7
,ach !ist is a su4se8uence o the pre#ious one7
List S& %ontains on-$ t&e n s!e%ia- ke$s.
CS301 Question No: / ( M a r k s: 1 )

) simp!e sorting a!gorithm !ike se!ection sort or 4u44!e sort has a "orst-case o
<>1? time 4ecause a!! !ists take the same amount o time to sort
<>n? time 4ecause it has to perorm n s"aps to or3er the !ist7
O(n
"
) ti0e 1e%ause sortin2 1 e-e0ent takes O(n) ti0e 3 A4ter 1 !ass
t&rou2& t&e -ist5
eit&er o4 t&ese a-2orit&0s %an 2uarantee t&at 1 e-e0ent is sorte+.
<>n
3
? time' 4ecause the "orst case has rea!!- ran3om input "hich takes !onger
to
sort7

CS301 Question No: 10 ( M a r k s: 1 )

Which o the o!!o"ing is a propert- o 4inar- tree$
) 4inar- tree o 0 e5terna! no3es has 0 interna! no3e7
A 1inar$ tree o4 N interna- no+es &as N6 1 e7terna- no+e.
) 4inar- tree o 0 e5terna! no3es has 0= 1 interna! no3e7
) 4inar- tree o 0 interna! no3es has 0- 1 e5terna! no3e7
CS301 Question No: 11 ( M a r k s: 1 )

/- using .........."e a#oi3 the recursi#e metho3 o tra#ersing a Tree' "hich makes
use o stacks an3 consumes a !ot o memor- an3 time7
/inar- tree on!-
T&rea+e+ 1inar$ tree
:eap 3ata structure
:uman enco3ing
CS301 Question No: 1" ( M a r k s: 1 )

Which o the o!!o"ing statement is true a4out 3umm- no3e o threa3e3 4inar- tree$
This 3umm- no3e ne#er has a #a!ue7
This 3umm- no3e has a!"a-s some 3umm- #a!ue7
T&is +u00$ no+e &as eit&er no 8a-ue or so0e +u00$ 8a-ue.
This 3umm- no3e has a!"a-s some integer #a!ue7


CS301 Question No: 13 ( M a r k s: 1 )

&or a perect 4inar- tree o height h' ha#ing 0 no3es' the sum o heights o no3es is
0 @ >h @ 1?
N 9 (& 6 1)
0 @ 1
0 @ 1 = h
CS301 Question No: 1' ( M a r k s: 1 ) 3 -ease %&oose 8u :s one

What is the 4est 3einition o a collision in a hash ta4!e$
T"o entries are i3entica! e5cept or their ke-s7
T;o entries ;it& +i44erent +ata &a8e t&e e7a%t sa0e ke$
T"o entries "ith 3ierent ke-s ha#e the same e5act hash #a!ue7
T"o entries "ith the e5act same ke- ha#e 3ierent hash #a!ues7
CS301 Question No: 1( ( M a r k s: 1 )

Which ormu!a is the 4est appro5imation or the 3epth o a heap "ith n no3es$
-o2 (1ase ") o4 n
The num4er o 3igits in n >4ase 10?' e7g7' 165 has three 3igits
The s8uare root o n
n

CS301 Question No: 1* ( M a r k s: 1 )

Which o the o!!o"ing statement is 0<T correct a4out in3 operation:
1t is not a re8uirement that a in3 operation returns an- speciic name' Aust
that in3s on t"o e!ements return the same ans"er i an3 on!- i the- are in the same
set7
<ne i3ea might 4e to use a tree to represent each set' since each e!ement in a
tree has the same root' thus the root can 4e use3 to name the set7
1nitia!!- each set contains one e!ement7
Initia--$ ea%& set %ontains one e-e0ent an+ it +oes not 0ake sense to
0ake a tree o4 one no+e on-$.
CS301 Question No: 1) ( M a r k s: 1 )

Which o the o!!o"ing is not true regar3ing the maBe generation$
;an3om!- remo#e "a!!s unti! the entrance an3 e5it ce!!s are in the same set7
;emo#ing a "a!! is the same as 3oing a union operation7
Re0o8e a ran+o0-$ %&osen ;a-- i4 t&e %e--s it se!arates are a-rea+$ in
t&e sa0e set.
Do not remo#e a ran3om!- chosen "a!! i the ce!!s it separates are a!rea3- in
the same set7
CS301 Question No: 1, ( M a r k s: 1 )

1n threa3e3 4inar- tree the 09++ pointers are rep!ace3 4- '
preor3er successor or pre3ecessor
inor+er su%%essor or !re+e%essor
postor3er successor or pre3ecessor
09++ pointers are not rep!ace3

CS301 Question No: 1/ ( M a r k s: 1 )

Which o the gi#en option is 0<T a actor in 9nion 4- SiBe:
Maintain siBes >num4er o no3es? o a!! trees' an3 3uring union7
Make sma!!er tree' the su4tree o the !arger one7
Make t&e -ar2er tree5 t&e su1tree o4 t&e s0a--er one.
1mp!ementation: or each root no3e i' instea3 o setting parentCiD to -1' set it to
-k i tree roote3 at i has k no3es7
CS301 Question No: "0 ( M a r k s: 1 )

Suppose "e ha3 a hash ta4!e "hose hash unction is En F 12G' i the num4er 35 is
a!rea3- in the hash ta4!e' "hich o the o!!o"ing num4ers "ou!3 cause a co!!ision$
166
165
1'3
168
CS301 Question No: "1 ( M a r k s: 1 )

What re8uirement is p!ace3 on an arra-' so that binary search ma- 4e use3 to !ocate an
entr-$
The arra- e!ements must orm a heap7
The arra- must ha#e at !east 2 entries7
T&e arra$ 0ust 1e sorte+7
The arra-Hs siBe must 4e a po"er o t"o7
CS301 Question No: "" ( M a r k s: 1 )

) 4inar- tree "ith 26 interna! no3es has ...... e5terna! no3es7
22
23
68
"(
CS301 Question No: "3 ( M a r k s: 1 )

1n case o 3e!eting a no3e rom )*+ tree' rotation cou!3 4e pro!ong to the root no3e7
<es
0o

CS301 Question No: "' ( M a r k s: 1 )

;&en ;e &a8e +e%-are+ t&e si:e o4 t&e arra$5 it is not !ossi1-e to in%rease or
+e%rease it +urin2 t&e ========o4 t&e !ro2ra0.
Dec!aration
E7e%ution
Deining
0one o the a4o#e
CS301 Question No: "( ( M a r k s: 1 )

it ;i-- 1e e44i%ient to !-a%e sta%k e-e0ents at t&e start o4 t&e -ist 1e%ause
insertion an+ re0o8a- take =======ti0e.
*aria4!e
Constant
1nconsistent
0one o the a4o#e
CS301 Question No: "* ( M a r k s: 1 )

_______ is t&e sta%k %&ara%teristi% 1ut =======;as i0!-e0ente+ 1e%ause o4
t&e si:e -i0itation o4 t&e arra$.
is&u!!>?'is,mpt->?
pop>?' push>?
isE0!t$() 5 isFu--()
push>?'pop>?
CS301 Question No: ") ( M a r k s: " )

Ii#e the 3ierence 4et"een strict an3 comp!ete 4inar- tree7
)ns:
) tree is a strict!- 4inar- tree i its each !ea no3e has non-empt- !et an3 right su4
trees' an3
1 there are !et an3 right su4-trees or each no3e in a 4inar- tree is kno"n as comp!ete
4inar- tree7
CS301 Question No: ", ( M a r k s: " )

) comp!ete 4inar- tree can 4e store3 in an arra-7 Whi!e storing the tree in an arra-
"e !ea#e the irst position >0th in3e5 ?o the arra- empt-7 Wh-$
)ns
/ecause "e nee3 a pointer in an arra- to point a position o no3e o tree7 parent no3e
an3 the chi!3ren no3es7 1n case o ha#ing a no3e "ith !et an3 right chi!3ren' store3
at position i in the arra-' the !et 2i an3 the right chi!3 "i!! 4e at 2i=1 position7 1 the
#a!ue o i 2' the parent "i!! 4e at position 2 an3 the !et chi!3 "i!! 4e at position 2i i7e7 6
7The right chi!3 "i!! 4e at position 2i=1 i7e7 57 "e ha#e not starte3 the 0
th
position7 1t is
simp!- 3ue to the act i the position is 0' 2i "i!! a!so
4ecome 07 So "e "i!! start rom the 1
st
position' ignoring the 0
th
7

CS301 Question No: "/ ( M a r k s: " )

Ii#e the name o t"o Di#i3e an3 Con8uer a!gorithms7
)ns:
17 Merge sort
27 (uick sort
37 :eap sort
CS301 Question No: 30 ( M a r k s: " )

Ii#e the eect o sorte3 3ata on /inar- Search7
CS301 Question No: 31 ( M a r k s: 3 )

Ii#e an- three characteristics o 9nion 4- Weight metho37
)ns:
17 This is a!so ca!!es union 4- siBe7
27 Maintain siBes >num4er o no3es? o a!! trees' an3 3uring union7
37 Make sma!!er tree' the su4tree o the !arger one7
67 or each root no3e i' instea3 o setting parentCiD to -1' set it
to -k i tree roote3 at i has k no3es7
CS301 Question No: 3" ( M a r k s: 3 )

>ere is an arra$ o4 ten inte2ers:
( 3 , / 1 ) 0 " * '
?ra; t&is arra$ a4ter t&e FIRST iteration o4 t&e -ar2e -oo! in an insertion sort
(sortin2 4ro0 s0a--est to -ar2est). T&is iteration &as s&i4te+ at -east one ite0
in t&e arra$@
CS301 Question No: 33 ( M a r k s: 3 )

Ii#e -our comment on the statement that heap uses !east memor- in arra-
representation o 4inar- trees7 Justi- -our ans"er in either case7

CS301 Question No: 3( ( M a r k s: ( )

,5p!ain the o!!o"ing terms:
17 Co!!ision
27 +inear %ro4ing
37 (ua3ratic %ro4ing
Ans:
Co--ision:
it takes p!ace "hen t"o or more ke-s >3ata items? pro3uce the same in3e57
Linear ro1in2
"hen there is a co!!ision' some other !ocation in the arra- is oun37 This is kno"n as
!inear pro4ing7 1n !inear pro4ing' at the time o co!!isions' "e a33 one to the in3e5 an3
check that !ocation7 1 it is a!so not empt-' "e a33 2 an3 check that position7 Suppose
"e keep on incrementing the arra- in3e5 an3 reach at the en3 o the ta4!e7 We "ere
una4!e to in3 the space an3 reache3 the !ast !ocation o the arra-7
Qua+rati% ro1in2
1n the 8ua3ratic pro4ing "hen a co!!ision happens "e tr- to in3 the empt- !ocation at
in3e5 = 127 1 it is i!!e3 then "e a33 22 an3 so on7
(ua3ratic pro4ing uses 3ierent ormu!a:
!. 9se &>i? K i
2
>s8uare o i? to reso!#e co!!isions
27 1 hash unction reso!#es to : an3 a search in ce!! : is inconc!usi#e' tr-
: = 1
2
' : = 22' : = 32
CS301 Question No: 3* ( M a r k s: ( )

:ere is an arra- "ith e5act!- 15 e!ements:
1 2 3 6 5 2 L 8 9 10 11 12 13 16 157
Suppose that "e are 3oing a 4inar- search or an e!ement7 1n3icate an- e!ements that
"i!! 4e oun3 4- e5amining t"o or e"er num4ers rom the arra-7