Professional Documents
Culture Documents
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#*$
(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***
(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
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
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
)
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
{
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 )
@
(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
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
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.
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
=
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 ;
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
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.
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
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-
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
BXEffiffiffi ffiffiS*d
:
.:
.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
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"
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
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:;
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