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  Ater 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( ,ierent ,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 eicient 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&ismpt401
) pop01& push01
) isE6pt<#% ? isFu''#%
) push01&pop01
uesti!n N!" 23 # Mar$s" 2 %
FiAe t(e ,ierence 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!ne6pt< 'et an, rig(t su7 trees? an,
I t(ere are 'et an, rig(t su7trees !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( 'et an, rig(t c(i',ren? st!re, at p!siti!n i in t(e
arra<? t(e 'et 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 'et 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< ater 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(ite, 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
,ierence 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(eapiicati!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 'et 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(eapiicati!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.! ,ierent 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, eicient'< s! a pr!gra66er ,eci,es t! use
Gu6an 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< Gu6an 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 Gu6an 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.
) Let t(rea, ! t(e rig(t6!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 #n1 '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:
N1 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: Ater
!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 riht sub trees occur+
#edraw the given tree and write balance of it. $
Chapter " 1. /ae no 00
A code was given and we have to tell what the recursive function is doing. %
/ae " 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. pae 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
/ae no 0 71 chapter no 0
iii1 Insert &$ in following A/0 tree
/ae 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 danlin 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 pae 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 ,ierent p!ints
1% T(e (eig(t ! 'et 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#erene %ariable x that re#erred to y !ointer itsel# these are not the
atual ob"ets themsel%es
&b'. int x(
int +y * x(
.he y is re#erene %ariable re#erenin$ 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: Ater
!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
" 3398 B B B B B B B
1 2.66 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 495 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 ini8 !r6 t! p!sti8 !r6:
A9;TCDOEF
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 ,ierent 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 ! Win,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)D6C7VN
" /(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< ater 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 prei8 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 ater 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 reerence 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 re7a'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 re7a'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 reerence 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 +DD 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 < 01 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 ater 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 reerence 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 re7a'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 re7a'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 reerence 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 +DD 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 < 01 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