Sie sind auf Seite 1von 41

L MNIIE

r.. r,.:r
EtrSg
..
^-:--:,: -

Fuhlications

:car"ffi
a-,

rr)N
a)1
r/

WORKBOOK
I
l
xElA pue uryl 6u p,
=o
uos olqq-; .
qcleos fue. ! .
tlt
suorslonul 6ur1unc3 .
6urqcreeg qdetg . ]los uOlUeS- .
sqderg jo suotleluaserdeg . Uog e6,e, . .
suql;ro61y paseg qderg : 9 raldeql uorlncrldrl;ny1xulen S uoSSErlS .
qde;g eOeisrl;ny1 . uos )lcinc .
Luolqord lcesdeuy L/O oLlI . renbuo3 pue ep!^!O : g ,raldeq1
LrJolqord ecuanbesqnS Uoululoo lseOuol . LUe.rooql JolsB[r, .
uorlecr;dr11n4 uleqCxule/\ . poqlaW uorlnlllsq'S .
LUolqoid srllEd lsouoqs s]led-llv . suollplau a)uarrn)au : 7 laldeq;
SloqLUnN lcceuoqll .
sleruou{1o6 }o.,tnorneqoB cr}o}druAsl .
6uluer6or6 rgueut(q : gleldeq1 suollcunl io suosuedr_uo3 .
0urpo3 ueLU#nH . sdoo-1 19 srsAleuy .
LUalqoJd rlled lsopol1s ocrnos a10urg . suorleloN crlolduAsy .
uralqord ae4 Ouruuedg lso3 u,tnultuty\ . soseC ]sog pup e6eteny ]sloA,, .
LUolqord(1euor1cer3)>lcesdeuy . srs{1euy ocueLrJlolrad rol poeN .
sanbluqral (paarg : y,ra1deq1 surrlllro6lv 1o slsf;euy >;1oldru(sy : 1 ,ra1deql
reells uolldlrlsao
6uluJurer6or6 A ernpnJls EIgO ,utrlllro6lV
Chapter 1 : Programming Methodology . Circular Queue
. Data Segments in Memory . lmplement Queue using Stacks
r Scope of Variable ' Types of Queue
o C Variable o Double Ended Queue
o Address arithmetic in C o Priority Queue
. Value of Variable in C Language Chapter5:LinkedLists
o Flow Control in C . Linked Lists
r Function o Uses of Linked lists
. Recursion . Singly Linked List or One Way Chain
. Backtracking r Doubly Linked Lists or Two-way chain
o C Scope Rules . Linked List lmplementation of Queues
. Storage Class r Linked List lmplementation of Stacks
. Pointers . Linked List lmplementation of Priority Queues
o Declarations and Notations o Other operation on Linked List
Chapter 2 : Arrays Chapter 6 : Trees
o Definition of Array . Tree Traversals for Forests
o Properties of Array r Binary Trees
. Accessing Elements of an Array . Types of Binary Trees
Chapter !i : Stack . Applications of Binary Tree
. Operation on Stack . Binary Tree Representations
o ADT of Stack o Binary Search Tree
. Operations of Stack . AVL Tree
. Applications of Stack Chapter 7 : Hashing Techniques
o Evaluation of'an lnfix o lntroduction
. Evaluation of Prefix Expression . Hash Function
o Postfix Evaluation o Collisions
o lnfix to Postfix Conversion o Collision Resolution Techniques
. lmplement Stack using Queues o Hashing Function
. Tower of Hanoi . Comparison of Collision Resolution Techniques
Chapter 4 : Queue o Various Hash Function
. Operations of Queue
. Application of Queue
lq6trldof a
leooz-oouol
(p) enenp (c) lc
leooz-oouol
tsrr
orcz Aq uotst^tc (p) ssacce lotutod -'. :
tcers (q) Aely (e)
I'e
lo Mollro^o)cElS (q) spunoq 1o 1no Ae." - :
e ut pajols suroltelep polopjo
t3
lo ]os e uo lno paurec oq uec L1cJeos fueurg 6.0 le
0ursrncel e ut uotltpuoc Ourleuruure] ]c e: -:: l; ;I
leooz-oouol lE
ll
pos uorpasul (p) yos e6rep (c) ta lgooz-=rvel
(q)
Pos>1ctnp Uosdeag (e) IE
It 6(p) 3:
ieLul (u)g urecuenbes ,(q) ::
or.l] lios uec Ourmollol oLl] lo qclLlg lopro t.q
IE s .{ --l_
1o 1no sreadde leqt [!o]t ouo rol ldacxe poyos ue uo d olenJeno o] popoou suolieo c..* -:
IE
sr qctqM u q16ue1 1o y ecuenbos e roptsuoC g.O ll roquJnu ulnLUrurLU oql'lA 'g *ie areu,,,' .'lE -
t;
lflo
leooz-ooucl l!
lo
yos eOrey1 (p) pos elqqng (c) t9o [rcoz-:=nNn]
pos uorpesul (q) posdeeg (e) n lerlueuodxe (p) JEOU ,l
e
E cuerpenb (q) ciLrql teOc Z
auotlect;dde
ex jo uotlcunl e se (x)11o qivc_-
tenbuoc puB optntp sr 0urano;;o1 oLl] lo r-.lctqM /.O 3o
E aL{} saqucsap isoq Llclr.lm '0urntol1o; eur
lsool-Ervs] 9
::
di i
(u 6o1+
u 6o1)6 (p) (u + ru)6 (c) ol
ol :Qlx)O + (t - x)l urnlol asto
(u)o (q) (u)o (e)
:L urnlar (Z > x) lt )
1o suosrredu.roc
porrnber oA 'u + uJ ozts ,to ]stl pouos E olut ?l
=l
9t (x 1ur) 0 1ur
u pue LU sozts lo slstl pol.los orrq 6ur0teut to3 g.o {
EI
EI
ol :(x)0 + (l _ x)l u]nlor osle
(zu)o (p) (u 6o1u)6 (c) EI :f urntor (l > x) ll )
(u)o (q) (u 0o1)9 (e) ;l (x 1ur)i 1u
<t
UI
[remsue ul :apoc C Ourmo1;o1eLl].reprsuoC e C
iseg] ;{erre uenr0 eq1 ut }ou Jo }stxo luotuolo
3t
{luofeu eql Jorllorll lcorlc o1 ftrxe;duuoc yos uorpesul (p) yos xrpeg (c)
ourl oq] sl le[]M 'Aetrc ue ]o suorlrsod
;l pos lcrnp (q) pos e0ra61 (e)
7 EI ieurl (u)g 6ulsn pepos oq lllm leu ..Ll eOuet eL,:
,",.1,
olot! ut pollncoo s! ll ll ,,,lueulole .9. I
i ul sluotrlala-u 1o Aele ue utqiuoOle qcrqm 6urs1
EI
t-l
ftr:ofeu,, eq o] ptES st luoulelo uy o1 ;enbe .u
Jo ueql ssol st Aetrc ue lo luotuolo fiene pue bl suolls3no 3floqf 3ldlllnru
'sluoruolo-u seq [u'"' 'f] V Aete ue ounssv g.O 3t
renbuol pue ep!^!o
,C*mputerScience&lT*&lg*ritltnn,Datastrueture&Prograntrll!irrg
MNTIE EHSH
fi {}!-il: }i*&ti#*$

Q.10 The minimum number of comparisons requtred


lil
to sort 5 elements is
(a) ,-1 (b) l;lz) I

(a)4 (b) 5
(d) 7
Io til (r+1)
,.$t- (c)6 _
lS
l!
(c)
lz I
(d)
,
tDRDo-20081
l< IGATE-2001]
Q.11 The worst case time complexity of Quicksort I p
Q.16 The usual O(n2) implementation of insertion sort
for n elements when the median is selected as lfr
to sort an array uses linear search to identify
the pivot is: I;
the position where an element is to be inserted
(a) o(n2) (b) o(n2) lg
los n) I ? into the already sorted part of the array lf'
(c) O(n log n) (d) u(n
o(n rog I instead, we use binary search to identify the
IDRDO-20081 l6
=
position, the worst case running time will
Q.1 2 The mostappropriate matching forthetottowinO I
I (a) remain @(n2)
pairs: IH
(b) become @(n (log n)2)
X : Depth first search HeaP I
1:g (c) become O(n log n)
Y:Breadth-firstsearch 2:Queue l;l- (d) become @(n)
Z:Sorting 3:Stack IGATE-20031
(a) X-1 ,Y-2,2-3 (b) X-3, Y'1,2-2 l:o
7 Let A be a sequence of B distinct integers sorted
(c) X-3, Y-2,2-1 (d) X-2, Y-3,2-1 I 3
o Q.1
in ascending order. How many distinct pairs of
tGArE-20001 l5n
D
sequences, B and C are there such that (i) each
Q.13 Consider the following algorithm for searching | 3 is sorted in ascending order, (ii) B has 5 and C
for a given number x in an unsorted array A[l n] i | has 3 elements, and (iii)the result of merging B
having n distinct values: IH and C gives A?
1. Choose an i uniformly at random from l"nl I i (a) 2 (b) 30
2. "r'r = x then StoP else Goto
lf" AUI 1; l:Ig (c) 56 (d) 256
Assumrng that x is present A, what is the I a IGATE-2oo3l
expected number of comparisons made by the lE
algorrthm before it terminates,
, r -^ I r
U
Q.18 A sort method is said to be stable if the relative
(a) n (b) n-, ,t order of keys is the same after the sort as it
I-
(c) 2n @) nl2 '
l=
was before the sort. ln which of the following
pairs both sorting algorithms are stable?
tcArE-2oo2l lg
-' (a) Quick-sort and lnsertion-sort
Q.14 Randomized quicksort is an extension of li (b) lnsertion-sort and Bubble-sort
quicksort where the pivot is chosen randomlV l { (c) Quick-sort and HeaP-sort
What is the worst case complexity of sorting n |l+= (d) Quick-sort and Bubble-sort
numbers using randomized quicksort? I
g
(b) o(n los n) IDRDO-200e1
(a) o(n) I ;
(c) o(n2) (d) o(nl) I-i O,19 ln a heap with n elements with the smallest
tGArE-2oo1l lg element at the root, the 7th smallest element can
be found in time
Q.15 Consider any array representation ot un n l3 (a) @(n log n) (b) o(n)
element binary heap where the elements are | 3 (d) o(1)
n of the array For
(c) o(log n)
sorted from index 1 to index
< IGATE-20031
the element sorted at index i of the array (l n),
the index of the Parent is

mlnffiH EHsllj
l:liri;i ii;i, j f i':.' ! :
- """"-" " '
.'. . "t-" ,,
6ro''irio;rej; lqnddieSSpeu'nnnnm &q*%s"B,.,* dE &ffiE&E t
ldeau ]uellnser aq1 0urlueseider fueLre
or"ll ur sLriolr 1o ecuanbes oqi sr Ournnollol eq1 lzooz-=rvgl le
io ouo qclqM 0t O 'uortsonb oqt ur punol deeq z ,-,
([J]
o
xeu ,4;e-g prle^ oLll olur iepro leq] ul 'pepiosul (u)(L + u)
,9
t
ore , pue 'OL 'Z'1 sluourole eql asoddns 6Z'0 o (q)
a
L - =' ulu UE
o lf
Isooz-:rvc] ,- tca
sr sdool +los lnoll]r\' ; ;. . .. .
r '0'8'9'9'6 (p) r 'e B'e e '6 (c) o
E'B'L'r'9'6 (q) 6'B 9'e r'r (e) - Io
o
c
6deeq : leooz-=rve l
=
E
xELLI Ourlirosatde t Aetrc uE ui slueuolo +o z-)j-u (p)
o
^re-t prle^
ecuenbes E sr 0ur,u.o11oi oq] +o ouo
qclqM BZ'D (q)
C l-u
d
.=
'Auado;d deoLl oLtri Alsrles ol aol] ! sl talauM lrr1tf -,-I = --
@
au11dn 11 0t-:rqsnci pue Iu] e uolleOol eqi ut x 0urcegd Aq .2
f
; uoql slueixele s==-- 6u
sllroli u Durureluoc deeq fue-g e oiut pouosut sq uec x o
]curlsip - -:
no qcreos {;eurq luoro}}ip }o iaqLlrru 3-t
s. - _ -:- ]l
Luolr uV premuo uorleool [y] e Luorl pelo]s ere 1qOr.r o1 O
l an
i+al LUar+ oojl aqi 10 lo^al puocos oqi uor} sspou oql I
c
'[e] e ot o lgoo l-=rvgl
Ii-] e uo;l pero]s sr '1q0u ot Uol ruo.t+ 'lo^ol ]xau o le
o
c.H
AV
c1
OF
00
JJ Li
oul ul sapou [g] e 'uoilecol ]sr4 oq] ut po.ro]s sr ]ool !
6 w lv vl z9 19 -?:
oLjl .sr olio] se {erLe ue {q poluosorder eq uec deoq E
Ate-g y uraplrqc t oneq sepou uelpltqc Z lo pEalsut c tb /t, Bn r0 a,_ -
ao 7- l
1nq 'deeq xeLl i(reurq e o)ltl sr deeq xeu A.re-g y .9 ti 09 0v 09 a g
E
6Z O 3 8Z'D roi EIPC uor.xuroc C w 0v Ll rt a9 -?. 3
o 1,]OU e.]E LIC t1A1 pue -' C SS: l
a rl
osoqt+o euo51 (p) (u)o (c) o
z are secuenbes eqord 0uru,to11o1 oql ]o utr ,',' .;
(u CIo1)9 (q) (r)o (e) _i lo
! vv-
o
loqunu oq] olecol o] pasn s oe]l ucrBas ' ,2 - ) ; p
1f',etn uorufi oq] lo ]uelr-lolo o
0
=
olpp!r_u pui, oi ol€1 llrM ji oLlltl qcnLU MoH ]sullstp Z Izooz-:rve ] le
7lc ^
6 (p)
pue sluorlrolo-u io qcee si{e:te pol-los-z uol.te /z'o L u " 'bor
c
'a
o t/t6o;
u (q)
,9
loooz-ocucl !
l
tcl 0_
l:l (p) [1.] r"r U)
Aq peqrrcsap ]seq sr sopou . -c a=.- :- - - -
LU] LU] Lr-l
1o (1ee; lsoqpnl ell] ol joor oq] L-Lc,- --:r =-.-
Ll-.1
r u(q) u (e) o uo sopou reqiunu)
io lqOloq otqrsscl ---*., :,-. O
asosriiaA u o eq1 oea qns 1q6r.r eLli u
sopoi- -. ....-..- . ']l
1o qderO elelduuoc e ur soar] 0uiuueds lurolsrp I oLl] ocr^^] lsorlr ]p pue +leq ]seel le s ::_- _-: p
d
eOpa 1o roqLunu oLll uo punoq reddn or,li sl iBqM ge'O E
O
uol oq] ur sopou +o ./oqunu aqi apc- -:2= , _. {i
o
!- LlcrqM ur eerl i{reurq e sr
ooll pesup e:-- -: = . .Z i ]-i
f
lsooz-ocuol (n
t '9 'B 'Zt'SL'0t (p) ;
I Ioooz-ocua]
,9 Ir
0L 'q '0 'B 'zL '9r (3) (r)o (p) (zu)E F
o
o
(-) (u)o (q) (u 6o1u)6 (e
t,'zt'01 's '8 '9t (q)
o :-.- -
9'r'B'Zt'CL'91 (e)
;,{padord deoq ur pelnduoc oq uBc Aeye ue Iq pe--:.=.--
-xeLr-r poryS;les s{e;re 0urmo1lo; eq} }o euo ,.lolqM gZ'C dee q -xe u.r € Ui }UOLUAIS iUl-l LLI u ,-. = _ -a:
f "*.,"".,"".-**-*,",,
d $ ry**q-,i.i*4,4
ffiE$ffi= 3trUlu F
_fn
Itttl'<
L3/
flr <ef €,#r f,fu con!4z€ts ti"-01_
lT I Algorithm, Data structr*" dPtograrnming ffiRIIE FIfS*l
I Computer Science &
"w$3*biic*ti***

(a) 10, 7, 9, 8, 3, 1, 5, 2,6, 4 Q.35 Consider the following functions


(b) 10, e,8,7,6, 5, 4, 3,2,1 f(n) = 3n'fi g(n) = 2'litos2n
(c) 10, 9, 4, 5, 7,6,8,2, 1,3 h(n)= Pt
(d) 10, 8, 6, e, 7, 2,3, 4, 1, 5 Which of the following rs true?
IGATE-20061 (a) h(n) is o(f(n)) (b) h(n) is o(s(n))
(c) g(n) is not o(f(n)) (d) f(n) is O(s(n))
Q.30 The height of a binary tree is the maximum IGATE-2000I
number of edges in any root to leaf path. The
maximum number of nodes in a binary tree of Q.36 Let the kth Fibonacci number wtth
Fo denote

height h is Fx= Fx-, + Ft- rIork' 2'Fo- F, = 1


(a) 2h- 1 (b) zh- t -1 Consider the following variation of an merge sort,
ic) 2h +t -1 (d) 2r'*t which assumes that the number o{ elements in
IGATE-2Oo7l its list argument L is a Fibonacci number Fn
l;l
lc Al gorithm FibMergeSort(L)
Q.31 The maximum number of binary trees that can
I
16l

be formed with three unlabeled nodes is


L is a list of items from a totally ordered
(a) 1 (b) 5 set,whose length is a Fibonacci number Fo.

(c) 4 (d) 3 {
lf L contains only 1 element, then return L;
IGArE-20071
else
Q.32 Consider the following three claim t
1 ' (n+k)m = @(nm)where k and m are constants divide L into L, (the first Fo-, items) and
2. 2n* 1= O(2n) L, (the remaining Fo-, items)
3.22n*t=O(2n) sorted L, := FibMergeSorte(L,)
Which of these claim are correct? sorted L2 := FibMergeSort (Lr)
(b) 1 and 3 l4
(a) 1 and 2 sorted L := Merge(sortedL.,, sortedLr)
(c) 2 and 3 (d) 1, 2 and 3 return sortedL;
IGATE-20031 )
IE
)
Q.33 Find the running time of the following algoriihm.
Assuming that the "divide" step in FibMergeSorl
procedure A(n)
takes constant time (no comparisons) and Merge
lfn<=2return(1);
behaves similar to the merge in the normal
erse return (^(tJnl)) merge sort. ldentify which of the following
(a) o(n) (b) O(los n) expfressions most closely matches the total
(c) O(log log n) (d) o(1) number of comparisons performed by
FibMergeSort when initially given a list of Fo
IGATE-2oo2l
elements?
Q.34 Let f(n) = pz log n and g(n) = n(log n)10 be two (a) O(k log k) (b) o(K2)
positive functtons of n. Which of the following (c) o(k Fn) (d) O(Fo log k)
statements is correct?
(a) f(n) = o(g(n) and g(n)+ o(f(n)) Q.37 lf Tr = O(1), match List-l with List-ll select the
(b) g(n) = o(f(n) and f(n)+ o(g(n)) correct answer using the codes given below the
(c) f(n)* O(g(n)) and s(n)+ O(f(n)) Lists:
(d) f(n) = o(g(n)) and s(n) = o(f(n))
IGATE-20011

MTTIIE ERSTT A,eopltright


ffi I3u*ii*aii**s
q!iO!IP3rifl,!;
i"-.,:.' .: :, :ii.-:- :-t / ..:: ::: ir,r::r :.::.
'--- -- -.T--il | : a r a :
rq6;ddo;6 i lq
FiStr=I 30riu
[rcoe-:rve]
elrur (p) zirur (c)
lzool-rrvsl
c2 L
zuu (Q) Lu 6o1 (e) i
.o IZ , '(p
t(cl oql
:(x) luud ,@
E ZI , t (or oq]
{ o
o tt , z@)
:x/LLl=A c
o 8V
I
:7 1(A+x) =x
oc
a :sepoc
o
) c
renbuoc pue optntC '?
(= < ,( - x) alrqnn - ,:,
co 0utLlu,tetOotd ctuleuA6' g
.=
lL = A
= qtdeC 'Z
Llcreos lsrrf Iq
E
iLU=x o {peerg '1.
'(0< >'l-<uleunssy) IE}C
c
6 il1s!-t our
eilO .=
ieleu"rrxordde u.rqluoOle 0urmo1lol oq] soop leqM ! slueuodu.toc polcouuoC'C
o leL
.a eerlDuruueds lq6tem ulnutut[\ 'C
leooz-::nNnl l
eO
]ios lclno 'E
(zu)o (P) (u 6o1u)6 (c) o uo
co sqled lseuoqs stted llV 'V
(u)o (q) (znu)o (e) O
f
! t-lsn
o
auorleiou o- eq1 Outsn JoA Sue
o
:slsrl oL{} A olaq uentO sepoc
O-Olq ut u.rq1rro6le oi-lt jo Iltxelduuoc eqt st
o
! ]coroc aql l3olos ll-lsll qllM l-ls!''l qclel\ 6g o
]erlM 'spuocasrllrur 8t0z s! ourr] unr aql ?889 L
sr u ]l spuocasrllrrx zL9 s! our] unr eL.ll '960, loooz-=rvgI
t 7'\,
sr ull u ozrs lo lndur uant0 e sunr uqluo6ge uV Z7O 3
]" -(u-
\U,
osotll lo euo51 (p) (, .u",u)o = (r) r (c)
(7 \ pu
l" lr(u)t>r'0o, - :
(q) (uzool)o = (u)1 (e) \U,i
(r.u",,)o(u)r ,;
u z6o1 u > (u)l > i:
eonr] sr luaulolels 0urmollol oLll lo LlcttlA MoN (l)O si (u): rz :l
aon.l] sl sluoLr-lelels 0ut,^,,c a-
Z<u )o+,UEL + ktu)tt) all] lo L]c!t]M s u! 0001 uBt.l] SSol LUr-rS u:','
' ,, - f =(u)t
f=ulo](f)l ) slueurolo oM] are aroLlllr poulL.ulalop o1 ulqlr,loe : p
Iq peurlap uortcunl aql oq (u)f tet ll'O luorcr,trto ]sou oql ro] uolP] oLrrl aLl] olou3c
(u)i tet 'steOalur u 1o
{et;e po}.ros e oq s -;- 80 3
leooz-:rvel r ll
(n o(u6o10o1))O lou [oool-rrvs]
V Z L E ]C u
lnq '9 0 < ) ]uelsuoo artlos ro+ (r(u6o16o1))6 (p)
I E Z ':
0 < u ]uelsuoc Aue ro1(r(u6o10o1))g ' L t I:
Z ? r.1]l
]ou inq '0 < I ]uetsuoc otlos rol (r(u 0o1))6 (c) cctTa
0<)i ocEv lo
]uelsuoc [ue ro1 (r(u0o1))g iou ]nq (sou)O (q) :sapo3
(s ou)O lou tnq (u)O (e) (eu)O=uI ', u 6o; +t-ul = -r 'C
sr(uor1e1ou fueurq ur pelueserdei sr u)u (u 6ogu)6 ='I 'e u 6o1 u + zi'I = "I 'C
]o loor oqnc oll] Ourlnduroc lo fttxe;duroc eq1 (zu)O ='I 'Z u *'/uI = -r 'E
'U (u)O=uI'L u+L-uI=uI 'V
> eu ]Eq] qcns u reqLunu lelnleu teOre1 eql se
pourlop sr u roql.unu lernleu e,o lool oqnc oq1 0r'o il-lsn l-lsll
sr"rc)!,r**rt{i$d
4oaq4raAA Ii5U3 3trUltl
{*rnpr:t*r Seienc* & iT a &lgcr&thnr, Sata StruetLgre & Fr*gramminq $x?ffiffiffi ffiffixffiffi
.. .. ," .. : -'

Q.44 Consider these two functions and two statements


log, 1 loair- l
^,
S'l and 52 about them. =
Q.47 Let S,t2^r )r=O a,
Z
and Sr= )12'.Whichof
r=A
intwork 2(int. a, int i, int j) o
int workl (inf a, int i, int o the following is true?
o
{
{

int t1=i+2;
::, (a) S, = @(n log n), 52 = @(n log n)
a
int x=a[i+ 2]; J
alil-"r1
int t2=alt1l; -
cn
(b) Sr = @(n), S, = @(n log n)
a[i1=t)+1 gC
returna[i+2] (c) S, = @(n log n), 52 = O(n)
- 3;] rd+t i^+D a. o
o
l
(d) S, = @(n) S, = @(n)
D
o IDRDO-20081
S1: The transformation from work 1 to work 2 is o
valid, i.e., for any program state and input Q.48 Which one of the following statements are
U
arguments, work 2 wiil compute the same m correct regarding Bellman-Ford shortest path
m
output and have the same effect on program a algorithrn?
state as work 1 n
C
u P: Always finds a negative edge weighi cycie
52: Allthe transformations applied to work I to o' if one exists.
D
get work 2 will always improve the =
o
performance (i.e. reduce CPU time) of work z
l
I Q: Find whether any negative edge weight
o cycle reachable from the source.
2 compared to work 1
(a) S1 is false and 52 is false
U
o (a) P only (b) Q onty
J
(b) 51 is false and 52 is true Z
(c) Both P and Q (d) Neither P nor Q
o
(c) 51 is true and 52 is false !
D Q.49 We have the following recurrence relation:
.(d) Sl is true and 52 is true o

IcATE-2006]
J
a
I
l(n) = l
t n<5
o
o
o lT(n/ 5) + T(3n/ 4)+ n n >5
Q.45 Consider the following segment of C-code
Then which of the following statement is TRUE?
int, J, n; o
=
g
l= l' o (a) T(n)e o(n2) (b) T(n)e ei(.,,fi)
o
while(1 <=n) !
o
(c) T(n)e @(n) (d) T(n)e o(n log n)
i=i*2 a
I I *r a
o IDRDO-200e]
o
The number of comparisons made in the o
C
Q.50 We have the following recurrence relationr
execution of the loop successfully for any n > 0 -.
is o
o I t fl=l
T(n) = l
(a) [log, n-l+ 1 (b) n
=
D
l I.7T(ni2)+n2 n>l
(c) los n (d) [log, n_]+ 1
o Then wlrich of the following statements is TRUE?
= (a) T(n)e O(n) (b) T(n)€ o(nros27)
IcATE-2007] =
j
o
- (c) T (n)e o(n2) (o) T (n)e @(n3)
Q.46 lf T(n) = 3T(n/2) + n, if n >1" T('1)='1.1'hen J
o IDRDO-200e]

T(n) =? =.
o
l
Q.51 We are given a sequence of n-numbers al , a2,
(a) o(n) (b) O(noezs; !
o ds...dn, we will assume that all the number are
l cjistinct. We say two indices i < j form an
(c) olnsrz; (d) O(n
oezs
iog, n) b
@
o
- inversion if a, > a,.
IDRDO-2008] How much time it wili take to find total number
of inversions in the given array?

mm$H HmSH
Frihlis*ti*cr*
.,,4, 1---,
lgrB-IS
=I!FE*&i3!
It{ uri "! - - tq
ffi#&#HH :=HG"5{.AW
lu,ooz-:.wgl
oslo U+UZ (P) Z_UZ -
u-uz (q) . .toc
:0 1urnlor(O==u)ll a
Z tj-.- '-
,9 O-S:-':-: -
:LUns olqnop
:l lu! - u€
o
o a.tE
I C
o 'z^Y
(u lur) ool alqnop -_
=
:uorlcunl - 3 0urnrollol oqi roprsuoC co Ioo
EIEC uoLrLl.loc
-
o
z9'o 3 Lg'O roJ !
.=
=
E
lsooz-=rvel O
:-fi:;*#ffi t3
(arau)6 (p) (u 6o; u)6 (c) C
6
(u 6o1 u)6 (q) (u 6o; 6o1 u)O (e) ,=
c
(ernlcnrls elep deeq e es1 : lurg) o i :0 = lelunoc :(,etu^:
,9
I
:sr sluourela asoq] llE ]o ]srl popos e 6urcnpord ) =:;
o :++lolunol -
1o {1rxo;duuoc otrr} oql qceo s}uorxolo co '==
O (+-
l Io
u 0o17u
lo stsrl pa]-ros u 6o1 are ereql esoddns Og'O c -
o -
a - = -:-. - (
o
lgooz-=rvel :e6en6ue1 o>lll c e ur uolJuM ]r,e*::-- -,.-.: - -
o
!
(l- N) u (p) + (L , >t)u (c) 6urmollotroqlreprsuoC (r-u)gs' -.. :--, - :- -
L 6
E LA
L+ I (L U) (q) )u (e) esoq^A uorlcun+ e sr (Lu)1 puE -l'-=-- - - =,- .:-
o
o (O ;; :
sr sepou leuralur u qirM e3r] B c ro i)irq e 6uuo1s Aetp te =:'., - =-
!)
qcns ur soneei raqurnu oql uropp-.lo y,(11cexe E
+o (u-6o1 u)i5 (p)
o
seq opou leulolur ,4rene '{re-1 e}eldu.;oc e ul 69'O 6 (zu)o (q)
o
o 5
lsooz-grve',lAt0o1(ln|+;=l))o(o) z
,j
c -uosuedu.roc ro,l 'osec ]s.loM oL..ll u
o
o .lorio
(ln| oollnl)o (c) lo requJnu oL.ll uo punoq
o
z
(l,i1oo1 lAl *(lrl)o (q) esoqi lo euop (p) -_ -
-a ]rt6
(e) ? (u 6o1)6
(q)
e inl)o 6 - =
,9
illxelduoc ou-rl Lllrm ornlcnrls elep deeLl fueurq E - :..'
L= olC
eql6ursn poiueLueldLrLr oq uec uq1uo6le qled uenr6 eq1 ur X ]uolxalo ]o uo l s.r = -- -, -
a
sepoqs- ocrnos o16urs s er1s1116 s1q0iam. e0pa L!
pue lndur se y reOelur ue sa)le] ]e-l * -: .--a = -=-
LL]
enrgrsod qlrm Lide;6
petcorpun u€ (: A) e 1ol BE"O o loftrxelduocaurlpulj uloonlp' e-- -:' : .- - Ulet
ale noA jl - Ll]lA pollU olE Slloc eq] -: -s=- =-- oJe
a
Irooz-=rve ] pue laplo P^il^c
@
(u 0olru)6 (p) z(u)o (c) 6 oL.l] qcrLlM leo
E t:s= bra_ _5r _
(u 0or
u)O (q) (u)o (e) O
- 'i,h
o osor.ll 'e5 'th
sr ure;6ord eql;o ftrxe;duuoc a f
a 2t
our] osec tsloM oql ueql (x lo aorlqns-]qOu ur ;
c
.? 1,re0e: '?5 'it
sopou-+eol +o
loquJnu 'x lo oo]lqnsleol ui sopou
o
o ]r eLr.il] r..lcr ').,
leol ]o reqrunu) urLu sr (x)0 6urlnduoc ]o tsoc O i
u-rori sieOl
al.ll ll x opou qoea io1 (x)O uorleunl E Jo onlen o
eq1 selnduoc pue sopou +eel u Lllr^ ooll Ltrcleos osoql-_ +ol
(u .\CL'
,&euiq pocueleq e lndur se se)lei ure:6ord V /g'O 'ls r
_,--,o) i<9 i
'bh 'ni . su
. L/1^rl*jnIn
tc- "r, \1 a
:
H
'Ltr-'
q.
-? r Computer Science & lT r Algorithm' Data Structure & Programming MBDE Ensld
r "- ryubli*ati$xs

sum = 0.0; int i, n;


2;i < = sqrt (n); i ++)
i<n;i+)
for(i =0;
I

l. for (i =
sum+=foo(i); lg { if(nmodi==0)
return sum, l: Printf ("Not Prime")

,lF) li return 0
la
]
return 1;
is
Q.61 The space complexity of the above function | 3
(a) o(1) (b) o(n) lt
)

Let T(n) denote the number of times the for loop


is executed by the program on input n Which
ienm-zoost lE
of the following is TRUE?
m
Q.62 Suppose we modify the above function tooQ l5 (a) T(n) = 0(.'6) and T(n) = a(lfi)
and store the values of foo(i), 0 < = i < n, as I p
a- I ,^r,*^ *^,^ I E (b) T(n) = O(.,fi) and T(n) = ei(1)
and when they are computed. With this l3
modification, the time complexity for function | 3' (c) T(n) = o(n) and T(n) = o(.fi)
foo$ is
IOO\/ significantly
l5 55lglllll\,ar rtry Ireduced'
vvuvv The sOace
-r-- - l'!
l4 (d) None of the above
complexity of the modified function would be: IE
lo IGATE-20071
(a) o(1) (b) o(n) l5
(c) o(n2) (d) o(n!) l= Q.66 Suppose you have k-sorted arrays, each with
tGArE-20051 lE n-elements and you want to combine those
k-sorted arrays into a single sorted array of kn
in
Q.63 Consider the following C-program traOment | 3 elements. How much time it will take?
which i, i, and n are integer
"
variables' Ilo; (a) o(kn) (b) O(kn logk)
{or(i =n, j=0; i>O; il=2,j +=i); li (c) o (k2) (d) None of these
Let Val (j) denote the value stored in the variable I E
jJ artsr of the for loop' Which one of | 3 Q.67 The number of comparisions required
to find
after termination
tvr
I6
the following is true? ,!\ ^t \) lE
maximum and minimum in the given array of n-

n)
(a) val (j) =.@(log
, r_
(b) val (i) = o(.fi IF
elements using divide and conquer is
(c) val(j) = @(n) (d) val(j) = @(n los n) | ts l3nl I-3nl
[onrr-zoout l!. (a)
lZ )
(b)
lzl -
Q.64 What is the time complexity of the torrowing lI (c) (d) ,
recursive function: LT]., [-?l
int DoSomething ( int ,,
n)
lg
I
I
=
:
Q.68 An algorithm performs (logNltrz find operations'
{ ifn<=z) ll N insert operations, (logN;rlz operations, and
return 1; Id
l= (logN)1/2 decrease-key operations on a set of
else I f data items with keys drawn from a linearly
return (DoSomething (floor (sqrt (n))) + n); I
) @in)
(a) (b) @(n los, n) lE
ls
= ordered set. For a delete operation, a pointer is
provided to the record that must be deleted'
For the decrease-key operation, a pointer is
(c) o(log, n) (d) @(logr logrn) ll lA, provided to the record that has its key
IGArE-20071 le
decreased, lVnich one of the following data
Q.65 Consider the following C code segment: structures ,s lne most suited for the algorithm
int lsPrime (n) to use, rf t.e goa is to achieve the best total
| ..: . i: .-.tr.;: :::.:..rt r: i: ':"]al:::i::l"l:::
6ro'suo; ge: g1qnd{seaapeur.manrtr
silsl;erililqndw
'!l:irr"-l:--!:i:,:-:-i;l..,iri", :::1: ;:;r l:: r::.4:,':: r't I
rqQtI@6 i rq
-__
list = 3gtiltr
[(e) :suy]
roplo lonal{1re;rurg (g urorl0urUels) ,3."- _ lelo
osor.lllo euo51 (p) (u)o (c)
olqeuen xaput ue q]lM V Aetrc e ut po,:--. :: ,' uq
(q) (u) o (u) o (e)
q deaq xeuu ]ue]lnsal oq] lo les.lo^el ,:c- - -: _ - ele
st (u) rl + [(u) 6 . (u) l] ueqr .9
o ,ial
(u)s=(u)qpue(u)O=(u)6,(u)O=(u)tret .LI .a 9V 'eZ'01 'L'9',g ''
't ' aa _a t
E sl .,l
o repro uenrO ullt olut pouosut elem stae a-_ -: -=.
c 'pel
o 6uranol1o; aq1
Ourulnsse dee;1 xElAl ou- -l---: _ _ 7_
.= : : sr r
4;aslnol fi.r1 3
o Alre
! Sl UJU],IOC : --: : -:
J ue 6ulsn asec ]slom ot.l] ut sLos ,-c)*11 ;=- lo l
o
E
.=
asolnutu 9 ut po^los oq uec 1eq1 uelqord 3 lo loqirlnu 00i = u ot.l] loj 'sluotua 3 - -: -: PUE
e lo azts lndur u.lnurrxeu aLll seleu:rxotdde E pauos e;Ours e olut sistl esaql aOteLu a/,,, rl -::: 5U
o
c sluolrjolo ,/u ]o s]stl po]los ? e.te oleLlj osoc c - s g_
{leso;c }soru 0utmo11ol ol..ll }o rlclrl1 :
.(B
'tg azts;o lndur ue lol spuocos 00 salel osec t-
lslo A or-1i ur utq1r.ro6;e
;o suo!ls3no
.2
yoseOleur E leql aunssv U.A
f edfi1 elee le)lJ3unN
o.
E
o
o
E
'rp uorlrsod pug
o- 'seurB orsl -u
o 9] ele] lr llrl ou.lrl rlcnul A oLl uoql +
o leeder ]uouJole leqlo fuene rluoixele auo uerfl put
-o
d .ror-llo olor..ll sluoutalo-u p Aetrc
pslose ua !e
E
sr qder6 slr-.ll o
to seOpe o 0)o = 6+l (p) (0)o = 0+1 (c)
-o
B lle to slq6rem lo uns e;qrssod unututu eLll .a
E (l)o = O 1q; {6is =1 19)
ol '6unao4o;
'l olaq uA orls eln6rl eql ur uenr6 oj€ fsy\ or.l]
U)1]
ur ore L{ctq^ se0pe esoql {;uo 1o slqOrenn e6pe di
al ot1l ruoll luouralels onr] purJ uor{ (l}O = 0 }l oso
ollt {G'C)'(J'f)'(f 'g)'(C,e),(C,V)} :se6pe zo
tl]1t
orll suteluoc pu€ gt lqbrean 1o sr (19y1) eell c-: papunoq
o
6uruueds uJntltutru eq1'slqOrean a6pe .le6e1ur o {1;eruouApod ere ;(u6o16o1) pue 1(u0o1} (p}
;
o
leo
Icullslp qyn se6pe g sell oloq umol.,ls qdeiO eq1 g4.g Z ((u)l) o = ((u)O)s + (u)i (c)
^ o;
c
,o
(((u)O '(u)1) utur) @ = (u)6 + tu} (q)
'uq1r.ro6;e uorlrped ssed ;o 6
lsrll lo loa#a oLll 6unraseld e;qrssod sr sleOelur 3 ((u)l)O = (u)0 ueql ((u)0)6 = (uls (e)
-o
l
o- osle3 ro on{ sluoluolels 0ulnno;1oJ or.l} a}r.t6^\
Aetrc p struetue6uele lo loqunu p1o1 [ueu.r 0/
'lueuole a
A oH lonrd sp luouJalo lsrr; Dursooqc UJ (r)o (p) (u 0o1)6 (c)
L]J
Aq per;dde sr uq1uo6;e uorlrl.red Uos lctnp o (u)o (q) (u 0o1 u)6 (e)
gg '06 'ge'4'L '96 'gL '08 '09 r..iclr.
o SI LUNLUIUILU
']ueurelo ]sJll sB o puz rou ulnujtxeul puz lallllou sl leq] ]stl str.l] ut do
0g ]nq d
'({gtlopuel peceld) Jeplo pouosun ut s}uouloie E luourolo ue puU ol suosuedutoc io JoqLUnu oq1
o 'siuotrjolo
Ournnollo1eq1;o Ourlsrsuoc {e:rc uB JeptsuoC gZ.O o icutlstp u sutpluoc tstl pojoploun uv
! 69'o
f
U)
Ll{-t1rc1 ;
c tsrt polurtAlqnop pouos (p)
.Io
onlen elqtssod urnu:rxeul orll oq plnoc ieLl4 {ele pepog (c)
o-
'palelnclec o
sl l/-l I pue poulElqo oro^ B puE V o deeq-ur4 (q)
r.xor, sonlen uoneco;/ pue l enrlcedso: ,]uousla @
{erre peuosun (e)
rc;ncqled loJ '(0 urorlOurpetrg) repro ul /a;qeuen
6suotleledo
xepur 6ursn g Aetrc eql ut pa;ols sen leslsne4 or.ll lle Ouueprsuoc firxeldu.roc crloldr-u{se
**{}tlsilrf qin{t !uc
f,T \aaq>Uo/1A
ti5u3 30uur t!
i e*mputer Science & lT a &$g*rttf;trw, **ta Str*uetrsre & Fr*grame"*isrg msamE ESISH
1& ']t i"'
"'"'::i.J :ii

r2. Consider the following "Max-heapify' algorithm Assume that the divisron operation takes
Array has size atleast n and < i < n After constant time and "sum" is giobal variable What
'1

applying the Max-heapify rooted at A I i ], the ol is the time complexity of "find (n)"?
result will be the subtree of A 11 . ..nl rooted sl (a) O(n'?) (b) @(n'?logn)
!l
at A i ] rs max heap. [Assume that except root
I :lcl (c) o(n3) (d) None of these
A[i], all its children satisfies heap propertyl
Max-heapify (int A [ ] int n, int l)
;l
cl
lAns: (a)l
-sl
{
ll:l 14. Grven n iinearly ordered Cistinct elements. What
is the worst case running time to find ith smallest
int P, m; 1l /) /:ll / ^"romthosenelements?
P=i; 3l
ol
elemenl (l <- rl/I

while (X) (Select the best answer by assuming n is larger

{
PI than 50)
if (Y && z) HI (a) o(losn) (b) o(n)
m = 2P + 1; :lel (c) O(nlogn) (d) o(n')
else m = 2p;
lAns: (c)l
if (A [P] < A [m]) igi
t T5. Consider the following sorting algorithm.
SwaP (A tPl, A iml); l?l Sorting (A, low, high)
P=m; lEl {
) if (low = high)return;
else lrl if (low+1 = high)
return; l3l t
) if (Ailowl > A[hish])
) SwaP (A[low], A[high]);
Find missing statements at X, Y and Z return;
respectively to apply the heapify for subtree \11
)
rooted at A [i]. lc
(a) p<n, (2p + 1) > n, A l2P + 1l > A [2P] l- r,
I hioh - low + 1\
=low.[_
(b) 2p < n, (2P + 1)< n, A [2P + 1] > A [2P]
la
s I,
(c) 2p < n, (2P + 1)2 n, A [2P + 1] < A [2P] ia
t; high-low+1)
(d) p< n, (2P +'1)<n, A [2P + 1] < A [2P] t. = Iow *r.i
l= '\31
lAns: (b)l lilE Sorting (A, low, tr);
T3. Conslder the following function
i; Sorting (A, t,, high);
find (int n) l= Sorting (A, low, tr);
{
l= ]
if (n <
else
2)then return: l: What is the running time of Sorting(A, 1, r
i li
lo
l-
function
(a) o(n17) (b) o(n27)
SUm = 0;
for (i = 1', i < 4', i++) f ind(n/2); Ir (c) o(n37) (d) @(no7)
foi' (i = 1; i < n*n; i++) l; lAns: (c)l
SUla'] = SUm +1; ls
)
l )

r$Bffiffiffi ffiffi=H lieiir''piffi


s*(?il*stiqie*3
HSHET 1q6t
=TMH*X$
I3
[(c)
I:
lp
lo
t=
l=
lo
lr (u 'r
l!
lo lrl v -+ [r + r]v
l! )
t:
lo (,{a>i . lllV tt 0 < /) e11q7q
l*=
lc
l6 fx] =,
IITI ls
l€
la ffly -+ Aay
[(u 6o1 u)g:suy] t: l
t iVl q10ue1 o14 -+ [ to1
tb urnler
t;
t:
la )
{
IP
lo (V) Uos-uorpasut
lo
lb++ I; A;enllcedsel
la pue X ]e slualltolels 0urssru-r
_-.^ (Z*\=\ ld>1 l;=y) ro1 t=
lm aLll pull 'pouos oq o] sluoluelo u ]o ecuenbas
ld++ IF
t-
Io Oulureluoc releuered se [u"';]y derre se>p1
(Zll,=[:;<[ lu=[) ro1 t: L{c!q/v\
'Uos-uotposul pollec ernpecold e se
jo=d le
lr ;l
pelueseld st Uos uotuosut Joi epoc opnesd eq1
)
(t++ lu>r lL r) tol EI 4eutr1 sseco:deld
= ol
7,I aL{t
j0 = b 'd '>t
'[ 'l lut lll/v\ }eL{^ uolll (l)o sl q.'.e eouel eq1 ur
)
=l
pl 11e1sre0e1ur-u or;] io {ueui moq inoqe fuenb {ue
ul
(u 1ur) ;un11ur ,t o] leq] Aem e qens ut lndur er_{} ssecotdeld o1
:, I
e,b, lo anle^ oLlt st ]eq^^ pue ftlxelduroc al ]uel oM ;1 o] 0 Jo a6uel aq1 ur s;eOe ur u ueNe
cl
.
ol
oLUr] eLl] puil uotlcunl3 Ourmo11ol oLll
raptsuoC L Lf !l [tl >! t nl ,1 r t; :suy] [(c)
al
:l
[(c) :suy] 'iopJo
:l Oursealcur ul suollcLrn+ oAU osolli 11e eOuery
3l 'u6o1Z
I
,, 9t 'u6o1 il 'uu 0i 'elrU
i]JIT (p) FTFI = = = =']'uol = '!
,",
tl-l-al t^)xl ?l re6.l,
[(1u)g :suy]
:l 'pos eOroLl palltpoul cSlu
1o ftrxeyduoc
li*,I-r*rl [-+-J-fi7 lsol
ffi*---l(e) EI
ol
orrJrl lElol puti uoql'e;npecord e0reuu
' 0)t leLlA
[E(q) L^ I x l' al prepuels 0ursn peOreLU uell] pue Uos uotyosut
-l
0ursn pepos are 1 q10ue1 ,o r_lceo slstlqns )i/LU
I(B)
'-l
=l Ljcrr.1A ut
pos e6teuu o} uotlecrytpoLU e roprsuoo
{ -l
de1-+ 5t
[l + l]V ol [(>l 6ot u)g :suy]
ol
{ eoujr] qcnLu Moq o)ei
= r
llr/,^ uos deeq 6ursn sluoLuolo-u ]o lstl pel;os ]Eqi,
l-.rl ouo olut )j/u ozts Jo qceo slsrl pouos-) 6ur0rep1 5d)
sii*l&sliiq*# !ir..
h$- ry*aq4.tafu1
ffiffiffiffi ;r
GreadyTechnique and
Dynamic Programming

@
(a) every minimum spanning tree of G must
iliifrfr*iilil; o contain
ffiff*,f Multiple choice Questions
o e,n,n
E
c=. (b) lf e,,.* is in a minimum spanning tree, then
-
f

a its relnoval must disconnect G


c
Q.1 Adjacency list is preferred over adjacency -g
o
o (c) no minimum spanning tree contains e,.n*
matrix when the graph is 3
s (d) G has a unique minimum spanning tree
(a) Planar (b) Dense o
o IGATE-2oooI
(c) Clique (d) None'of these
U
IDRD0-20081 m
m Q.5 Considerthe following graph where the numbers
a denotes the weight of the particular edge
Common Data for Q.2 & Q.3 -!
c
g
We are given 9 tasks T,, Tr...Tn.The execution of os
each task requires one unit of time. We can execute I6' f

one task at a time. T, has a profit P, and a deadline d, z


o
{
profit P, is earned if the task is completed before the oa-
J
end of the d,th unit of time. Z o
c$
Task T1 T2 T3 T4 T5 T6 r7 T8 Te f
o
Profit tc 20 30 1B 1B 10 Z3 16 25 z
Deadline 7 Z tr 3 4 tr Z 7 .) o
o
o Now, calculate the minimum cost spanning tree
:o of the above graph using either prim's or
Q.2 Are all tasks completed in the schedule that
o Kruskal's algorithm.
gives maximum profit? o
! (a) e2 (b) ee
(a) Alltasks are completed o
o
(b) Tr and Tu are left out
c
o
o
(c) 102 (d) 123
o
a
(c) Tr and T, are left out c Q.6 ln a simple connected undirected graph with n
-:
(d) T+ and Tu are left out 6'
o nodes (where n > 2)the maximum number of
o-
IGATE-20051 ='
N nodes with distinct degrees is
l

Q.3 What is the maximum profit earned? o


l
(a) n-1 (b) n-2
(a) 147 (b) 165 J
(c) n-3 (d) 2
o
(c) 167 (d) 175 C IDRDo-2oo8l
=
o
IGATE-20051
=.
=
o
Q.7 A file contains characters a, e, i, o, u, s and t
Q,4 Let G be an undirected connected graph with ol
o
with frequencies 10, 15, 12,3,4, 13 and 1
distinct edge weight, Let eru, be the edge with 3
6
respectively. lf we use Huffman Coding for
maximum weight and e.,n with minimum weight. a. data compression then the average code
:
o
Which of the follorr;ing statements is false? length will be.

INRITE E]Is}J
ffi Frjt:{;fati*fts
6to'suorgerS gnddseaepeu 144m*
ffist*H tq6p{do3 g
l'l
=IUU[*'
{l 'r} e0pe eq1lo lq6renn
ltn71
oqi sr Moloq M xuleuj oqt ul {r1u3 .{7 ,0 ,z ,t ,0} ap
]es xauon qlrm qder0 poloaltpun e1e;dwoc e roptsuoC
lc .lo]
gt.o g rL.o rol pleo uoturuoc L
t;
lE
Iar ]p
lsooz-:rvel lu
saoriro^ ortl (p)
l.
ld)
llV IE le
p 'c ,q ,e ,soclua^ {;ug (c) 'ailnos
l=
l.
q '0 ,] ,o ,e soctllo^ (q) l- or.i] se d xolia^ qlrm qder6 polcolp pe1q6;am
^luO (e)
e xoue^ {gug l:
l- -eOpe 6urmollo; oi1l uc Luqiuo6le qledlsaporp
lo
l-
ol osuelstp l= oclnos e;6urs s,et1s>1fr6 unl om esoddng
qled lsepoqs slcarroc eLl] selndLuoc ,qder0 t= lo
aloqe olll utE xoyon uJoll un; ueqm uq1uo61e tit: leooz-=rvgl u
qged lsaltorls ocJnos a10urs s,erisltrg IF e (p)
t-
t-
lo 7 (q)
lq
t.-
t: 2petrnbet su;ool ]o .tequln-
t-
lo urnujturuj olli st ]EL{M ,uot}elnp e]l}uo s}r lo-
t: oL{}lo} ponlosor st uloor eq11 {1uo rl.,loor e lo
I;I ftrnrlce .sn oo]
ur polnpo{..lcs oq uec fttnllce uV ol olqel,e^s
et.o tHt suoor lo ]os e ut sotlt^tlce oLli olnpaqcs ol
(rnr 6or(rnr+ r=r))o (p)
isl poau oM 'y firnrlce lo oul] CIurpue aql solouop
I sl .x ,orep1
(rnr 6or n t)O (c) l*l "x pue eull 0urlrels oq] solouop
tJ
(etnt)o (q) l:l ,,"q "o ta.l'l "a tO "p tq to "c tp "e tc tq te.,
lel
(zhlO (e)
t5l :repro {lenrlcedset ur
a{irxelduoc aull} ol1} lll^ }eLlM
l:l H pue'e 'J'l ;ecrOolouolr.ic
c,c,B,V sotlr^tlce jo
'ornlsnrJS etep
lsll polUrl poilos lsl seutrl 0urpue pue 0uryels oL.l] ole 0urnnoylo; eq1
aql Oursn pelueuegduj oq uec uq1uo01e qled l=l
souor.ls- ocjnos e;6urs s,er1s>1tr6 .s1q6lenn e0pe I{l leooz-rrvsl
I5t
(p) sio
lel L' BS (c)
enrlrsod qltm qderO polcojtpun ue (l (q) (e)
A) e lol ZL.O l;l r0 *,
ol lo
ol
() I
lzooz-:rvel !ltrt
e (p) (c) LI
e ,t
'6 I
, (q) s (e) <l
ul
,g .rl UA
u lo onleA ol.l] st ]eqA 1- = 1 pue ol
'LV = 1ll oorl ,fue-u e1e;dr_uoc e ut so^eol
Jo :l:l
roqujnu olll aq I pue sopou leurolut lo Jaqulnu o)l lsn
eql oq I tol uorpllr-.lc ou ro uoJpltLlc u sEr.,l opou 6l
=l
EI
qceo Llcrr.ll ut oot] p st ooll fue_u e1e;dLnoc -I() I
V L L.O ol aqderO 0ulnnol 1o1 eq1 1o
dl
=l
al eerl0uruueds LlinuJtutLU e 1o iqOrem oql sr lellM
lrooz-:rveI 8'C
ol
s'n 'H 1'O I (p) s r,n ,u ,o I (c) ;l [oooz-oouo]
ol
1'S'n'U',O I (q) n 1,s,u ,o I (e) sl B9 Bq /^\
(p)
Lpaztpull aJe socuElsr p OI ,lt 0gL'-'
qled lseyoqs oll] r1oiql^ ro] socll;on ]o ios oql UY 89
(q) /p\
\U/
olur popnlcur 1e0 sepou or..l] op ropro leLlm ul gvL
0vt
-
IY
d-L *{:i*{}u*i$qiitd M
ryQaq4jaAA
EsH=l Etrlt u
-L Ll
;
:i
Cornputer Science & lT e Algorithrn, Data Structure & Prograrnming MHI,E EHSTT

(b) lf e is not in a minimum spanning tree T,


(o 181 4)
then in the cycle formed by adding e to T,
l1 0124 sl
all edges have the same weight.
w=18 1207 3l o
o (c) Every minimum spanning tree has an edge
l1 470 ,J o
!
of weight w
l+ 9 32 a=.
-J (d) e is present in every minimum spanning tree
a
Q.14 What is the minimum possible weight of a g c
IGATE-20071
o
spanning tree T in this graph such that vertex 0 o

is a leaf node in the tree T?


:s Q.19 Given Z-arrays of numbers dt,&2, a, ... an and
o b,, br, b, ...bn where each number is 0 or 1.
(a) 7 (b) B o
The fastest algo to find the largest span (i, j)
(c) e (d) 10
U
m such that di, di*t.... dj = b,, b,*,, ...b, or report
IGATE-2010I rn
that there is no such span.
(t
Q.15 What is the minimum possible weightof a path -oc
(a) Takes O(2') (b) Takes O(n2)
o
P from vertex 1 to vertex 2 in this graph such (c) Takes O(n) (d) Takes O( ,fi ) times
s
that P contains at most 3 edges? =.
o
f
I Common Data for Q.20 & Q.21
(a) 7 (b) B z
o A sub-sequence of a given sequence is just the given
(c) e (d) 10 €
U
o sequence with some elements (possibly none or all)
IGATE-2010I z left out. We are given two sequences X[m] and Y[n] of
zo
lengths m and n, respectively, with indexes of X and
Q.16 Which one of the following statements are !
s
Y starting from 0.
correct regarding Bellman-Ford shortest path o

algorithm? =
@' Q.20 We wish to find the length of the longest
CI
o common sub-sequence (LCS)of x [m] and Ylnl
P : Always finds a negative edge weight cycle o

if one exists.
3
!0
as /(m, n), where an incomplete recursive
o
o definition for the function (i, j) to compute the
Q : Find whether any negative edge weight cycle
!
o length of the LCS of X[m] and Y[n] is given
reachable from the source. o
o below:
(b) c
(a) P only Q only O
o (i, j) = 0,if eitheri=0orj=0
(c) Both P and Q (d) Neither P nor Q
o-
o
= expr"1, if i, j > 0 and X[i-1] = YU -11
c
Q.17 Consider a weighted complete garph G on the = o
= axpr2, if i, j>0 and X[i-1]+YU -11
o
vertex set {v, ,,t2, ....., v.} such that the weight ;' Which one of the following options is correct?
D
of the edge (v,, v,) is 2 li - jl . The weight of a = (a) exprl = (i-1, j) + 1
o
minimum spanning tree of G is 3 (b) exprl = (i, j -1)
(a) n-1 (b) 2n-2 (c) expr2= max ((i-1, j), (i, j-l))
=
J
o
(c) (n/2) (d) n2 C
(d) expr2 = max ((i-1, j-l), (i, j))
J
IGATE-20061 o
{:. IGATE-200e1
Q.18 Let uzbe the minimum weight among alledge o
!
= Q.21 The values of (i,j) could be obtained by dynamic
weights in an undirected connected graph. Let o
3
programmlng based on the correct recursive
e be a specific edge of weight w. Which of the @.
o definition of (i, j) of the form given above, using
following is FALSE? : an array L [M, N], where M = ffi * 1 and N = fl * l.
(a) There is a minimum spanning tree
such that Lli,jl = (i, j).
containing e.

MRE'E ENs}I @ Copyright


{i11{3irl*:}t3q*d @
risuS auuul ,
lt
epq (p) qce (c) au:q1uo01e s,et1s>1[rp
(q)
unt oM uoqm lcarioc sr 0urnnol;ol oq]
]o qctLlM
rcq cqe (e)
ueql se6pe lq6rean enrleOeu suteluoc qderO
00101 L .rol ooBSSou pepocop oql ll ,Z,A I
6l
srleql^ uoq] epou [.lene utol1, osor.t] euo51 (p) our
L, r-1]lm plrqc 1q6rr
?i lo 11 pue r]ioq (c)
r
EI
puP ,0, t.ll.l^^ pllr..lc tlol sE papoc ootl ueulllnq rr Aruo (q) d/\l
fl gz.o E I 1{1uo (e)
6 I aonrl ore slueulolels o^oqe ollt lo r.lctqM clr-
eh (p) w@) :t;
I peurlop
Bs (q) 0e (B) -tt"^ sr qled ]seuor1s LtctqM rol xoyo^ Ioc
'eOesseul onoqe eq11o 6urpocue ! |
3 | e rol
punol sr qted ]soUoLls ]celloc e .e;c{c
uer.ujJnLl ro; perrnber sllq to loqunu olll pul1 LZ.O i L,,n,^..
E tU6tem enne6eu
^.,.^a^. seq qdei6;r uene ,urqlrroOp
I
ppqqccccpppccqeqqqqee E I Ptol-ueullo8 oq] Jo uotleutu-lrot or.,ll ]v II
'1 o1 qled
:eDesseul 6urmo;;o1 or.l] JoprsuoO f I
e ulnJol s[ear1e lltl s ]e oulpels
s I lsoiJoUs
gz'o ? LZ:O )ol le^^suv polull c]
,H
uqluoOle prol-ueulloB ,] pue s socrua^
,_|I
o^i Iue pue qder6 pelqOrenn {rene .I
osot.ltlo euop (p) rr pue r qtoq (c) FI ro3
6l sluau.rolets 0urmolloi aLt] roprsuoC gZ.O Ir-
rAuo (q) 1I1u6 (e) E I
.onr] ore sluoualels o^oqe aL{} Jo r-lctqM toroa=rvet
e
'g qder0 ul qI \ zl^ + oe (p)
( Z + oe ,1)xeur (c) uor
I
3,1 oe'1)xeu
(zlt + ue '1)xeu (q)
sacrilon jo Jaqurnu sru olot1M .un"y (L _ u)
iI Qll+ ( + 0e (q)
1)xeu (e) oq]
]soul ]E iqOrean onell lltm e lo aot] Ouluueds g ol lenbe sr:/\-'-rr
X uot1 oAr
Yl I
LunLurulur oLll uoLlf .unry al g qdelO L-ue '
'ze'Le ecuenbesqns
E I 1o luln
e rol 1qOtem eOpe eOete^e teq] osoddng .tr lqOrenn elqrssod ulnulxeur aq]
uh,
ise
=l I I ..,,l^,ll.^.-
f Ie lot-ue.'
- ^rrh --
'g qdetO or.1] ur/ o] n u-lolJ !| ow 're '0e ecuenbesqns
lo e lo iq0renn
qled lselioqs oll] st 1 ut^ o] n Luor; qled 3l olqlssod LunLutxeu oql olouop x lol .ollres
2| sluoluolo 0urureuler oqlioropro eq1 Ourdael PUE
or..i]^ pue n socruon onnl {ue loi uor-ll .e "qr
qdet0 e 1o eetl Ouruueds LUnulurLU e oqf E 'ecuanbos or..ll [!o.l] s]uotitolo oulos 6ul1elap lo [
lol I dl| r^^^. (tte
sluoulajels 0urnno11o1 or.ll
? Aq peuelqo sr ocuonbas e 1o ecuenbesqns y
roptsuoC aZ.O 2l| t ue + z,lte^+ 0e se paurlep srsloqunu ud/\
ox c,
"zlt ' te '0e ecuenbes '
(p) "x (c) ,"", Jo t 'e e 1o 1q6rem ot)I ZZ,A
1,,
ff i
'x (q) x (e) f I toooz-rrvel
f
I
'ycesdeu>1 oql ut poceld {l1erped
sr
qcrqnn lcefqo aq] pul] ueql iq0rem irun red 1t1ord ;1. I arotaq pelndLuocs>broi>dreqirelr
3 Is tt eq o] spoou tb ,dl f (p)
LUnuJlxeul 0ursn penlos sl u.le;qold >lcesdeu>1 u |
i1
A I [ru 'ru]r lo uod
> repto toleut uutn;ocloteptotofeu] Mol Jaq]to
(Lx ,..., zx ,t.x):slcefqg .
| (f 'r)
0'V't'L'g'g'Z) = (Ln'"''zM,t,rn) :s1q0re11 . E ur Oetndiuoc oq ]ouuec ([,t] lo sante^ oql
I (c)
L
(e,el,g,Z,St,9,0L) = (ra,...,.d,,d) :slrlord . ,nlr rn
E I PUE
slcelqo / pue gL sl>lcesdeu>11o
ftrcede3 . f reOro ro[eu uuunloo ro repro rofeLu mo;
I lo
,t)
:oouelsut lcesdeu>1 oLlt loptsuoC
aZ.O E n u, palnduroc aq {eru (t
I io sante^ aq1 (q) Ito
5l Pelndu:oc eorl
asaLt] lo ouoN (p) ,\treOorO aq o] (['t)7 to sonle^ oLl] ro1
qder0 ur selc{c ol onp so}putrrrot lalou (c)
ll
}l O o' pazrter]rur
eq ptnoqs I lo stuoLualo llv (e) oOp(
s]lnsoj 3I
]corJocul ecnpord {eu"r 1nq soleutul.lo} }l (q)
i (l ')t lo uorirut1ap o^lslncoj oq] rol uortnlos
0urntutet6otd crureu{p oql 0urpte0er
InUl oq 101
oleuiuJro] 1ou {eu il (e) plnom sluau.tojejs 6urnrrolgol ol.l]
io ouo qclqM L vr
trT *'.
u t-,;] iI*l-1 i 14 i.l
0 t jI >1ooq4sotr4 i tj 5il"ii: :
riSHA ETIIUIU H
*rn
AU: " Computer Sclence & lT r Algorithrn, Oata Structure & Pragrarnrning MMMH ERs}J
i fiq*,rii,l.'lg t*gls

Q,29 LetPo= 5, Pr =6, Pz=7,Ps= 1, Po= 10, Pu= Q.32 Suppose that minimum spanning tree of the
2 and for 1 < i < 5. Let X, be a matrix with P,_, following edge weighted graph contains the
rows and P, columns, and X = X,.Xr.Xr.Xo.Xu. edges with weights x, y and z
o
Which of the f ollowing is optimum oo
C
parenthesization for computing X?
c=.
(a) ((X,(Xr.X3))X4)X5 (b) (Xr fi2.\))(X4.X5) f
:i
U)
(c) (X,X2)((Xsxr.xs) (d) ((Xr.X2)(&.x4))X5 g
c
o
o
fp

# Numenical Data Tgpe o What is the maximum value of x + y + Z(


frii Questions o
Q.33 Consider the following graph G.
g
m
Q.30 Suppose that you are running Dijkstra's TN

algorithm on the edge-weighted digraph below, a


-o
q
starting from vertex A. g
o
o
-_
o
I=
o
z Find the number of minimum cost spanning trees

U using kruskal's algorithm or prim's algorithm.
o

=
Z Q.34 Assume Dijkstra's algorithm is used to find the
o
!
o shortest paths from node 'G' in the following
The table gives 'Distance' and 'Parent'entry of o graph.
each ve,'tex after vertex E has been deleted from f
the priority queue and relaxed. (,
o
o
Vertex Distance Parent 3
p
A 0 NULL o
o
D
2 A o
c
C 13 F o
o-
c
U ZJ A o
o Find the number of edges which are not included
o
E tt F o
c in any of the shortest paths from node G.
F 7 B =.
@
Lf, 36 F o Common Data for Q.35 & Q.36
o
H 19 E r lVatrix multiplication is associative and matrix chain
sf
multipiication uses following matrices:
What could be the possible value of expression o

x+y?
3 Ar is 10 x 100,
=.
f
o
A2 is 100 x 5,
Q.31 Find the number of strong components in the c
J
43 is 5 x 50, and
following graph. o
{l Ao is 50x1
o
fl Q.35 Find the number of orderings thai are possible
CI
ol
rl to compute A1 A2 A3 44.
;lal
ll
Q.36 Find the maximum number of multiplications
,l
required to compute 41 42 43 44.

MHIIE E[ls:J
*tJ$r?**iiq*d,1.!@
nsH=I AGHUT
I!II uoql '(lst/\ or..l] ut popnlout oie se6pe qctqru,
ur rapro ar..ll sourlep uorlsod ereqm) g > ua >
[(oos r) :suv'9 Loz-rrvg] [
lc oraL{M da ,{q po}ouop sr oori 0uruueds
'- st porllaLi-t uorlecrldrllnul lo
l@
rV ,V te urnL.ututLu ul eOpe ue jc uctltsod aq1 pue
xuleur crseq aq] Oursn ,y lcnpord IE
"V lnr oell 6uruueds LUnLUtutLU ut popnlcur sr qcrqnn (,e)
oq] puli o1 patrnber suotlecrldrilnrr Jelecs lo
la)
l. eCIpe lelncrlted e to3 eotl Ouruueds uLnr-ururu.r
lo roqulnu LunuJruluj eq1 [lenllcodset ,g x t: o-qt pull o1 qder0 o^oqe eq] uo polncoxa o.te
0L pue'01 x 0z x 0z x q,g x 0L suotsuol]Jtp
lo socrJleuJ .lnol
li
eq ,V gue ,V ,"V ,ty ]el .LI t: uq1uo01e s,le)lsnr)j pue u;q1uo01e s,u.l.rd aLLlnssv
tp
t.:
[enr1 :suy]
.g It
se6pe L-u uretuoc O IE
lo
l-
'Z
IL
e1c{c aneq luop e
'L l6
polcouuoc sl c lc ute
aeslEj / on]f }t sl IE
la
'pre oLli serlduur sluauielels 6urnnol;o1 t!
aL{} }o oM} ll
{uy sepou-u uo qderO potcolpun e oq O }ol t;
'91 lo A oloq qderO pelcerrpun palq0rom
lal or..lj JoptsuoC 't
I pop
[h)g:suy]
t:
la
lo
lo
lo
ip qde;6 pot+rpoLU or.li rol tS/\ ln, ilssJno^ fi{
]cnrlsuoc o] o)lE] llt^^ oLUr] LlsnL! MCrl ueL.ll l ut ]ou
lnq e u! luoserd e6pe eql jo auo tqCIran oq]
I;
Itr
1o l:
'9t ls sl slr".l]
to
posparcap amleqlesoddns elolst eoq
ltol 0urop;otr uq1r.ro0le leuuldo oql dq asec ]sJoA oq]
[(1-)6:suy] t:
Irl ur popaou oq lllm ]BL.l] suosuedu-loc 1o reqlunu
jo)e] iltM or.Ljt] LlcnLl-r Mor.l ]ou ole ls[/\J
:l6t eql 'oult] e 1e secuanbos oA^] req1e0o1 0ur0reu
ol 0utl'
:7 I
ol Iq ocuenbes e;6urs e olul peOreur
sr 1 porlrpolu lcaqc o] uor11 1 ur e6pe eql1o oq ol o;e ot'll
,.1
ouo lo 1qOrem oLij poseoroop oM leql esoddng cJ {eq1 {lenrlcedser gg'9t '0t'97 sq16ue1 Ourneq
'
secuenbes pouos are t1.1
unLututLU 'vt 3l
'e lo oor] Ouruueds lsoc ;I
e oq I ]ol a)l
I 'S ,U ,O d asoddng 6g.p
zl saoi
;l
[("u)g :suy] cl
ol
ol soirocoq oetl 0uruueds LUnLUtuILU e 1o 1qOrem eql
aruetootd cru:eu{p esn no{
ol
:l
'enr1,4q paseorcut slg
lo eOpe qcee 1o lqOrenn
]l alel 11rm ualqord enoqe oql ar!r] tlcnu A oH
o-l '009 slC
'LunuirxeLu sr LUns s]l [, ...2+r, 6l oLll ueq7171 io oajl Ouruueds ulnultutul
leqi qcns
'L+te '!e ecuenbosqns snorOrluoc pulj o] ueqgra
ffl e 1o 1qOrem eq1 Se0pe 00g pue sootpo^
<I
''' ee'ze'La s;equnu EI 001 ]o qder0 polcolpun polcouuoc oq g ]al ge.O
1eol-u lo ocuenbes E uanrC 'eI 2l
ol
a)l
,l ac ol s r.lJoll acuelstp Llnt].]lutrj.l sl ieqM
[(e 6o1 e)g :suy] :i
'peuos Apeerle ere se0po cl
al
ot
eq1 1r 'se6pa-ul pue socriron-u uleiuoc qderO a-l
:l
polco;tpun ue lo oo.tl Sutuueds ]soc tlnLutulLu al.l
EI
oi
eq1 0urpurl ro1u_rq1uoO1e lelsnry 1o ftrxegduuo3 'zt '-t
.l
ol
()l
[(7) :suy]
ol
a js t"r'n"r( ,r)- t','o(rr)l
aq]
,o on teA urnlurxeuj ell] st leqM 'g qder0 0ulnno11o1or.{} roptsuoC /e.O oq]
' *il*il*'llid;i1d *w"*""*-*= *liSii
4c#qllj*fv\
${SUEI ACIHUI t5
Linked l-ist, Hashing, Staclc
Queue and Array

o P=listiQ=list->next;
o while (q)
Multiple Choice Ouestions C
o

o=.
f
{
a
a
a
temp = p - > value ; p - > value
Q.1 A circularly linked list is used to represent a go =Q_)value;
Queue. A singie variable p is used to access f
o q-> value = temp i p = Q-> next ;

the Queue. To which node should p point such o


o Q=p?p->next:0;
that both the operatrons EnQueue and DeQueue
]
U
can be performed in constant time? m
l
m
a (a) 1,2,3,4,5,6,7
-!
C
g (b) 2, 1, 4,3, 6, 5,7
l F-l-z
f--" I
s
lo
(c) l, 3, 2, 5, 4,7 ,6
I (d) 2, s, 4, 5, 6,7, 1
(a) rear node z
o
(b) front ncde o IGATE-20081
q
J
(c) not possible with a single pointer Z Q.3 Consider the label sequences obtained by the
o
(d) node next to front cs following pairs of traversals on a labeled binary
o
IcATE-20041 J
tree. Which of these pairs identify a tree
@-
u uniquely?
Q.2 The following C function takes a singly-linked o
1 . preorder and postorder
list of integers as a parameter and rearranges l
s
g 2. inorder and postorder
the elements of the list. The function is called o
o
!
3, preorder and inorder
with the list containing the integers '1 , 2, 3,4,5, o
o 4. level order and postorder
6, 7 in the given order. What will be the contents C
o
o
o (a) 1 only (b) 2 and 3
of the list after the function comoletes o
a (c) 3 only (d) 4 only
execution? ='
a
o IGATE-20041
struct node o
s='
{
l Q.4 Suppose each set is represented as a linked
o
int value; 3 list with elements in arbitrary order. Which of
.next; €
struct node f
o
the operations among union, intersection,
a
); 5
membership, cardinality will be the solwest?
o
void rearrange (struct node.list) { (a) union only
=.
o (b) intersection, membership
{ f
co
struct node *p, *q ; l (c) membership, cardinality
@
int temp ;
q.
o
(d) union, intersection
if (! list ll :
t Ust - > next ) return; IGATE-20041

mffiffiffi
*w
HsEsH o Copyright
Fukr{i*ati*n*
Ar"r{}llt3"1l iff**{
6ro'suo glmllqnddseaepeu'nnnnitrr kkFd dE tmtit lq6uddo3 g lq6l
E *Jldd dHUN
sr uarplrr.lc t ro 0 our^eq apou LlcEo tllr^ 'sopou [rcoz-rrnrur] slsrl omt OurOreu (p) lroo
Lrlo oor] paloor E ur sepou leeilo roqurnu oql 0L'o 1sr; e Our[doc (c)
CI relurod 1so1e 0uuanocer (q)
loooz-rrvgl ;lol
q uiolr ue Ourssecce (e)
r
a^oqe eq11o euou (p) O ieOeguenpe 1se1eer0 slt o] lstl pe1ut1-u(1qnop e
o
rSOdiSVl = ludrsvl (c) o) tro {yedo;d srq} sazrlr}n suorleredo 0urnno11o1eq1 cls
'- lo qclqM urelr uenr0 e lo rossooopord eqi 1o 'uoll
]UdISY/-I = NIISVI (q)
=
o
c uorieururolop eq] soletrlrcel tsrl po1url-Alqnop y /'O ]o q
ISOdISVI = NllSVl (e)
l polr
qciqM eell fueutq o
aeerl sle,ule sr 0urnno11o1oql +o t: lsooz-:=nNrl
=B
o1e;duoc e 1o 'Alenrlcadseg ;esronerl reproerd E
]uourolets lsel oll] se :0 = Ileu <- e ppv (p) lroo
o
ue raprour .iep;o1sod e ur polrsrn xouon lsel eLll ]uoulolels-]l oql roue :L = )jreul <- e ppy (c)
=
d ]uotuolels-+l oq] le]+B :0 = )lleLi-l 3 e ppv (q)
olouop IUdISV-] pue NIISVI 'lSOdISVl ]ol 6'0 ,=
i:, luoLualels lsru ot.l] se :L = )jjEr.x <-- e ppv (B)
o
,9 {uedotd y.iom urer6ord eql e>leu-t
loloa-=rvgl 'a
f
plnolls leql eOueqc eq1 0utmotlol otl] Luorl ]caloS
'd = peaq lpeeq = ]xeu-d :ttnN = yeu<-b (p) o
!
o
:llnN = yeu<-b 1[ = lxou<-d :d = peoq (3) O {
a= :;+(b<-e)
o
lpeeq = yeu<-d 'd = peaq :llnN = ixeu<-b (q) o
o ]unocopou + (d <-- e) lunocepou urnlol eOl+
'd = peoq lpeeq = You<-d :llnN = b (e) o
c :0 urnlor (1reLr <- e) 1r fueu
'ourl)1uelq 6
E ) aLi],'
eill eceldar ol oArleurolle lco;roc ol.i] osooqO o (e, 1se1 1cnr1s) lunocapou lur
ao
{ .9 {b, 'd - }sol }cnr}s :)lreur 'olur lut} }sa} }cntis leoc
- 'apoc
:peeq uJnler o srr..l] r-uorl 6urssruu ]uau-rolels e sr orol-ll
6
o 'sopoLr le )ol uaz,(11er1rur oq ol poLunsse plol+
o
{ =
.: yreuu e sesn ]l opou uantb e uorl olqrssocce
c
:1xeu<-d = d o
sapou io roqllrnu oq] ]unoc oi posn oq ol sl
rl
ld=b B
o urerOord 3 6urmo;go; oL.lI siolutod lpnu ou qltn
Z
o; sopou ieLlio o] srelutod oml Allcexe sel{ qctqM
) c
o
.F g'O
(ffnru = i lxou<-d) eltLlM 6
]o Llceo sopou 1o posudLroc sr olnlcnrls elep V
.O : lx
lPeaq=d:116-15=6 E
L
- Izooz-=:nNn]
:peaq urnlor ((llnN == ]sll or.l] lo stuauiolo oM] ]srrl aql e6ueqcrolul (p)
a
]xou<-peeq) tt (f:fiN = = peoLl)) ll U iuoluolo ls.rl eq] oroloq ]uaurolo ue ppy (c)
U
1b* 'd* epop o
) ]sll orlt lo juot:ola ]sel oLlt aieteC (q)
( peeq. opoN) luoli-o1-olotr+ opoN I tsl
a or.ll io ]uaurala ]sel aqi raUE lueurolo ue ppy (e)
:apoN t (!
E
:]xou* opou lonrls
O
o
:onlen ]ut ) a.-
a
)
opou ]cnrls lepadAl ,l
c ats!t oqt 1o q16ue1 eql
'>luBlq ,iO)
uol sr opoc uo spuedep eLrrl 0urpuodsolloc eq1'suorleredo
o
eq1 io ped oLUoS tsrl porlrpour or-.1] sujnlor pue o
O 6urmo;1o1 eq] +o LlcrqMrol ]srl or.ll ur ]uourolo ]sel
lsll ollt Jo tuorl oLll oi ]uouralo ]sel oLlt 0r:tnoul o oq] o] lolurod e sr pue
1 ]srl ell] ur ]uorxolo ]srl
,{q lsll or-l} poqrpouJ 11 "lueurnOre lndur se ist; or.lj o] lelurod e sr 1 oroql 'A oloq ernOrl eql ur
pe1url-,(16urs e solei uorlcunl 3 Our,uo11o1 eq1 B'O uenr0 se Lrrol eq] ]o ]srl po1url {16urs e roprsuoC g'O
sxJ*il#*riq*{*
N*sq{rc;il4 ffiSHg EI{IUTII
e*mputcr Sri*ne* & iT * AtrgorEthm, Sata Stnucture & Fr*gramming rMRITE EHSH
y1t{fii.1;:":i; :1

(n-1) struct listnode


(r) (b) : {
; J int data;
o struct listnode *next:
(n-1) (zn + t'l
(c) -7- (d)\/ o
o l;
void fun (struct listnode .head)
!
l.
a
IGATE-20021
a
J
- { if (head == NULL I I freaO -> next ==NULL)
C return;
Q.11 The follolving numbers are inserted into an go
empty binary search tree in the given order: :
o struct listnode xtmp = head -+ next;
0) head -+ next = tmp -+ next;
10, 1 , 3, 5, 15, 12, 16. What is the height of the o
binary search tree (the height is the maximum o free (tmp);
distance of a leaf node from the root)? fun (head -9 next);
o I
m
(a) 2 (b) 3 m I

(c) + (d) 6 a What is the functionality of the above function?


T
c (a) lt reverses the linked list
ltsRo-2ooel o
o'
o
(b) lt deletes the linked list
Q.12 Binary search can be carried out on a set of -.ol (c) Alternate nodes will be deleted
ordered clata items stored in a v (d) lt reverses
zo the linked list and delete
(a) Array (b) Stack € alternate nodes
o
(c) Queue (d) List o
z Q.17 Consider the following code.
Z
IDRDO-20081
!
o int f(Struct Node .A, Struct Node .B)
ID
Q.13 A binarytree can be uniquely reconstructed from o {
the {ollowi ng traversal(s) :
). if (A == NULL && B == NULL) return 0;
@
(a) Preorder o
o
else if (A == NULL ll B == NULL) return 1;
o
(b) Postorder else if (A -+ data != B -+ data) return l;
3
(c) Preorder and Postorder 0 if (f(A -+ left, B + left) ll f(A + right, B -+
5
(d) lnorder and Preorder [DRDO-2008]
o right)) return 1;
o
! else return 0;
Q.14 lnsert keys 4, 12,8, 16,6, 18,24,7 inot an ooa
)
initially empty binary search tree. Delete ihe ooo
node having the key 6. The preorder traversal o Assume Node is a structure type with 3
c members as follows:
after deletion is 1.
@'

a,12,7,8,24,18,16 o
o Struct Node
@)
(b) 4, 1 2,8,7 , 16, 18, 24 ='
)
N { int data;
(c) a, 1 2,8,7, 24, 18, 16 Struct Node *left;
o
(b) 4, 12,7,8, 16, 18,24 Struct Node *right;
[DRDO-2009] =
='
J );
o
Q.15 The concatenation of 2-lists is to be performed c
lf two binary tree root pointers are passed to
in 0(1) time. Which one of the following J
o
the function f( ), then which of the following
{
implements? =' statement is correct?
(a) Single linked iist :
o
n@ (a) lt comoares two given binary trees and
(b) Doubly linked list l. returns '1 if two trees are different and it
a
(c) Circular doubly linked Iist @.
o returns 0 otherwise.
f
(d) None of these (b) lt compares two grven binary trees and
returns 0 if two trees are different and it
Q.16 Consider the foliowing C program.
returns 0 otherwise.

www,madeeasypublication s.org MN{TE EMSH ,@ Copyright


Fsi:li**ti*ftr!
]!
tr 6 :se pautol pur
C
BL B BL 8 .o sr 'poroJs aq o1 sde>1 or.,l] luepuedepur
lo
-a sl rlcns
L L E ]l ]ELl] suollcunl qsELl +o ssels ]!
o
v o e uorl AlLuopuet uotlcunj Llser1 or1l
0ursooq3 ;7'g
I c PU
o
I :J 9L I .=
3
roplo
v , o 6ui
c osronol ut s;aqtrtnu tcceuoqqU u lsll+ sluud (p)
EL t c7 I o]t
= sraqulnu tcoeuoqqU u ]sl] sluud (c)
Z Z
co
ZL Z -_ (q)
0 ol L - u txor] sioqulnu stut./d
L
=
E
L
o L
* u ol0 Luorl sloqulnu stuud (e)
0 (q) 0 (e)
c alseeepeut
6
,c uorlcunl anoqe ;o ftr;euorlcunJ oq] sl tBqM
.olqei qseLlluellnso] aLll st ]eqM :o
o
'6urqord ieautl pue
0f pour >t = (>i)q uolicunl .9
E {
l
qsell r.l]rn Oursserppe uedo Dursn g; q16ue1 {
o CI
!
lo alqe] qseq ftdLue {11er1rur ue olut poirosul o i(r)1ulrd
O
f
ere 9L pue g 'tZ't'Z'tt 'Bt '7g_ s{e>1 or1_ gZ'O c l(I + r,6)enenbua
o
o :(A 'O)anenbua
o
loooz-=rvel o
! :(5) anenbep = {
os (p) 0z (c) (s <-
E i(S) enenbep = r
0L (q) v@) o
o )
Zllcreos Inlssoccnsun ur seqord lo ! :L
_@ (++l:u>7:0=t)Jol
roqurnu pelcadxe oql stleql 'uLelqord onoqe ul ,Z'O =
o :( I 'O) enenbua
6 :(0 'O)enenbue
loooz-=rvel o-
e, (p) r (c) zo i
.:
!
o
(u 1ur)Aseeap€ur pto^
s (q) z@) o 'uorlcunl 0urnnolpol or.lt roprsuoC
iL.lc.reos lnissoccns 3 0Z'O
0
e ur seqord lo .taqunu peicadxe eq] sl ]eqM z ale
a
q loooz-=rvel
.o
'souluo 9996 0urureluoc 'siols
000'01 lo lelol
6 LsoL (p) L8 (c)
e qll/v,olqe] LlseLl
ssolppe uedo ue toptsuoC eZ'O
-! L0/ (q) Le (e)
?z'o ? gz'o lol PlBo uoruruoS L=
U)
aLU polr.t >i = (l)q 'uottcunl Llsell oll] ul
EU
loooz-:rveI u ur se ocror.lc ]soq oLl] sr 6urmo;1o1 eqt to L.lctLlM 6 f 'O
U
osaq]]oeuo5 (p) (c) o
Lr loooz-:rveI
z (q) e (E) o
e (p) r (c)
gV gL eE t L 6l ZL gZ: si{e>1 0urnnolgog o
/t 6 s (q) z@)
E
;s{e1 6urnno11o; O 0t 9t 98 6Z
oql orols ol suolstlloc lo loqulnu oqi sr ]eqM o
!- 'sAe>1 CIurnnollo1
l
'LL poLU I = (I),q pue LL pour C)
;
s or.ll Jo uoryosur ro1 6urqord leeur; r.1ltltn suotstlloc (r-t
(z!
+ ! + (>i),tl) = (t '>1)q uorlcunJ qseLl aq] ua^re zz'O o
'i
Jo roqurnu oLlt olelnclec poul / I = (>t)r..t ]al gL'o
o-
o
loooz-=rvoI o^oqe eq1 1o euou (p) O osoL.{t }o euol,t (p)
Ourqseq lesro^tun (c) o 'soorl
0utqseq ulolrun egdLlrs (q) oql olerluorolitp o1 pasn oq ]ou uec onle^
Ourqseq lcaped (e) urnlor lnq seetl fueulq uanr6 oml sereduloc 11 (c)
.;i i
4#*q4fiiA risug Eluuut n
26 Computer Science & lT r Algorithm, Data Structure & Programming MRIIE
@
EE51{
F*hlica*i*m*

0
0 (d) tt
(c)
I

1 1
2 +Z
2 12 2 19) o
o e 23
J 13 ? 13,3,23 -o:. 4 34
4 2 4 o
5 ., tr 5,15
J
-a 5 52
C o 46
g.
6 23 b o 7 JJ
o
7 6 7 3 8
ID

t6 B 1B o
o 15 I o

o Q.27 Which one of the following choices gives a


IGATE-2ooeI m
m possible order in which the key values could
a have been inserted in the table?
Q.26 Consider a hash table consisting of M = 1 l slots -!
(numbering of slots start from O), and suppose cI, (a) 46,42,34,52,23,33
integer key values are hashed into the table o' D (b) 34,42,23,52,33,46
1_

I,
o (c) a6, 34, 42,23,52,33
using the hash function h1:
int h1 (int key) zo (d) 42,46,33,23,34,52 IGATE-20101
{
{ int x; U
o Q.28 How many different insertion sequences of the
x=(key+5).(key+5); key values using the same hash function and
x = x/16; z
=
o

x=x+key, -D
linear probing will result in the hash table shown
o above?
x=x7o11', (a) 10 (b) 20
f
return x; 6
o
o (c) 30 (d) 40 [GATE-2010]
) o

Suppose that collisions are resolved using linear :D Q.29 Given the following inpul (4322, 1334, 1471,
probing. The probe sequence is given therefore U
o 9679, 1989, 6171,6173,4199) and the hash
by (hl(k) + i) (mod 11)(i starts from 0). The !
o function x mod 10, which of the following
integer key values listed below are to be o
o
c
statements are true?
inserted, in the order given. What are the final ooo 1 .
9679, 1989, 4'199 hash to the same value
contents of the hash table after the following o
C
2. 1471, 6.171 hash tothe same value
key values have been inserted in the given -_
@
3. All elements hash to ihe same value
o
order: o
5'
4. Each element hashes to a different value
43, 23, 1 , 0, 1 5, 31, 4,7 , 11, 3 D
f
(a) 1 only (b) 2 only
(a) 43 0 31 1 23 15 7 11 .) 4 o (c) 1 and 2only (d) 3and4only
= IGATE-2003I
(b) 43 0 1 31 7 15 23 11 4 =.
f
o
c Q.30 Consider the hash table of size 7, with startinE
(c) 43 0 31 1 7 23 "15
11 4 3
f
o index 0, and a has function (3x + 4) mod 7.

Assuming the hash table is initially empty, which
(d) Noneoftheabove l
o
of the following is the contents of the table, when
!
the sequence 1, 3, B, '10 is inserted into the
o
Linked Answer tor Q.27 & Q.28
A has table of length 10 uses open addressing with
= table using closed hashing (Linear probing)?
o-

hash functron h(k) = k mod 10, and linear probing. =


(a) B, -, -, -, -,-, 10 (b) 1,8, 10, -, -, -,3
After inserting 6 values into an empty hash table, the (c) 1, -, 3 (d) 1, 10, 8, -, -, -, 3
table is as shown below. IGATE-20071

wvwrrnadeeasypublications.org TITrIE,E ERs*T 0.,Copy,,right


Puhli**ti*n*
, 6ro.suo;rci;lqndrie5epeLu.^ M^." ruul'
ffiSU=S
=Ifi&*{gl
Aere reeur;e ur porots s! [L * u "0'L - u '0]V Izoo
lrooz-=rvsI t -z dot = r dot (o) xr.rleLU reln0ueu1 reMol p lpr.l] oLUnssV ge'O L
(=ZlSXVn = Z dol) ro (Z/lZlSXVyl = ; doi) (c)
i 0
IZISXVI/\ = 7 dot + t dot (q) .o Ioooz-:rnrur]
.@
osor.tlloouop (p) [r + I 'l]C = [[ 'l]e (c) c(e
(l + z/:ztsxvnt E
o aq]
=7 do1) pue (ZIJZ1SXVI = ; do1) (e) o lr 'l + =
[]c ['r]e (q) [l + f 'r]c = [['r]a (e)
C UAU/
o uor-l]'(; + u) x u azts lo C
sr,,llni Icels,,
= rlclq',
Jo+ uor1puoc eql'{lluercrilo posn oq ol sr oceds xr;lEul reln6ueicer E olur lU ore B lo asodsuer]
=
co pue
vxulelir Jl u x u azrs jo I pue vsaclllEr.lr
Lp
otlt +l s>lcels aqj jo qceo ur luouela ]sou:dol : A ,,.,
Uul+,
o
oql ]o uorlecol or.lt o] lurod (7 doi > L dot) Z dol ! reln0ueui .roMol oM] are o.ror.ll leLli aunssv gt'O
l_
pue ; dol solqeuen Ierre eq1]o spuo eirsoddo E (p) Ieoo
ulor1 nlor6 s)jcels oA ] or.l1 'sycels om1 lueuueldu.rr o
[OOOZ-=-w9] e^oqe oq];o auoS
s lo siuotr;ole 11e sosrene: (c)
c
o] posn si []ZISXV/\ tlV Aere e10urs V 6e'O 6
,c
pe6ueqcun s seneel (q)
!
o suorlrsod
Aq Ual s solelorI (e)
leooz-=rvel ,2
,F
(p) (c) f,
:(u '1. 's) osro^o./
xz-l X-(A+y)u o :(u '; + 1 's) esraner
xz + e (q) (1+y)u (e) !
o di L:
O :(>i 'l 's) esra^or
sr l3els srr..ll lo luaurola ue lo olrl->lcels eOerene f
C
o >1
'u > > l- oroqM 'op
or-ll_ S ulor+ LU sa^oular ]etll uorle;ado ciod aq1 o '(enrsnlcur 0u t,rn'
o ocuenbas 6ur,uo11o1 ei..i] soop 1eq7y1
Jo Uets eqt oi (Lu)qsnd 1o pue oll] LUor] pesdela o
! qtoq) | pue r suorlrsod ueemleq s:luouralo ]o qseq
oLUrl oq] se LU io o}rl-Icels oq] ourlop 'L > ur iol 6 ' th
'uorleredo ]xou oq] lo Uels oql pue uorlerodo E ropro oql asrer,ar qcrqnn ([ 'r 's) esrener ernpecord
o ";]s Aere ue uenrO ere no[ esoddng yg'p
o e pue [u
)loels qcns ouo ]o puo oLl] uooMlaq esdelo ! lo lo
spuooes puE 'qceo spuocos X o)iel suorleredo = Izooz-=rve]
o
dod pue qsnd 1eq1 oulnssV suorle;edo 0e0q (p) 0109 (c)
c0
dod u r-uloped uaql pue 'ocuenbos ur sroqunu o UMOL
zo Oeo, (q) }vov @)
lernleu u ]srl aql qsnd e,u esoddns '>lcels Alduue .:
c s![0q][or] cue
oqt qll/!\ 0uryelg L > u ozrs lo ycels e oq S ]ol Be'o o 3Lt] ]
o e jo ssorppe aLl] '0 sso.lppe fuoureuu u.ror1
o 0uryels polols sr {ere oq} teq} pue olqessorppe
lzooz-=-wgl z lo l
g;
C
-e1{q sr Aroueuu ureru or.i} }eql 0urLunssv
ose3 .o
(s :[6s L][ss L]e reqc
lereueO oq] ur papoeu sr ourqceur Oururnl e (p) .?
! '3 ur{ele leuorsuourp
popoou eie eoi] uorssordxe f
L
-oml e io uorle;elcep 6urmo;1ol orl] raprsuoC t0'O
e Ll] lo ]q6!or.l orll se sycels Aueur se (c) a
Ll..l
papoeu o.re s)lcels o^A] (q) LLl Ilooz-=rve]
a
qOnoue sr )cels euo (e) rnol (p) ee;q1 (c)
sllec uorlcunl poppaquo o
oM] (q) euo (e)
o
due lnoqlrnn uorsserdxe ue ojenle^o 01 /e'o d au ozrs 1o enenb e lueulelduur oi perrnber u
E
O
azrs lo s)3els lo roquJnu urnLUrurLU all] sr ]eqM ze'o
Ioooz-==nrur] o
!..-
(p) (c) l
oeLr egrr a Ioooz-ousr]
0 (q) gLW @)
;
c
6er L (p) vezt o)
-?
iAetrc B ur porols [Oe OO]V o (q)
ve} L1ZL @)
o
'001- (_)
sr oroqM'lOlA ul parols s! [O '0]V ll = u st [6t]V ]o ssarppp 0urpe]s oql leurrcop 0Z L L
o
uorlecol ie parols sr Aele aLlI splom [rouleu-r
roJ rapro mor-[q-mor ,, o]e eorql dn soye] pue 0uu1s e srluoulolo qcef 'gL
[t-1g*rlrf '' L sacrpui sell V Ier;e leuorsuoLurp ouo V !t'O
*ir.{}itu*rlq *6j :. i I
>iOAGX j0 t\n
rEsHEt gtlutu H5
-}{}Coi.npurerSri*nce&lTeAlEorithmuOatastructure&Pregrarnnti;rgl MHIIE
ERSTT

Q.47 A binary search tree was constructed by


Q.40 To remove recursion from a program we have
inserting following elements in to an initially
to use the following data structures
emPtY binarY tree"
(a) Array (b) Stack lg
List 27,16, 88, 34, 65, 52,77,93, 4,'1 2, 29' 44'
(c) Queue (d) lg
50,
92
tDRDo-2oo8l lE
= Preorder and postorder traversals of the resultant
Q.41 The expression 1 " 2 ^ 3* 4 ^5 * 6 will O" g binary search tree were stored in arrays A and
I
as
evaluated IE
B respectively. How many elements have same
(a) 3230 (b) 16230 Ia
index location in both the arrays? [Assume
(c) 4e152 (d) 173458 I i arrays A and B start from the same indexl
i'sno-zoonl li Q.48 Consider the followrng elemenis which are
ii.rserted into initially empty AVL tree in the given
Q.42 What isthe maximum sizeof theoperator sta"f
I
H
order.
during the conversion of the infix expression Il-<
B '1, 3, 4
11,7 , 12, 13,2,9,
A + B.C - D/E Postfix?
to Ig
(b) 2 What is the last element in preorder traversal of
(a)1 lil left subtree of resultant AVL tree?
(c) 3 (d) 4 tDRDo-2oo8l l3)
I Q.49 Consider the following C program
Q.43 What is the maximum size of the operand stack I F struct treenode
while evaluating the posif ix expression lo {
623+-3821+.? l= int data;
(a)1 (b)2 15 struct treenode
.left;
(c) 3 (d)
iol o
4 lonoo-aooal
luHlru-zuuo] li
lE=
o
.ri
struci treenode ght;

Q.44 Assume that the operators x, -, + are left | 3


)
*root)
int gate2015 (struct treenode
associattve and ^ is right associative The order | 3
of precedence (from highest to lowest) is ^, x, I i
{
int gate;
+, -. the postfix expression corresponding to li
n nf is l: if (root ==NULL) return 0;
the infixexpression a+ b x c-d e
if (root + data
o/o
lq 2==1)
(a) abcx+def ^^- la
(b) abcx+de^f n
{
13
root -+ data -=1;
(c) ab+cxd-enf n l3
l: gate ++;
(d) -+axbcnndef lrsRo-2ooel
l= )
la
else
Q.45 The best data structure to check whether an |=
L ^t^^^^l
balanced ^^"^athnoao I : root -+ data +='1 ;
arithmetic expression has Parentheses
l'Z return (root --+ data + gate2015 (root -+ left) +
isa l: gate2015 (root -+ right);
(a) queue (b) stack Ii
(c) tree (d) Iist [GATE-2004] l? )
l{ the above code is executed on the foliowing
l=
tree then what is the outPut?
t ttt
I ffi#
-
ouestions I l; I
\
e
- lt
Q.46 What is the maxirnum possible height of an AVL
| : o) (+ 2
tree with 20 nodes?
IDRDO-20081 a) (z) (a

wr,vw.madeeasypublications.org
MrlMH ffiFTSH
wfrs.*hli*ati**x
GCopyright
$r"t1;;ii;eii rq I tfi
H.gl*::l
I tdud JHuQg
=t'tt{rrt
'(requnu lcels soteopult) I
:(75)dod = x !f
Xcets rol alqeuen do] se posn sr ereqm r lcels
{ i
.9 relncryed E ol uo relEp qsnd ol pesn '( ) USna
:(x'79) qsnd .9)
E
uortcunl0urmollol aql 'O are slcels lo JoqLUnN
:(;5) dod = x l o
o 'L -d ol0 xopur urorl d ozrs lo g Aerre e;6urs ur
(((lS) (^rduLa-Icets) 1) elrqm esle c
o s)cels r11 'eI
I
e d nu: +o uorleluotlreld u r eq1 rop rsuo3
{ -_
3
:urnior o
c [(u)g-enenbep'( ;)g-enenbue :suy]
:(,,A1dLua sr p,,) lurrd f
o eowl llr^
c
) .= suoqercdo enenbep pue enenbue ourl r-.lcnu A otl
=
E ,ZL
uo14 ((tS) {lduue-lce1s) 1r lsrl po>lurl elOurs 6ursn enenb lueue;durr ean 11
o
uo14 ((ZS) [1due-yceis) 1r
c
(d
) [( l)O-doa '(;.)O-qsn6 :suy]
.c
c eoret
(x'p)e1a;ep pron o
.9
{ ; llrA suorlerado dod pue qsnd ou-rl r.lcnru Moq
= '11
:(x';g)qsnd o ]srl polurl e16urs Oursn >1ce1s lueueldulr ear;1
E
o
) O
f
!
(x 'g)yesur pron o
a- il3sJno^ fi.II
Molaq uenrO sr 'ZS pue LS s)jcels o
o
om1 Oursn 'p enanb B uorlelueuuelduur uy 'VL !
lo 6
E
( Zll olu! iuou-rolo {ue 0urqseq
o\ t o
[(p) :suy] o lnoqlrl ilol ore suorlecol AueuL moq 'suorsrlloc
!
[r
- tr + r)x ]J == 'r (pt
.@
or-ll olpueq o1 Ourureqc sosn olqel L.lseq ll eg'O
o
[r-tr-rlr9] d,
==1r (c) CE
'sluolrolo uenr0 eql qseq o] 6urqord reourl sosn
\ o
o
r o) ,
z olqel qseLllr '6t ]uollrola ue lo uorlesol or..{} pulj z9'o
ll+lxil=='1 (q) c
\ d,/ o '0 o1 urorl suorlBcol sELi olqei qseq olunssv
o L 0
r o\ , o '9 '91 '02 '6t 'L L 'V6'tZ'BB 'tL 'VV'Zl
ll-tr:.-l=='1 (e) z=
d/ a 'L
\ a L potlr (q + tz) = (l)q
o
.F
ad
iuorlcun] o^oqe uorlcunl qseLl or-.{} 6ursn uanr0 rapro or.i} ur alqe} qseLl
or.l] ul V ece;der o1 uorsserdxo ]coroc olll sr
!
!
eLl] olur por.lseL.l orp ]eLl] s{e1 6urmo;lo} or.l} roprsuoC
L=
0uranol;ol oqi lo r.lcrr16 sluot:olo arols lp^A loels
a eg'o 8 z9'o rol eleo uour.uoc
reqlo AlrelrLrrs pue 'L * OZ ot b uiorl sa.rols l- LLl
U ',,uollelol
Icels 'L * o o] 0 urorl sluourelo so.rols 0 loels o l- = uollElol alqnop,, pue
o ,,Uollelol L = uollelol e;6uts,, aLUnSSV si{e1 uant6
{
lr = ;r11' o oLl] q]!M IAV o>leLu oi suorlelor lo roqLunu lelol
o 'eortr
i++11 E purj 11y ftdure {;1er1rur ue ojur po}rosur
O
asla o ore ropro oq] u! 09 'Zt '91 '9 'V 'Vt {e>1 oq1 ;g'p
d
{ a=
:(1.) ltxe
;
! 1 ur sapou ]o roqurnu lelo] aql oq llrA leqM
,?
1(,,mo;peno 1ce1s,,) puud
uor..ll ,9, tqOlor.l Jo oari IAV ul elqrssod sapou
o
o
O ]o raquJnu LUnulrurur oq] lo prt ouo lo slslsuos
)
o oerlqns 1q0u pue 9 tq6loLl Jo aoi] lrV oU] ul
(---V-)l!
)
elqrssod sopou lo roqulnu urnurxeuJ oqt io lleq
(r 'o d 's) HSnd sureJuoc aerlqns uol r-l3rr_lM ur 1 oorl or.ll roprsuoS 09'o
".r-
16**ri#{}rifir:d
*r. 4oaq4nAA HsI'EI EITIHITI
{*mputer Seisnee & lT * &lgcrithm, Sata Strueture & Frogramrning MHTIE EtrEg
lnr hiae, *":r :tr.;

Let n insert and m (< n) delete operations be T9. ln an adjacency list representation of an
performed !n an arbitrary order on an empty undirected simple graph G = (V, D, each edge
queue Q Let x and y be the number of push o (u, v) has two adjacency list entries: Iv] in the
and pop operations performed respectively in !o o adjacency list of u, and Iu] in the adjacency
the processes. Which one of the following is f_
a
listof v.These are called twinsof eachother.
true for all m and n? -
f

a
A twin pointer is a pointer from an adjacency
(a) n+m<x<2nand2m<n+m C
g list entry to its twin. lt lEl= m and lVl-- n,
o
o
(b) n + m<x < 2n and 2m<y <2n and the memory size is not a constraint, what
(c) 2m <x < 2n and 2m <y< n + m
=
!D

o
is the time complexity of the most efficient
(d) 2m < x < 2n and 2m < y < 2n [Ans: (a)] o algorithm to set the twin pointer in each entry
in each adjacency list?
U
T5, Consider 3 dimensional Array A[90] l30l [40] m
(a) o(#) (b) @(n + m)
m
stored in linear array in column major order. lf U) (c) o(nf) (d) o(#)
.U
the base address starts at I0, what is the location c
a, IGATE-2016, Ans: (b)l
of A [20] [20] [30]? o'
D
Assume the first element is stored at A[1 ][1]11 l. =.
o
l
T10. Let Q denote a queue containing sixteen
v numbers and S be an empty stack. Head(Q)
lAns: (22079)l zo
returns the element at the head of the queue
U
T6. Consider the foilowing infix expression whtch is o
Q without removing it from Q. Similarly Top(S)
to be converted to postfix expression using =
Z
o
returns the element at the top of S without
!
StaCK, !D removing it from S. Consider the algorithm given
(((F + A) :. (R + S))/ T) + (A'r (B + C)) o below.
J

What is the size of stack? lAns: (15)l o @' while Q is not Empty do
o
o iI Sis Empty OR Top (S)< Head(O)then
17. Consider the hashing table with 'm' slots and 3 x: = Dequeue (Q);
0
'n' keys. lf the expected number of probes in d
o Push (S, x);
unsuccessful search is 3, then find the expected o
number of probes in a successful search.
-o else
o
C
o
x: = pop (S);
lAns: (0.7324)l o
o Enqueue (Q, x);
o
q end
TB. Consider the two linked list L1 and L2 given -.
@'
o end
below each of length m and n o
a' The maximum possible number of iterations of
ID
= the while loop in the algorithm is _.
o

What will be the worst case time complexity to


3 [GATE-2016, Ans: (256)]
j=
find address of node'X', where both Iinked list o
C
rltl
will intersect with each other? =
o
(a) O(m log n) (b) O(m + n) {
=.
(c) O(n log rn) (d) O(n2 iog m) o
l
o
[Ans: (b)]
=
o
l

BXEffiffiffi ffiffiS*d
:

rr.rww ma d eea syp u b cat o n s.o rg e Ccipyri$ht


I i i

.:
.l l
6ro'suorle: r
1q nd{seaeper.u'nnnnnn b&md da *HE*!
,:rq61rrido3 g l
g Edud Edwwffi
C
.a
,q
E
o
leooz-::nNrrl a es pue ,e ,, (q)
C
'uelqo;d o ^ "opj:J:l'['xJi1':f;
E 1 ur A ]o luepuocsop
o
otl] lo ozls ot{i secnpol 1t lo uuelqord c= B sr n pue e ur e6pe uE eq lsnLu {n 'n} (e)
oql io lred [iuo sonlos ioq]ra liec qce: =
co lenri s{emle sr siuoLUo}e}s 0urmo1;o1 eq1
: siuorrolo oml seq ur.lluoOle uotsrncer y (p) t
E io r,lclr.lM lESronerl oql ur n 0urlrsrn roge polrsrA
'olnpoul o
c
xolion (pelrsrnun) Mou ]s.rj al.ll aq A lol pue
0ur11ec oql o1peulnter sr lortuoo eq1A1leug pue d I
,E e ur xopen e aq n 1o-l 'oo;l Llcreos lsrryqldep
C
raqlouB roue ouo palEururol ole sourlnorqns o
.a 6ur1lnser aqt oq I iol pue 'e lo lesro^er] lsrq t(
uoLlM repro eures oLli ul paddod st l
o
-q1deperoprsuoC qderOpolcorpunueaqelol e'O
uorleurolul eqilo llE'llec Llceo ur'Alenrsrncer ao
O
aurtnorqns e sllec olnpoLU e ueqry1 (c) -- llooz-=rvel Jo
o
o
o
']srl porepro ue secnpord
ez(P) iu (c)
o
-o
eori qcleos fueurq e +o lesroner] roprour otll (q) 6
G:,F 7
E (q)
'tq0u eql o]
o
,z I - uI; (e)
o
!
opou acueleqlo-]no aql 0urlelor [q aer1i,1y .a
(e)
= iseotilon u 1o {un' "'zA'tn} = 1 }as
pocuelequn Uollo+el e acueleq isnuu eg o
6
t
uenrO e lo ]no potcnilsuoc aq uec (pelceuuoc
'luauolels osle] o
o
Aluesseceu 1ou) sqder0 pelcorpun {ueuu nno;1 Z'O
eq1 {rluepr 's}uouJoleis Ournnol1o1 eq1Ououuy g'O Z
-
o
o
B llooz-=rveI
leooz-=rve l o
Z
@
osor.ptoauoN (p) (n l)p > (n ])p (c)
/9r0t2v986 (p) 6B/99rez L0(c) C
o
6 (n';)p < (n L)p (q) (n ;)p > (n !)p (e)
/8699 LrrZ0 (q) 6sgrZtOtel (e) .e UO
! sr
sluor!aleis
aooj] lue]lnso; eq] Jo acuonbes lesronerJ -
L
alcoroc ]n
a 6u rnno; 1o1 or-1l r L.lM'
rapro-ur eqi sr ]eqM s;oquJnu lernleu uo 6uuepro lo qc les.ronerl ]sr U-l1ipeor q oLl] (s
!l
LJ 0uunp A aroJoq poirsrn sl n ur Alenrlcodset
lensn olll sasn oor] qcreas fueurq eq1 oari L1oreas o il 'e on
fueurq ftdue Aplerlrur ue oluuopro ]Er.ll ut pouesur o
A pue n o] r uuori sqied lsolroqs oLll lo (o
ae Z'y'6 '0 'g 't '8 ' L 'q '/ sroquinu eql esoddng t'O a sq16ue1 oq] aq (n'r)p pue (n ))p 1e1 r opou e uror+
6
uo
E 0uryels ouop oq e ]o lesro^erl lsrrfr1lpeorq e ]ol
O
loooz-=rve l o [(
a- 'g qderO pelq6remun polcarpun uEloprsuo3 L'O
1 ur iue;ed aures oq] onell lsnur al
c
pue n uaql e ur e6pe ue iou sr {n 'n} Jl (p) '-o
^ o
o suolls3no ]f,lorlf 3ldlllnn
IUI O
sr n uaLl] g ur e6pa ue ]ou sr{n'n}11 (c) o fu1
leoie
lu
te
,u
i{ct
tor
{c
r{derD pue eerl ot{
a0
UE
!!
H
tr c
??
J4-

Q.6
i !:_*fur*r Science & Argorithm, Data structure & programming

A data structure is required for storing a set of


lnFxf,lE EFI$H
I
Which one of the following sequences of keys
integers such that each of the following can be the result of an inorder traversal of the
operations can be done in (log n)time, where n tree T?
lo
is the number of elements in the set. lo (a) 9, 10, 15,22,23,25,27,29,40, 50, 60, 95
1. Deletion of the smallest element. l€
l= (b) 9, 10, 15,22,40,50,60,95, 23,25,27,2s
la
2. lnsertion of an element if it is not already l= (c) 29, 15, 9,'i0, 25, 22, 23, 27,40, 60, 50, 95
present in the set. ls (d) 95, 50, 60, 40,27,23,22,25, 10,0, 15, 29
Which of the following data structures can be lq IcATE_20041
ll
lo
used for this purpose? l= lo Q.10 Suppose a binary tree has only ilrree nodes A,
(a) A heap can be used but not a balanced I]
lo B, and C and you are given that the post_order
binary search tree
l<
traversal for the tree is B-A-C. The exact pre_
(b) A balanced binary search tree can be used is order traversal for the tree is.
ls
l(n
but not a heap I< (a) C-A-B
lr
l.
(c) Both balanced binary search tree and heap lu (b) A_B-C
can be used IB (c) C-B-A
(d) Neither balanced binary search tree nor l; l (d) a definite pre-order traversal cannot be
heap can be used irl determined from the information given

ltsRo_200e1 Q.11 Level order traversal of a rooted tree can be


Q.7 Postorder traversal of a binary search tree is l5l done by staiting from the root and performing
given as foilows 35, 40, 55, 60, S0, 100. Then
l:lE I

I
(a) preorder traversal
the given tree is: (b) inorder traversal
(a) Minheap tree (b) Maxheap true
l=l (c) depth first search
(d) breadth first search
(c) Strict binary tree (d) None of these lrl
IGATE_20041
lE
Q.8 Consider te following graph: til I

la Q.12 I
Consider the label sequences obtained by the
lE I following pairs of traversals on a labeled binary
lii
I^ I

tree.
lsl Which of these pairs identify a tree uniquely?
l: I
1 . preorder and postorder
=l
ol
ol 2. inorder and postorder
,l-l=l 3. preorder and inorder
<l
al 4. level order and postorder
il (a) 1 only (b) 2 and 3
A possible Depth First Search (DFS)sequence
=l
=l
f,l (c) 3 only
ol (d) 4 only
for the above graph is
3l IcATE-2004I
(a) d, e, b, a, c, f, g (b) b, a, e, c, d, f, g
(c) d, b, a, e, f, c, g Q.13 The inorder and preorder traversal of a binary
(d) b, c, d, e, f, g, a =l
ql tree are: d b e a f c g and a b d e c f g
IDRDO_20091 respectively. The postorder traversal of the
EI
Q.9 Postorder traversal of a given binary search tree, EI
ol
binary tree is
rl
T produces the following sequence of keys (a)debf gca (b) edbgf ca
10,9,23,22,27,25, 15,50, 95, 60, 40,29 (c)edbfgca (d) def gbca
IcATE-20071

wfia;hfi*xti*tta @ Copyright
.::-.r'rr":::':..].::,:. i.:., :: .. *tj{rt1g3l;{i*i{{6ffi
,$rorlqqrs}.'.}sluft-eeepetu;111 ff;fr5' atrUUI ,,1H6.u{do: o
BB' LL'99'zz'vr' tL'te'9q (p) 'xauoA oLUes L
'99 (c)
LL'sB'vv 's9'zz 'tt 'or oLl] te potoor oor] Slg {ue 1o qldep eql se
'99 (q)
88'LL '99 'L t 'VV'ZZ'80 c Llcnu se ]seol ]e sl xouoA E ]e palool oo_11
.o
'LL'vv 'zz'LL'rr 's9 (e) a
BB '99 .a (qcreeg lsrrl qldeg)g3q ,{ue 1o qldep eq1 (e)
E
4lesraneil reproerd prlBA e st o e
o 6oslel sr luourotels Ournnol1o1 oq] lo qctqM / L'O
C 0
6utmollo1oLlt Jo rlcrqM BB pue LL'gg '99 '17 'tt o
'ZZ'll sonle^ oLll suretuoc eoli Llcteas fueurq = lzooz-rrve l A
V 0Z'O 3
o (p)
c (uu)o (u + u)6 (c)
osoq] +o ttV (p) o pue u 'c '[ (c) f l
(tr)o (q) (u)o (e)
u pue c '['e (q) c pue [ 'e 'u (e) co
= 'ft rxe;d u.roc or..url ser-tr
'oar] o^oqe al.ll ul , pue E
o se6pe u pue socruo^ u uo qderO polcalpun
t 'Z 'l sroqurnu oq] lllj ueql D>lcfourleolutqqp q
6
uE ur sJUouodluoc polcouuoc io loqulnu
.g
sr ooji o^oqe oll] lo leslo^eJ] Joploul oq] ll
!
eq1 0urpurl ;o1 uqluo6lB iuatcUa ]soLUoqI gL'D
o
.2
E 0 Z(p)
l , L
o t t v z@)
!
o
o Z e(q)
f, L I
E
o Z v t s(e)
o At
o
o o CEV O
-o
:sopoc
6
E
rlc,reos q1da6 'y lv
o 1sr11
o
-o
,@
tanbuo3 pue opr^rC 'e
eerl 6urnno;;oi orll loplsuoC 6 L'O c
6uruuuuer0otd ou-reu{g'7
o
qderO eq1 ur qled 1se0uo1 oql (p) 6 poLlloLu Ipeerg '1.
o,
l lo so^eol ore ieq] zo il1sll
-: 0
sopou esoql Aluo o] M rxorl qled tseUoqs oql (c) qted ]seuotls s,p{o13 'q
o eq
qderO eq1 o uuq1uo61e slueuodu.roc polcouuoc-tE'C
3
ur xouo^ fuena o1 M uroJ] r.lled tseyotls oqf (q) zo eetl 0uruueds LUnLulutLU s,leISnl) 'g
U;
sacriroA C uollecrldrl;nu xuleu s,uossetis'V
.o
red fuane ueamleq qled 6
tro tsoyoqs oq] (e) .O t-ls!-t
'0urlnduroc lo1 E :slsrl
orll Molaq uenr0 sepoc aq1 6ursn loMSUe
L=
ornlcnrls elep E sr scrE eerl aq1 {q pouiloJ I ool} a ]co.r.roc or.l] ]colos ll-is!l r.1]lM l-lsll qciey\ gL'o
eq1 's1q0rem e0pe lenbe qlrm qder0 polcolpun Lll
U
'polcouuoc 'pelq6renn ue ul l apou octnos o lr,ool-=rvgl -ol
qder0 e 1o slueuoduroc polcouuoc
e rrloll lPsio^eli
Sl8 e io sc]e oojl oLll loplsuoC 8I'O o ra
o
pull ol pasn oq uec Llcreos 1srr1-q1dep (p) ,V
'xt.lleul 6 paicnrlsuoo ,4;enbrun
E
Acuecelpe ue Ljlrm paluasetdar sr qdet6 o
o aq ]ouueo aerl {reurq oq} 'oor} Ileurq lvt
y G 'A)9 qderO e ur oLUr] (r1)9 sa>1e1 ggg (p) 6 e rolo sllel xrilsod pue
xrie:d eqi uenr0 (c)
a= 6Z
elcIc -;: qderO e;o slueuodutoc polcouuoc 96
-?
ou seq qderO sueou; oorl SIC e ur se6pa pult ol pasn oq ]ouuec r1cleos 1srr1-qlpeetq (q) 6Z
o
o
ICeq ]o ocuasqe eq1 'qde.i0 polcolp e rol (c) O 6urruu-ier6ord 9b
enbrun sr
o crLueu{p 6ursn {lluetc41o porriroped eq
socruo^ oml uool loq qled ]seuoqs oql uaql uec uorlcnrlsuoc oalJ Llc.leos fueurq leurldo (e) ouj
]L-l0rann
tcurlsrp eneq qderO e ur saOpe 1;e 1r (q) aosle] sr sluau.rotels 6urnnol1o1 oq] lo euo L.lclr1M t f 'O s,{
:5|l!,qq.wlewsi.i*la*tllqg.|d1!ffillflP
i(l
;*ts 4ooqryalu fi$U=- 31.IUIU H
( I
f*rnp*ter Sri*ne* & lT * &lg*ritknr, sat* struetHre & Prcgra:r'tmiseg $MMMH EffigH
ii*hii**ti***

Q.21 ln delete operation of binary search tree, we performed starting at s Let T be ihe resultant
need inorder successor (or predecessor) of a BFS tree. lf (u, v) is an edge of G that is not in T,
node when a node to be deleted where it has o then which one of the following CANNOT be the
both left and rrght child. Which of the following o
o
value of d(u) - d(v)?
!
is true about inorder successor needed tn delete (a) -r (b) 0
a=.
operation? =
a (c) 1 (d) 2 lAns: (d)l
(a) lnorder successor is always either leaf aC
node or a node with empty right child.
-g
o
o
T2. Given two inputs BST and Min heap tree v;iih n-
(b) lnorder successor maybe a an ancestor of Is nodes. To get the sorted order which is better
the node o and how much time?
(c) lnorder successor is always a leaf node. o [Ans: BST and O(n log n)]
(d) lnorder successor is always either a leaf U
node or a node with empty left child.
n'l
m T3, Given an adiacency-list representation of
a directed graph G(V E). Then how much time
Q.22 The worst case running time complexity to -U
C does it take to compute the out-degree of each
a,
search for an element tn a balanced binary o
E lAns: O(n2)l
search tree with (2n)! elements? -.
o
(b) O(n log n) -
(a) O(n") I
zo T4. lf the graph G(V, E) is represented using
(c) o(n) (d) o(n2) { adjacency matrix then to find universal sink (in-
U
o degree is V-l and out-degree is 0).
=
fffim Numerical Data TUpe Z
o
oD
[Ans: O(n3)]
HJ 0uestions T5. An operator delete (r) for a binary heap data
^. o
J,
structure is to be designed to delete the item
Q.23 Assume the preorder traversal of binary tree is o in the r'-th node. Assume ihat the heap is
"abc". f-low nrany total different binary trees are oo
implemented rn an array and i refers to the I
Bossrble whose postorder traversal is "cba" with
,
ID
th index of the array. lf the heap tree has depth
ihe given preorder traversal? U
o d (number of edges on the path from the root
o
Q.24 Apply DFT on the graph grven below and find
!
o
to the farthest leaf), then what is the time
o
minimurn number of times backtracking required C
o
complexity to re-fix the heap efficiently after
o
(starts from A). o
o
the removal of the element?
C
-.
(a) q1)
@
o (b) O(d) but not O(1)
o
-' (c) O(zd) but not O(d)
ID
= (d) O@zd) but not O(2d)
o
[GATE-2016, Ans: (b)]
= {
f T6. The number of ways in which the numbers l,
o
C
2, 3, 4, 5, 6,7 can be inserted in an empty
=
o binary search tree, such that the resulting tree

Trg Yourself o
has height 6, is--_- (Note; The height of
l
!
o
a tree with a single node is 0).
T1. Lei G = (V E) be a simple undtrected graph, 3
@'
[GATE-2016, Ans: (64)]
@.
and s be a particular vertex in it called the source. o
l IIII
For. e d(x) denote the shortest distance
V, let
in G from s to "x. A breadth f irst search (BFS) is

*&ffiMH ffiHXffiH
P*hii**tii.rlr*
s**lis i,qrld
6;o:suorlmrlqnd{seaapeu,namil lq61"rddo3 sr 1
Hst EI mtrffiffi"a
lsetcuenberl eql
C
arots o] 6 rol [em ]soq ol.lt aq plnom ]eqM 09 .o epoc pa;tdtuoc
.a
onoqe 6rocs l..l3po 1o Acuenberl aql sluud ueq111 E or-li t.uor+
o lortuoc +o Moll oqi rolur ol olqe aq (q) ll
o
siuopnts 00q lo sorocs eql0utluesetder (96; 'g) E suerOo.rd paluoput eneq (e)
a 11erur
'=
e0uer eql ur sre6elur 00g ul spear d u-ret6o;d y l'O ol sr 0urulLuer6ord pernlcnlls lo 1eo0 eq1 0'D t(
o
c=
lsooz-=.Lvel =
o
c laooz-::nNrl ]o
{;uo y pue 'L (p)
t Aluo y pue Z 't (c) olqeue^ oures ]o esn eldt11nu (p)
E dd
Iluo 7 pue
; (q) ApoT pue I (e) o
raUlluopr ot.ues ol.l] 0urneq solqeuen e1dt1lnLu (c) ,it
c
ocuelrior1ur1oecuesetd eq1ut uustqd:ouA1o6'7 6 ,t
,E onlen olues eq1 Ourneq solqeue^ e1dt11nur (q)
olnr -o
.c uorlecol
edAfqns qlrm pe;dncc {}Ladord etes-edA1 'g l t(
o fuoureur ouJes oqlOurneq solqeuen eldt1lnLu (e)
sseuped{r[t]ctr]S 'Z !
o oi sroler seOen0uel
O
uorle;nsdecuo pue uollcerlsqv ' L cof
0ururr.uer6ord Z'O
o-
lo lxeiuoc otl] ut 6utsetly
o
iseOen0uel 0urr-uuuer6ord peluettolcelqo ue o
,o
,o sornleo, terluosse ere 0urttollol aLll lo r-.lc!t{M g'O o
loooz-:rvel
E epou edI11o
o lOl
lqooz-:rvel co oinlcnrlsesr Llcrqn Jo]uoulala qcee'{ele ue (p)
e^oqe oqi lo tte (p) .a O
= sluoulalo 6 g- 1o {ette uB pue
o
o^rlerelcap ere qioq (c) E
d ']eoll e
re6elur uE :splorl I ]o ernlcnrls e (c) 10
o
snlnclec-y uo poseq ere qloq (q) o t-ii
Z sluourolo g 1- ;o Ierre ue ol relutod
enOenOue; lernpecord eie qloq (e) to -t
o e 0ureq plo4 qceo 'splell Z lo ornlcnrts B (q)
sr se0enOuel leuoticun] pue seOen0ue1 SI
o epou ed{} }o erntcnrls e o}
Z= LUE
0uru-rurer6ord cr6o1 io u(yedotd uouruloc V g'O a
C relurod e sr LlcrqAA luoulolo qcee '{erte ue (e)
Io
o el
6 oq o] s eullop
lsooz-=rvol ,9
l
a ('
o^oqe eq1lo q1e (p) L :[Ot]s. opou tcnr]s [
a :{
oslo auou ]nq 'posn oq uec 1l uo poullap U
U :lteou -ul
suorleredo eqt Aluo qcrqm lo+ edft elep e (c) o
:l lul 6u
polerluelsur oq louuec teqt ed{l eiep e (q) o
o )
sselc lcerisqe ue se euues (e) d
[ (z
st(ICV)ed{1e1e6 }certsqv uV ,'O EO opou ]cnrls
o qci
!- suorlerelcop 3 6urmo11o1eq1 L'O
af, oLu
lvcoz-=rve l c
o
'=
stuouroleis OlOe ]o osn eql ptone (p) lo
o
o suolls3no 3)!or.tf 3tdlllnru
]xei uer0ord O
alli Luoil lorluoc lo Moll otll ralur o] elqe oq (c) o ffiffi [(u
lo
-u
t(p
6u!urr.uer6ord aq]
'l
lUE
E
J* Computer Science & lT r Algorithm, Data Structure & Programming MRDE EtrglI
Fubilcatii:*s"

(a) An array of 50 numbers Program P10


(b) ,An array of 100 numbers {
(c) An array o1'500 numbers x=-]0;
o
(d) A dynamically allocated array of 550 o rr-2.
J-vr
o
fl
numbers funcl(y, x, x);
(o
=.
J
lGATE,20O5l f print x;
(h
c print y;
Q.8 Consider the following C function. .?
o
o l
float f, (float x, int y) 3
funcl(x, y, z)
{
{
float p, s; int i; E
for (s = 1,p = '1,
i = 1; i < y; i++)
lz y=y+4;
tb
lm Z=X+Y*Zi
{

P*=x/i; lx i
s+ =pi t;
l.
(a) 10,3 (b) 31, 3
lo
la (c) 27,7 (d) None of these
i ls
return s; i5 IGATE-2001I
l-=
) o Q.12 Consider the following program
{
For large values of y, the return value of the U o
Program P2
function f best approximates var n:int:
zo=
(a) Xv (b) e* t
procedure W(var x:int)
s
(c) ln(1 + x) (d) x' l
q
begin
IcATE-20031 X = X * 1,
=
Q.9 Assume the following C variable declaration o
o
print x;
o
int. Ai10l, B[10] [10]; end
3
Of the following expressions !, Procedure D
o'
1. A[2] 2. A[2][3] o
o
begin
3. B[1] 4. B[2] I3l !
o
var n:int;
o
Which will not give compile-time errors if used
c
o n=3,
o
as left hand sides of assignment statements in
o-
q
w(n);
a C program? End
(a) 1,2 and 4 only (b) 2,3 and 4 onty o
=
o
begin \\beginP2
(c) 2 and 4 only (d) a only tr n=10;
sf
D.
IcATE-20031 o"
3 end
Q.10 The C language is: lf the language has dynamic scoping and
f=
(a) a context free language o
parameters are passed by reference. What will
(b) a context sensitive language =
3
o be printed by the program?
(c) a regular language (a) 10 (b) 11
(d) parsable fuily only by a turing machine o
=
!
l (c) 3 (d) None o{ these
o
IGATE-2002I i
@'
IGATE-2001I
@.
Q.11 What is printed by the print statements in the o
l Q.13 ln the C language
program P1 assuming call by reference nt (a) at most one activation record exists between
parameter passing? the current activation record and the
activation record for the main

mnlrH Etrslt :, o Copyrighg,


i)l:fo{is:s11***
i(l{}ll**:{tild.".,.,',",".,,.,""%
{
:(u ',,p %,,)Jiuud :Z+(Z-u)lutnlel
{ cl
:u=l l
jul-u=u st (g<u) lt
3t
osla El :LUrnler(0=>u) l!
JU_LU=LU :0 = I lur crlels
3l )
(u < u)1r € (u 1ur) 11ur
B
I :uotlcunl3burnnoJlolalllroptsuoC
) E I gl.O
(u = ;u.r) elrqm
c
!l truu,-=rour
lI=u t_
jx=t! = apoceurllcBtu
;l raOuo1
^ 6urie;eue6:a;rduoc oq] ut sllnsol ll (p)
l*0<Apue0<xoLunssv+/ ;lE I
:({B 'xB ',,p% p 7,,)iuecs EI sutetOord
,LU ,^ ,x ,i ;o1 perlnber fuoureu oqt soseorcut (c)
]!
:u lur I "r,
.I suerOord oqi lo ou.ll Ouruunt eql seseelcur (q)
) I I
Ouleul
i I suer6olO {rren o1}lncl}1p orotu }t seleul 1r (e)
uerOord 3 Ournnoglol oli] loptsuoC g [.O g I snecoq Inluleq
! | stlueurelels ,,o1o6,, eq] lo asn polculsoJun uV g[.O
lsooz-:rvel
0'B'r'0'z (p) vL'8'?'O'Z o) $l toooz-=rvet
o'z'o'r 'B (q) gl seYiqs; seu{qs1. (c)
vL'z'o'v'8 @)
sel{q
!o]
--r"r 7r y
| (q)
\Y,f sey{q
oa+t\V 77 (e)
C'C, \V)
l1uud uret0otd anoqe oLl] soop leqg ;9 II sr 'suorleloptsuoc
-E
I Juou.ru6rle Ouuou0r ,l olqeupn
{ lueuterrnbet A:ouietu eq1 .{lenrlcedsar
:(LUns ,,ulp 7,)guud I I ,ol
rl 'selAQ g pue sey{q ,sei{q
=| 7 7 {dncco 0uo1
t(uns ,e) oo1
Pue teol1 'Uolls edl{l eqi lo slcelqo ]eL.lt oLUnssV
j0=ulns'B?OZ=eNl 2* |
!l=t 'rI
.+ I
l 3i
0 ureu 1ur al :n{
=_l :z 0uo1
{ !;
c
:(>1 ',,p puud E I :^ ]Botl )
"7.,,) 6l
:(urns ,l uolun ll
) oo1 ;t9 I
:l+ulns=LUnS il
,t fe]sPoqs ]
-l
:Ollu =[iglo/oU=\ ?I ]cnrls
uorterelcop3Ournnollolor.llroprsuoC
:urnlol (0 = = u) ]l *l rL.O
:0=[,0=y]ul [zooz-=.rvet
EI
) E poJlec oq uec
(uns 1ul ,u lur) ool pron
I
=l uo;tcerl o^tsrncoj oL{l
[| ojoiaq }ce}s }uolo}irp
r-uer6otd-3 Ourano11ol eq1 r"p,rro3 2 ffi 3 e uo pa^es oq o] uotlcun] e^rsrncol oq]
|
,o1 p.rocor uotle^l]oe aql satrnber uorsrncer
lzooz-=rvel H | (p)
(p)
ecuenbes Ourlyec uot]oun1 1enlce aq]
Br 6 (c) 5l
;. uo spuedop solqeue^
/ (q) I 1eqo161o {lrlrqrsrn oll} (c)
e (e) ecuenbes ourglec uotlcun] lEnlce oLll
a(q) I lo ontp^ oqt sl leqM rE
:- II 'r-"r-- "Y+
,o spuedep uleul aq] roJ plocol uollBntlce
I
{ or.l] pue p.loco./ uotle^tlce ]uoJJnC oLll
:t + (;- u) I urniet uoomloq sploco.l uollentlce
Jo loquJnu aLll (q)
!;
d.L 4aaq4jo/t4 $r".i*t}3*lisli',#,w
ij
liSHA AUHUI *a=
i Cornputer Science & lT r Algorithrn, Dat* Strueture & Programrning .ry'w MRIIE EN55
,5ffi P*htri*ati+rps

The program comPutes Q.23 main 0


(a) x + y, using repeated subtraction t
(b) x mod y using repeated subtraction void *vp; (
o
(c) the greatest common divisor of x and y o
o
char ch = 'g'
char *cP = "goofY";
!
(d) the least common multiple of x and y L
o
IGATE-2004I = - int j = 29'
a
gc vP = &ch;
Q, 1 9 Consider the following C function o
o printf("%c", . (char .) vP);
int f(int n) l
l0 vP = &i;
t o printf("%d", .(int .) vP);
staticinti=1; o
vP = cP;
if (n > = 5) return n ;
U printf("%s", (char.)vP + 3);
n=n+i; m
m
)
i ++; a
-o (a) g20fy (b) goofy
return f (n) c
o (d) none ofthese
;
(c) go2fy
o
) D
t.
o For the following Program
The value returned bY f(1) is f Q.24
I
(a) 5 (b) 6 zo main( ) {
(d)

-o incO; incO; inc();
(c) 7 8
)
IGATE-20041 t_=
lo inc0 {
E
Q.20 Consider the following C-function: o static int x;
int f (int a, int b) o printf("%d", ++x);
J,
{ )
o
if (b > a) return (f (b, a) ); o
o the output
else if (b==0) return (a); lg) (a) prints O, 1,2
else return (f (b, a%b) ); (,
o (b) prints 1, 2,3
)
- o (c) prints 3 consecutive but unpredictable
Which of the {ollowing will be returned by the Co numbers
c
8, 30)? o
function call f(1 o (d) prints 1'1.1
o
(a) 2 (b) 3 o
C UNUEE-2ooeI
(c) 6 (d) 8 -.
in
o
IDRDO-200e1 o Q.25 main 0 {
:s ;n1i = 2581
Q.21 ln a C program how many bytes are required to J

o int*iptr=&i;
store the string "john" in a charater array" .) iptr), .((char .) iptr + 1
printf("%d%d",.((char ));
(a) 2 (b) 3 =
1
f, )
(c) 4 (d) 5 o
(a) 2,1 (b) 2, 5
IDRDO-20oel f
o
(c) 1,2 (d) 5, 2
{L
Q.22 Consider a declaration o
l Q.26 main 0 {
inta=5,*b=&a; c
o
int r = 300
printf ("%d", a.b); f
6. *ptr (chaf)&i;
9. char =
The outPut is o *++Ptr
- = 2;
(a) 25 (b) garbage
printf("%d", i);
(c) 5.addressof b (d) error message
i
UNUEE-2ooel
:-;:j:rl.:i:'.i. :
61".r*rlri3{3qixd
6:lorsro; 1e:1 q
1
nd{s eaap e ru, n*14q E=l{=
: IJU{
:=lal{rtl
dgHE ,tHFU,{d9,;,e
osoqlloouoN (p) 7xc+Q (c) (++l:01 >rlg=r)tol
z-cxQ (a) c*q (e) :l'0=rlul
'Zt sB ]ndtno eql stuud opoc 'epoc 6urmollo+ or..li roprsuoC 6Z'O
,C, o^oqe oll] ]l 'X luaLuolels 0urssruu orjl pull
{
loroz-arvel
vL'zL 'Ll (p) 71'81 (c)
:(q',,p2,,)*uud :11ne1ep
:(c ',,p%,,)tlurrd :g ese3 YL,U G) TI,ZL.tl (E)
:lEatq :9 aseC ers pue SS 'ZS 'l-S sluouratels 1o e0erenoc
:(q ',,p2,,)lur.rd :y ese3 sarnsua Moleq uenr0 salrns ]so] eql lo r.lclrlM
:(e',,p7,,)purid :7 ese3 p-cpuBQ=ie ,L
) P=i CpuPq=B ct
(X)rtollMs ]3urlsrp llE orE p pue c 'q'e : zt
lenbe ;1e ore p pue c 'q 'e : LI
'epoc"e=c'z=q'zt=PlUl
6ur,nnollol or.{} roprsuo3 'uenr0 ]ou ore sonlen lcexo
Ze'O tt
aLll 'p pue c 'q 'E solqeuen lo sonle^ oLl]
d-b (p) b+d (c)
pallstles satyedord ^q
surol ur pesserdxe ere
or"li +o
e-b (q) 1-+d (e)
y1 pue g_
oloq uanrCI 'ZI'lL sasec ]so] otlf
lsrolurod ol lcedser a
^
l-.llrl loarocur sr iuaurolels 6urnnol1o1aq1lo r.1clqM puo
:,,S
:[1]e6 = [
:[g]ep = i {:}rxo :0S}oslo
:b* 'd* '[Ol]e {:zS} (p - - c)}r osto
tut
'epoc 6uranollol or.l] roprsuoC [:1rxo :;g] (q = = e) ll
Ig'O
urOaq
{ :eOelenoc luauloiels
:(76 - ;6) urnler rol polse] oq ot sr u.lerOord 0urmollo; ol-ll BZ'O
| (;6++") e;rqm
: Ld = Zd* leqo
loioz-rrvel
z0 (p) r0 (3)
l LZ G) ZZ @)
(;6" reqc) {seeepeur 1ur
{
{ :o uJnlol
:0 uJnlor :([ 'l ',utpz p"7.,) puud
: ((r1s) Iseeepeuu ',,p7,,) puud :([r'm)l
,,9L0zalEe,, = lis* lellc )0 ureur 1ur
1; = ['6 = 1191
)
( ) ureuu iur {
'.2 = d*
luer6ord 6urnno;1o1 eq11o 1nd1no olll st leLlM .Oe'O
; lb=d
c
/L (p) sr (c) '-o ) (b. tut 'd.lut)l pto^
(q) a <r.l'otpis > opnlcut#
rL LL (E) o
()
df lo onle^ oqt aq lllM ]eqM o ilurrd urer6ord 6urmo1go1oLll soop raUM LZ'6
iZ=+x s00 (p) eee (3)
(++xBBZ%!)tl 000 (q) ege (e)
$u+l;8sttq et{:{ .l,:
4oaq4joAA risua aClHEI
4fn Computer Scienee & lT o Algcrlthm, S*t* Structure & Progranrnruing TNHBE ESISH I
FrrllJi*.r,. +;sl.

Q.33 What is the output of the following program? The output of the above function on input .ABCD
int f(int a) { EFGH" iS
printf ("%d", a++); (a) ABCD EFGH (b) ABCD
o
return (++a); o
o
(c) HGFE DCBA (d) DCBA
C
] :,
(o
maino {
J
a: Numepical Data Tgpe
a
intb=1; g C
Questions
o
b = f(b); o
3
b = f(b); s Q.36 What is printed by the following C program?
o
b=f("i +f(b)); void main( )
o
) {

Code:
C]
m int c, *b, **a;
m
(a) 1335 a
c=4i
(b)1357 -! b=&c;
C

(c) 2335 g
o
a=&b;
o printf ("% d', f (c, b, a));
(d) 2468 -.
o
f
I )
Q.34 Consider the following C program zo int f ( int x, int *py, int ** ppz)
# include <stdio. h> U
o i
void f(int x, int * p) { l inl y, z;
*p -x; !
Z
o **ppz +
= 1;
**ppz
x =10; TD

o
z= i

) f
"py+=2;
int main ([
@
o y = *py; f
o
o wr-?'
inta=5, b=6; 3
s return(x+y+z);
int *p - &a, **q; U
L
o )
*P=20;q=&p; o T
!
f(a, &b); o
o
Q.37 The output of the following C program is
*Q = &b'
E
o
o
void fl (int a, int b) {
o
*n - Qfl. o int c;
H-vv,
c C=di a=b; b=Ci
printf("%d, %d", a, b)', =
@-
o
o_
I
void f2 (int.a, int -b)
]
=
s {
What is the output product by above C program l
int c;
(a) 10,20 (b) 20,30 o
l
' c=*a; "a=*b; *b=c;
(c) s0, 10 (d) 20,20 )
=
f
o int main( ) {
C
QA5 Consider the following function written in the C Tt
J
o int a=4, b=5, c=6;
programming ianguage.
f1 (a, b);
=
void foo (char.a) {
o
f f2 (&b, &c);
if (.a &&
*a != ") {
c
o printf("%d",c-a-b);
l
.!.
foo (a+1);
-'
putchar (.a): l

)
)

m*se$H Effi*sH
Fxhii**ti***
Hqr-x:t ffi!'tHltt rq6t.rr(do: O
IEorq
{ (,,auo,,)puud: aseC
L
l(g)1unoc (,,orez,,)purrd :.]lnBlep
]
)
OureLu pron (r) qclrms
{ l0=rlur )
'.(p ' ,p"t",)ltuud ( )ureu.r
:(;-u) lunoc (i < u) lt auer6ord 0urruio;1o11o 1nd1no oqt sr ]EtlM 'Z,t
:++p
'.(p '
,pv",)ltuud [(.u)g :suy]
:(u ',py",)11uud {
{
:L =p lut cr1e1s)
{
(u 1ur)1unoc pron
(t)puud
;uer0ord (uolL=Drol )
3 6urmo11o1 aq] +o ]ndlno aLll oq lllM ]EqM '9r (o==tpouu)1t )
(u ol t = !).rol )
1(q) :suyl
(u)v
o (p) ]ndlno ou (c)
uortcunl 6urnno1lo; ;o ftrxeldLroc orxr] or1l pulj 'g-
&duue 1ou sr 6uu1s (q) ,ldLue CIurr1s (e)
sr urerOord onoqe eq1 1o 1nd1n6
{ il3sJno^ fi.Il
(Z u)V + (L - u)B urnlor oslo
-
(;)urnler(l>u)lr )
(u)e
{
( I - u)e + (Z - u)V urnlo.l osto
)
Ouleu 1ur '9t- (;) urnger (l > u) 1 )
(u)v -.--
:((pron) (.)tut 'IZ](")1ur)(rid.) plo^ 't __
(g)V ttec uorlcunl 0urmo1;ol eW ]o lndlno eq1 pu13/69'g ,:
:(rut)(((rut) (1.) pton'iut)q.) pto^'E
:[9]((X[S]x.).)reqc'7 {
"*/'
:(X[](0x.).)reqc ' L :0 ulnloj
'vt :((g 'e)l ',p7.,)1 lurrd
suoriBrelcop 3 6urnno11o11o 0urueeu oq] olu6
:{g'tt 'v't,L'L 'zfi = []erut ]
ld* '1-
ld lsuoc* lul 'Z 1ur lsuoc ( ) ureLu 1ur
suorlEJelcop 3 0urmo1loi 1o 6urueauu or.l] oluM '8r
{
[(;.)g:suy] :(t - u 'L + B)l - e+ urnioJ oslo
{ :(i - u' ; + e)l + e+ ujnlol (O == ZoTo e.) I es;e
t :0 urnlor (O => u) ,l )
)jeolq (u 1ur 'e* ]ul)l ]u!
(,,ee;q1,,)11uud : g ese3 <q'orpls > opnlcur#
Yeorq lurer6ord
(,,om1,,)pur.rd ; Z eseC 3 0urmo11o1 eqi peluud onle^ oq] sl ]eq6 ge'O
^q
t& t**iFi*liq*{j
4**q4lcn4 ffisIlEI EI{IHTTI
d""1
il
i C#mputer Science & lT r Algorithm, Data Structure & Programming MRDE EM5**
r:$.
"r ..
,;i
F: r.l*;ir ft:i**;1:;

(a) 312213444 (b) 3 121 1 1 222 Consider the following program:


(c) 3122134 (d) 3121112 int (int.p, int n)
IGATE-2O16, Ans: (a)l ol {
ol "1)
T7 . What will be the output of the following pseudo- sl if (n = <=
return 0;
.:l
code when parameters are passed by reference ql -l else return max ((p+1 , n-1), p[0]-p[1];
+l
and dynamic scoping is assumed? ,, I
)
^_e.
d-!' EI
ol
int main ( )

void n(x) :tt


:lol {

t int a[ ] = {3, 5, 2,6, 4};


ol
X= X* a; print(x); 6 printf("%d', (a,5));
l E
i
void m(y) m
m
Nofe; max (x, y) returns the maximum of x
{a = 1; a = y- a; n(a); a andy.
-c
print(a); C The value printed by this program is
g
) o IGATE-2O16, Ans: (3)l -.
B
void maino o
-
I
{ Z IITI
o
m(a); {
o
o
) f
(a) 6,2 (b) 6,6 Z
o
E
(c) 4,2 (d) 4,4 o
l
q
IGATE-2016, Ans: (c)l
The following function computes Xvfor positive =
@
T8. -oo
integers X and Y.

lo
;
int exp (int X int Y) t;
lo
{
intres =1,a=X,b=Y', t:
ta
l.
while(bl=0) lo
l3
{rt@%2==0) lo
lt
{ a=a*a',b=b12, }
else {res = res*a; b = b- 1; la
l?
l-
) l.
)
t,:
la
return res; l=
tJ
l=
) l+
Which one of the following conditions is TRUE ls
befor every iteration of the looP? lr
l=
ll
(a) XY = ab (b) (res * a)Y = (res.,Y)b IH
(c) XY = res
*
ab (d) *
XY = (res a)b l6
t:
[GATE-2016, Ans: (c)] li
Iu,
lo
l=

MRf;TE EIIsTI
--M P[.!bii*;]?i*t]in

Das könnte Ihnen auch gefallen