Sie sind auf Seite 1von 36

UNIT I LINEAR STRUCTURES 1. What are the main objectives of Data str ct re!

" To i#entif$ an# create sef % mathematica% entities an# o&erations to #etermine 'hat c%asses of &rob%ems can be so%ve# b$ sin( these entities an# o&erations. " To #etermine the re&resentation of these abstract entities an# to im&%ement the abstract o&erations on these concrete re&resentation. ). Nee# of a Data str ct re! " To n#erstan# the re%ationshi& of one #ata e%ements 'ith the other an# or(ani*e it 'ithin the memor$. " A #ata str ct res he%&s to ana%$*e the #ata+ store it an# or(ani*e it in a %o(ica% or mathematica% manner. ,. Define #ata str ct re 'ith e-am&%e. A #ata str ct re is a 'a$ of or(ani*in( #ata that consi#ers not on%$ the items store# b t a%so their re%ationshi& to each other. e.(.. Arra$s+ Recor#s etc. e.( of com&%e- #ata str ct re Stac/s+ 0 e es+ Lin/e# %ist+ Trees+ 1ra&hs. 2. Define abstract #ata t$&e an# %ist its a#vanta(es. ADT is a set of o&erations. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ) An abstract #ata t$&e is a #ata #ec%aration &ac/a(e# to(ether 'ith the o&erations that are meanin( f %% on the #ata t$&e. Abstract Data T$&e 1. Dec%aration of #ata ). Dec%aration of o&erations. A#vanta(es.

1. Eas$ to #eb ( sma%% ro tines than %ar(e ones. ). Eas$ for severa% &eo&%e to 'or/ on a mo# %ar &ro(ram sim %taneo s%$. ,. A mo# %ar &ro(ram &%aces certain #e&en#encies in on%$ one ro tine+ ma/in( chan(es easier. 4. What are the t'o basic t$&es of Data str ct res! 1. 3rimitive Data str ct re E(.+ int+char+f%oat ). Non 3rimitive Data Str ct re i. Linear Data str ct re E(.+ Lists Stac/s 0 e es ii. Non %inear Data str ct re E(.+ Trees 1ra&hs 5. What are the fo r basic 6&erations of Data str ct res! 1. Traversin( ). Searchin( ,. Insertin( 2. De%etin( 7. List o t the #ifferent 'a$s to im&%ement the %ist! 1. Arra$ 8ase# Im&%ementation ). Lin/e# %ist Im&%ementation i. Sin(%$ %in/e# %ist ii. Do b%$ %in/e# %ist iii. C rsor base# %in/e# %ist DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e , 9. Define sin(%$ %in/e# %ist 'ith neat #ia(ram. A sin(%$ %in/e# %ist is a co%%ection of no#es each no#e is a str ct re it consistin( of an e%ement an# a &ointer to a str ct re containin( its s ccessor+ 'hich is ca%%e# a ne-t &ointer. The %ast ce%%:s ne-t &ointer &oints to NULL s&ecifie# b$ *ero. ;. List the o&erations of sin(%e %in/e# %ist. <a/eEm&t$

IsEm&t$ IsLast =in# De%ete =in#3revio s Insert De%ete%ist >ea#er =irst A#vance Retrieve 1?. Write the ro tine for insertion o&eration of sin(%$ %in/e# %ist. @A Insert Bafter %e(a% &osition 3CA@ @A >ea#er im&%ementation ass me#A@ @A 3arameter L is n se# in this im&%ementationA@ Doi# Insert BE%ementT$&e E+ List L+ 3osition 3C F 3osition Tm&Ce%%G DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 2 Tm&Ce%%Hma%%ocBsi*eofBstr ct No#eCCG ifBTm&Ce%%HHNULLC =ata%ErrorBI6 t of s&aceJJJKCG Tm&Ce%%LME%ement HEG Tm&Ce%%LMNe-tH3LMNe-tG 3LMNe-tHTm&Ce%%G N 11. Write the ro tine for #e%etion o&eration of sin(%$ %in/e# %ist. @A De%ete first occ rrence of - from a %istA@ @A Ass me se of a hea#er no#eA@ Doi# De%eteBE%ementT$&e E+ List LC F 3osition 3+ Tm&Ce%%G

3H=in#3revio sBE+ LCG if BJ IsLastB3+LCC F Tm&Ce%%H3LMNe-tG 3LMNe-tHTm&Ce%%LMNe-tG =reeBTm&Ce%%CG N N 1). List o t the a#vanta(es an# #isa#vanta(es of sin(%$ %in/e# %ist. A#vanta(es. 1. Eas$ insertion an# #e%etion. ). Less time cons m&tion. Disa#vanta(es. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 4 1. Data not &resent in a %inear manner. ). Insertion an# #e%etion from the front of the %ist is #iffic %t 'itho t the se of hea#er no#e. 1,. Define #o b%$ %in/e# %in/e# %ist 'ith neat #ia(ram. Do b%$ %in/e# %ist is a co%%ection of no#es 'here each no#e is a str ct re containin( the fo%%o'in( fie%#s 1. 3ointer to the &revio s no#e. ). Data. ,. 3ointer to the ne-t no#e. 12. Define circ %ar%$ %in/e# %ist 'ith neat #ia(ram. Circ %ar%$ %in/e# %ist is a co%%ection of no#es + 'here each no#e is a str ct re containin( the e%ement an# a &ointer to a str ct re containin( its s ccessor. The &ointer fie%# of the %ast no#e &oints to the a##ress of the first no#e. Th s the %in/e# %ist becomes circ %ar. 14. Write the #ifference bet'een Sin(%$ an# #o b%$ %in/e# %ist. Sin(%$ Do b%$ It is a co%%ection of no#es an# each It is a co%%ection of no#es an# each

no#e is havin( one #ata fie%# no#e is havin( one #ata fie%# an# ne-t %in/ fie%# one &revio s %in/ fie%# an# one ne-t %in/ fie%# The e%ements can be accesse# The e%ements can be accesse# sin( DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 5 sin( ne-t %in/ both &revio s %in/ as 'e%% as ne-t %in/ No e-tra fie%# is reO ire# hence+ 6ne fie%# is reO ire# to store &revio s No#e ta/es %ess memor$ in SLL. Lin/ >ence+ no#e ta/es memor$ in DLL. Less efficient access to e%ements <ore efficient access to e%ements. 15. Write the #ifference bet'een #o b%$ an# circ %ar%$ %in/e# %ist. Do b%$ Circ %ar%$ If the &ointer to ne-t no#e is N %%+ There is no first an# %ast no#e. it s&ecifies the %ast no#e. Last no#e:s ne-t fie%# is a%'a$s Last no#es ne-t fie%# &oints to N %% the a##ress of the first no#e. Ever$ no#e has three fie%#s one is it can be a sin(%$ %in/e# %ist 3ointer to the &ervio s no#e+ ne-t an# #o b%$ %in/e# %ist. Is #ata an# the thir# is &ointer to the ne-t no#e. 17. Write the #ifference bet'een c rsor an# &ointer im&%ementation of sin(%$ %in/e# %ist. CURS6R I<3LE<ENTATI6N 36INTER I<3LE<ENTATI6N 1%oba% arra$ is maintaine# for storin( The #ata are store# in a co%%ection the #ata e%ements .The corres&on#in( of str ct res. Each str ct re contains in#e- va% e for each #ata item re&resents #ata an# a &ointer to the ne-t str ct re. its a##ress. Co%%ection of em&t$ ce%%s is maintaine# A ne' str ct re can be obtaine# from in the form of a arra$ from 'hich ce%%s the s$stems (%oba% memor$ b$ a ca%% to DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 7

can be a%%ocate# an# a%so ce%%s can be a ma%%ocBC an# re%ease# b$ a ca%% to ret rne# after se. freeBC. 19. Define stac/ ADT 'ith e-am&%e. A stac/ is a %ist 'ith a restriction that insertions an# #e%etions can be &erforme# in on%$ one &osition name%$ the en# of the %ist ca%%e# the to&. e.(.. n#o statement in te-t e#itor. 3i%e of bi%%s in a hote%. 1;. State the o&erations on stac/. Define them an# (ive the #ia(rammatic re&resentation. 3 sh 3o& To& 3 sh. 3 sh is &erforme# b$ insertin( at the to& of stac/. 3o&. &o& #e%etes the most recent%$ inserte# e%ement. To&. to& o&eration e-amines the e%ement at the to& of the stac/ an# ret rns its va% e. )?. Write the ro tine for & sh an# &o& of %in/e# %ist. @Aro tine for & shA@ Doi# 3 shBE%ementT$&e E+Stac/ SC Stac/ S 3o&BSC 3 shBE+SC To&BSC DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 9 F 3trToNo#e Tm&Ce%%G Tm&Ce%%Hma%%ocBsi*eofBstr ct No#eCCG IfBTm&Ce%%HHNULLC =ata%ErrorBIo t of s&aceJJJKCG e%se F Tm&Ce%%LME%ementH-G

Tm&Ce%%LMNe-tHsLMNe-tG SLMNe-tHTm&Ce%%G N N @ARo tine for &o&A@ Doi# 3o&Bstac/ SC F 3trToNo#e =irstCe%%G IfBIsEm&t$BSCC ErrorBIEm&t$ stac/KCG E%se F =irstCe%%HSLMNe-tG SLMNe-tHSLMNe-tLMNe-tG freeBfirstCe%%CG N N )1. What is the & r&ose of to& an# &o&! DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ; To& o&eration e-amines the e%ement in the to& of the %ist an# ret rns its va% e. 3o& o&eration #e%etes the e%ement at the to& of the stac/ an# #ecrements the to& of the stac/ &ointer b$ one. )). State the #isa#vanta(es of %in/e# %ist im&%ementation of stac/. 1. Ca%%s to ma%%oc an# free f nctions are e-&ensive. ). Usin( &ointers is e-&ensive. ),. State the a&&%ications of stac/. 1. 8a%ancin( &arentheses. ). 3ostfi- E-&ression. i. Infi- to &ostfi- conversion ,. = nction ca%%s. )2. Write the a%(orithm for ba%ancin( s$mbo%s. 1. <a/e an em&t$ stac/.

). Rea# characters nti% en# of fi%e. ,. If the character is an o&enin( s$mbo%+ then & sh it onto the stac/. 2. If it is a c%osin( s$mbo% Then If the stac/ is em&t$ Re&ort an error 6ther'ise &o& the stac/ 4.If the s$mbo% &o&&e# is not the corres&on#in( o&enini( s$mbo% Then Re&ort an error 5. If the stac/ is not em&t$ at the en# of fi%e Then Re&ort an error DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 1? )4. 1ive the =eat res of ba%ancin( s$mbo%s. 1. It is c%ear%$ %inear. ). <a/es on%$ one &ass thro (h the in& t. ,. It is on%ine an# O ite fast. 2. It m st be #eci#e# 'hat to #o 'hen an error is re&orte#. )5. Convert the (iven infi- to &ostfi-. BjA/CPB-P$C Ans.j/A -$PP )7. Convert into &ostfi- an# eva% ate the fo%%o'in( e-&ression. BaPbAcC@# aH) bH2 cH5 #H) Ans. 3ost fi-. abcAP#@ Eva% ation. ) 2 5 A P)@ H1, )9. Write the feat res of re&resentin( ca%%s in a stac/. 1. When a f nction is ca%%e# the re(ister va% es an# ret rn a##ress are save#.

). After a f nction has been e-ec te# the re(ister va% es are res me# on ret rnin( to the ca%%in( statement. ,. The stac/ is se# for res min( the re(ister va% es an# for ret rnin( to the ca%%in( statement. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 11 2. The stac/ overf%o' %ea#s to fata% error ca sin( %oss of &ro(ram an# #ata. 4. Rec rsive ca%% at the %ast %ine of the &ro(ram is ca%%e# tai% rec rsion an# a%so %ea#s to error. );. Define O e e 'ith e-am&%es. 0 e e is a %ist in 'hich insertion is #one at one en# ca%%e# the rear an# #e%etion is &erforme# at another ca%%e# front. e.(. Tic/et co nter. 3hone ca%%s 'aitin( in a O e e for the o&erator to receive. ,?. List the o&erations of O e e. T'o o&erations 1. EnO e eLinserts an e%ement at the en# of the %ist ca%%e# the rear. ). DeO e eL#e%ets an# ret rns the e%ement at the start of the %ist ca%%e# as the front. ,1. What are the &rereO isites for im&%ementin( the O e e ADT sin( arra$! =or each O e e #ata str ct re the fo%%o'in( &rereO isites m st be satisfie# 1. Qee& an arra$ O e eR S. ). The &ositions front an# rear re&resents the en#s of the O e e. ,. The n mber of e%ements that are act a%%$ in the O e e is /e&t trasc/ of sin( Tsi*e:. ,). >o' the enO e e an# #eO e e o&erations are &erforme# in O e e. To enO e e an e%ement E. increment si*e an# rear set O e eRrearSH-

To #eO e e an e%ement DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 1) set the ret rn va% e to O e eRfrontS. Decrement si*e Increment front ,,. Write the ro tines for enO e e o&eration in O e e. Doi# EnO e eBE%ement t$&e E+0 e e 0C F IfBIs= %%B0CC ErrorBI= %% O e eKCG E%se F 0LMSi*ePPG 0LMRearHS ccB0LMRear+0CG 0LMArra$R0LMRearSHEG N N ,2. Write the ro tines for #eO e e o&eration in O e e. Doi# DeO e eB0 e e 0C F IfBIsEm&t$B0CC ErrorBIEm&t$ 0 e eKCG E%se 0LMfrontPPG N ,4. List the A&&%ications of O e e! " 1ra&h A%(orithm " 3riorit$ A%(orithm DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 1, " Uob sche# %in( " Cate(ori*in( Data ,5. Define &riorit$ O e e 'ith #ia(ram an# (ive the o&erations.

3riorit$ O e e is a #ata str ct re that a%%o's at %east the fo%%o'in( t'o o&erations. 1. InsertLinserts an e%ement at the en# of the %ist ca%%e# the rear. ). De%ete<inL=in#s+ ret rns an# removes the minim m e%ement in the &riorit$ 0 e e. 6&erations. Insert De%ete<in ,7. 1ive the a&&%ications of &riorit$ O e es. There are three a&&%ications of &riorit$ O e es 1. E-terna% sortin(. ). 1ree#$ a%(orithm im&%ementation. ,. Discrete even sim %ation. 2. 6&eratin( s$stems. 3riorit$ 0 e e > De%ete<inB>C InsertB>C DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 12 UNIT II TREE STRUCTURES 1. Define Tree .1ive an e-am&%e. A tree is a co%%ection of no#es .The co%%ection can be em&t$ .6ther'ise a tree consists of a #istin( ishe# no#e r ca%%e# the root an# ? or more non em&t$ s bLtrees T1+T)+T,VVVVV.T/ each of 'hose roots are connecte# b$ a #irecte# e#(e from r. E(. #irector$ str ct re hierarch$ ). Define #e&th of a no#e in a tree. 1ive e-am&%e. =or an$ no#e ni the #e&th of ni is the %en(th of the niO e &ath from the root to ni e(. root

T1 T) T, VVVVV TQQ a b# ef c DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 14 The #e&th of e is ). ,. Define %en(th of the &ath in a tree 'ith an e-am&%e. Len(th of a &ath is the n mber of e#(es on the &ath. The %en(th of the &ath from AL> is ,. 2. Define a &ath in a tree. 1ive e-am&%e. A &ath from a no#e n1 to n/ is #efine# as the seO ence of no#es n1+ n)V..n/ s ch that ni is the &arent of niP1 for 1WiX/. E(. A DE C =1 > 8 A DE C =1 > 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 15 The &ath from AL> is AL8LDL> 4. Define hei(ht of the no#e in a tree. 1ive e-am&%e. The hei(ht of no#e ni the %en(th of the %on(est &ath from ni to a %eaf E(.

The hei(ht of no#e 8 is ). 5. Write the ro tine for no#e #ec%aration in trees. t$&e#ef str ct TreeNo#e A3trToNo#eG str ct TreeNo#e F E%ementT$&e E%ementG 3trToNo#e =irstChi%#G 3trToNo#e Ne-tSib%in(G NG 7. List the a&&%ications of trees. A DE C =1 > 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 17 " 8inar$ search trees " E-&ression trees " Threa#e# binar$ trees 9. Define 8inar$ tree. A 8inar$ tree is a tree in 'hich no no#e can have more than t'o chi%#ren. ;. List the tree traversa% a&&%ications. 1. Listin( a #irector$ in an hierarcha% fi%e s$stem B&reor#erC ). Ca%c %atin( the si*e of a #irector$ B&ost or#erC 1?. Define binar$ tree ADT 'ith an e-am&%e. A binar$ tree is a tree in 'hich no no#e can have more than t'o chi%#ren. 11. Define binar$ search tree! 8inar$ Search tree is a binar$ tree in 'hich each interna% no#e - stores an e%ement s ch that the e%ement store# in the %eft s b tree of - are %ess than or eO a% to - an# e%ements store# in the ri(ht s b tree of - are (reater than or eO a% to -. This is ca%%e# binar$LsearchLtree

1). List the T$&es of binar$ search trees iC 3erformance com&arisons iiC 6&tima% binar$ search trees 1,. List the 6&erations of binar$ search tree! " <a/e Em&t$ " =in# " Insert " De%ete " Search " Dis&%a$ 12. Define Threa#e# 8inar$ tree. A DE C =1 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 19 A Threa#e# 8inar$ Tree is a binar$ tree in 'hich ever$ no#e that #oes not have a ri(ht chi%# has a T>READ Bin act a% sense+ a %in/C to its IN6RDER s ccessor. 8$ #oin( this threa#in( 'e avoi# the rec rsive metho# of traversin( a Tree+ 'hich ma/es se of stac/s an# cons mes a %ot of memor$ an# time. 14. List the ses of binar$ tree. 1. Searchin(. ). Com&i%er #esi(n. 15. Dra' the e-&ression tree for the (iven &ostfi- e-&ression sin( stac/. A8ACP 17. Define binar$ search tree ADT 'ith an e-am&%e. A binar$ search tree is a tree in 'hich for ever$ no#e E+ the va% es of a%% the /e$s in its %eft s b tree are sma%%er than the /e$ va% e in E an# the va% es of a%% the /e$s in its ri(ht s b tree are %ar(er

than the /e$ va% e in E. A 8 1) A8 A , A8 AC A A8 C P 2 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 1; 19. >o' #e%etion is &erforme# in a binar$ search tree. 6nce the no#e to be #e%ete# is fo n# there are three &ossibi%ities 1. If the no#e is a %eaf+ it can be #e%ete# imme#iate%$. ). If the no#e has one chi%# the no#e can be #e%ete# after its &arent a#j sts a &ointer to b$&ass the no#e. ,. If the no#e has t'o chi%#ren the (enera% strate($ is to re&%ace the #ata of this no#e 'ith the sma%%est #ata of the ri(ht s b tree an# rec rsive%$ #e%ete the no#e 'hich is em&t$. 1;. Define interna% &ath %en(th. It is the s m of the #e&ths of a%% no#es in a tree. )?. What is the avera(e #e&th of a%% no#es in an eO a%%$ %i/e%$ tree! The avera(e #e&th of a%% no#es in an eO a%%$ %i/e%$ tree is 6 B%o( NC. )1. List o t the #isa#vanta(es of 8inar$ search tree. 1. De%etions in a binar$ search tree %ea#s to trees 'hich are not eO a%%$ %i/e%$. ). Absence of ba%ance# search tree.

,. The avera(e #e&th is not 6 B%o( NC in trees 'hich are not eO a%%$ %i/e%$. )). Define tree traversa%. Trave%in( thro (h a%% the no#es of the tree in s ch a 'a$ that each no#e is visite# e-act%$ once. 5 ,4 9 7; 2 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )? ),. List o t the t$&es of Tree traversa%! There are three t$&es of tree traversa% 1. 3reor#er traversa% ). Inor#er traversa% ,. 3ostor#er traversa% )2. Write the ste&s an# ro tine for the &ostor#er traversa%. Ste&s. 1. Traverse the %eft s b tree. ). Traverse the ri(ht s b tree. ,. Disit the root. Ro tine. voi# &ostor#erBno#e Atem&C F ifBtem&JHNULLC F &ostor#erBtem&LM%eftCG &ostor#erBtem&LMri(htCG &rintfBIY#K+tem&LM#ataCG N N )4. Write the ste&s an# ro tine for the &reor#er traversa%. Ste&s. 1. Disit the root

). Traverse the %eft s b tree. ,. Traverse the ri(ht s b tree. Ro tine. voi# &reor#erBno#e Atem&C F DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )1 ifBtem&JHNULLC F &rintfBIY#K+tem&LM#ataCG &reor#erBtem&LM%eftCG &reor#erBtem&LMri(htCG N N )5. Write the ste&s an# ro tine for the inor#er traversa%. Ste&s. 1. Traverse the %eft s b tree ). Disit the root ,. Traverse the ri(ht s b tree. Ro tine. voi# inor#erBno#e Atem&C F if Btem&JHNULLC F inor#erBtem&LM%eftCG &rintfBIY#K+tem&LM#ataCG inor#erBtem&LMri(htCG N N DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )) )7. 3erform &reor#er traversa% for the (iven tree. A8D>EC=1 )9. 3erform inor#er traversa% for the (iven tree. =D8EAC

A 8C DE = A DE C =1 > 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ), );. 3erform &ostor#er traversa% for the (iven tree. =DE8CA ,?. Define the fo%%o'in(. iC Leaf No#es at the bottommost %eve% of the tree are ca%%e# %eaf no#es iiC Sib%in( The no#es 'ith common &arent are ca%%e# Sib%in( A 8C DE = DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )2 UNIT III 8ALANCED TREE 1. Define ADL Tree. 1ive E-am&%e. An ADL Tree is a binar$ search tree 'ith a ba%ance con#ition+ 'hich is eas$ to maintain an# ens re that the #e&th of the tree is 6B%o( NC. 8a%ance con#ition reO ire that the %eft an# the ri(ht s b trees have the same hei(ht. E-am&%e. ). Define 8a%ance factor.

The ba%ance factor of a no#e in binar$ tree is #efine# to be hRL hL 'here hL an# hR are hei(hts of %eft an# ri(ht s btrees of T. =or an$ no#e in ADL tree the ba%ance factor sho %# be 1+? or L1. A DE C = 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )4 ,. 1ive the ba%ance factor of each no#e for the fo%%o'in( tree. 8=HL1 8=H1 8=HL1 8=H? 8=H? 8=HL1 8=H? 2. When ADL tree &ro&ert$ is vio%ate# an# ho' to so%ve it! After insertion of an$ no#e in an ADL tree if the ba%ance factor of an$ no#e becomes other than L1+?+ or 1 then it is sai# that ADL &ro&ert$ is vio%ate#. So the no#e on the &ath from the inserte# no#e to the root nee#s to be rea#j ste#. Chec/ the ba%ance factor for each no#e in the &ath from inserte# no#e to the root no#e an# a#j st the affecte# s btree s ch that the entire s btree sho %# satisf$ the ADL &ro&ert$. 4. <ention the fo r cases to reba%ance the ADL tree. " An insertion of ne' no#e into Left s btree of Left chi%#BLLC. " An insertion of ne' no#e into Ri(ht s btree of Left chi%#BLRC. " An insertion of ne' no#e into Left s btree of Ri(ht chi%#BRLC. " An insertion of ne' no#e into Ri(ht s btree of Ri(ht chi%#BRRC. 5. Define Rotation in ADL tree. <ention the t'o t$&es of rotations. A DE

C = > 8 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )5 Some mo#ifications #one on ADL tree in or#er to reba%ance it is ca%%e# Rotation of ADL tree. The t'o t$&es of rotations are " Sin(%e Rotation " LeftLLeft Rotation " Ri(htLRi(ht Rotation " Do b%e Rotation " LeftLRi(ht Rotation " Ri(htLLeft Rotation 7. Define S&%a$ Tree. A s&%a$ tree is a se%fLba%ancin( binar$ search tree 'ith the a##itiona% &ro&ert$ that recent%$ accesse# e%ements are O ic/ to access a(ain. It &erforms basic o&erations s ch as insertion+ %oo/ & an# remova% in 6 B%o(BnCC amorti*e# time. =or man$ nonL niform seO ences of o&erations+ s&%a$ trees &erform better than other search trees+ even 'hen the s&ecific &attern of the seO ence is n/no'n. 9. List the 6&erations of S&%a$ tree. " S&%a$in( " Insertion " De%etin( ;. List the 6&erations on 8LTrees. " Search " Create " Insert 1?. List the 8LTrees A&&%ications. " Databases

" Conc rrent Access to 8LTrees 11. Define 8LTree. A search tree that is not a binar$ tree is ca%%e# 8LTree. That satisfies the fo%%&'in( str ct ra% &ro&erties " Root is either a %eaf or has bet'een ) an# < chi%#ren " A%% non %eaf no#es e-ce&t the root have bet'een R<@)S an# < chi%#ren. " A%% %eafs are at the same #e&th. 1). Define binar$ hea&s. A binar$ hea& is a hea& #ata str ct re create# sin( a binar$ tree. It can be seen as a binar$ tree 'ith t'o a##itiona% constraints. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )7 " The sha&e &ro&ert$. the tree is an a%most com&%ete binar$ treeG that is+ a%% %eve%s of the tree+ e-ce&t &ossib%$ the %ast one B#ee&estC are f %%$ fi%%e#+ an#+ if the %ast %eve% of the tree is not com&%ete+ the no#es of that %eve% are fi%%e# from %eft to ri(ht. " The hea& &ro&ert$. each no#e is (reater than or eO a% to each of its chi%#ren accor#in( to some com&arison &re#icate 'hich is fi-e# for the entire #ata str ct re. 1,. List the 6&erations on 8inar$ hea&. " A##in( to the hea& " De%etin( the root from the hea& 12. List the A&&%ications of 8inar$ hea& >ea& sort Se%ection A%(orithm 1ra&h A%(orithm DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e )9 UNIT ID >AS>IN1 AND SET 1. Define hashin(. It is the im&%ementation of hash tab%es. >ashin( is a techniO e se# for

&erformin( insertions+ #e%etions an# fin#s in constant avera(e time. ). Define a Qe$ in hashin(. a. A /e$ is a strin( 'ith an associate# va% e. e.(.Sa%ar$ information. ,. Define >ash tab%e. 1ive an e-am&%e. The hash tab%e #ata str ct re is an arra$ of fi-e# si*e containin( the /e$s. 2. Define tab%e si*e of a hash tab%e. Tab%e si*e is the si*e of the tab%e an# it is &art of the hash #ata str ct re. The tab%e r ns from ? to Tab%esi*eL1. 4. List the t$&es of hash f nction. 1. Division metho# ). <i# sO are 4? 2; ? 1 ) , 2 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ); ,. < %ti&%icative hash f nction 2. Di(it fo%#in( 4. Di(it ana%$sis 5. Define a >ash f nction 'ith an e-am&%e. >ash f nction ma&s each /e$ into some n mber in the ran(e ? to Tab%eai*eL1an# &%aces the /e$ in the a&&ro&riate ce%%. e.(.Qe$ mo# Tab%esi*e is a basic hash f nction 7. 3ro&erties of a hash f nction. 1. >ash f nction sho %# be sim&%e to com& te. ). Sho %# ens re that an$ t'o #istinct /e$s (et #ifferent ce%%s. ,. It sho %# #istrib te the /e$s even%$ amon( the ce%%s.

9. What is co%%ision in hashin(! If an e%ement is inserte# an# if it hashes to the same va% e as an a%rea#$ inserte# e%ement co%%ision ta/es &%ace. ;. What are the metho#s of reso%vin( co%%ision in hashin(! 1. Se&arate chainin( hashin(. ). 6&en a##ressin( hashin(. 1?. Define se&arate chainin( hashin( Se&arate chainin( means to /ee& a %ist of a%% e%ements that hash to the same va% e. 11. What are the o&erations of se&arate chainin(! 1. =in# ). Insert 1). List o t the a&&%ications of hashin(. 1. D8<S. ). Com& ter net'or/s ,. Stora(e of secret #ata 2. Cr$&to(ra&h$. 4. Sec rin( the #atabase 5. Database a&&%ications 7. Storin( #ata in a #atabase 1,. What are the a#vanta(es of se&arate chainin(! 1. Avoi#s co%%ision b$ maintainin( %in/e# %ists. ). The %in/ %ists 'i%% be short if the tab%e is %ar(e an# the hash f nction is (oo#. 12. What are the #isa#vanta(es of se&arate chainin(! 1. ReO ires &ointers. ). S%o's #o'n the a%(orithm ,. Time is reO ire# to a%%ocate ne' ce%%s. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,? 2. ReO ires the im&%ementation of a secon# #ata str ct re. 14. What is o&en a##ressin(! In o&en a##ressin( if a co%%ision occ rs a%ternative ce%%s are trie# nti% an em&t$ ce%% is fo n#.

It is an a%ternative to reso%vin( co%%isions 'ith %in/e# %ist. Bi.e.C h?BEC+h1BEC+VVV. Are trie# in s ccession. Where hiBECHB>ashBECP=BiCCmo# Tab%esi*e 'ith =B?CH? 'here = is the co%%ision reso% tion strate($. 15. What are the t$&es of o&en a##ressin( hashin(! " Linear &robin(. " 0 a#ratic &robin( " Do b%e hashin( DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,1 17. Differentiate bet'een %inear &robin( an# O a#ratic &robin( Linear &robin( 0 a#ratic &robin( " Definition. " It amo nts to tr$in( ce%%s seO entia%%$ 'ith 'ra&aro n# in search of an em&t$ ce%%. " Definition. " It is a co%%ision reso% tion metho# that e%iminates the &rimar$ c% sterin( &rob%em of %inear &robin(. " = nction. " It is %inear B i.e.C=BiCHi " = nction. " It is O a#ratic Bi.e.C =BiCHi) " A#vanta(es. " 1.Does not se &ointers " No secon# #ata str ct re " ,. Time is not reO ire# for a%%ocatin( ne'

ce%%s. " A#vanta(es. " 1.Does not se &ointers " No secon# #ata str ct re " Time is not reO ire# for a%%ocatin( ne' ce%%s. " If the tab%e is ha%f em&t$ an# the tab%e si*e is &rime then insertin( a ne' e%ement is s ccessf % an# ( arantee#. " No &rimar$ c% sterin(. " Disa#vanta(es. " Time for insertin( is O ite %ar(e. " 3rimar$ c% sterin(. " Linear &robin( is a ba# i#ea if the tab%e is more than ha%f f %%. " 2. 8i((er tab%e is nee#e# than se&arate chainin(. " Disa#vanta(es. " There is no ( arantee of fin#in( an em&t$ ce%% if the tab%e (ets more than ha%f f %% or if the tab%e si*e is not &rime. " 8i((er tab%e is nee#e# than se&arate chainin(. " The n mber of

a%ternative %ocations is severe%$ re# ce# if the tab%e si*e is not &rime. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,) 19. Define &rimar$ c% sterin(. It is the formin( of b%oc/s of occ &ie# ce%%s. It means that an$ /e$ that hashes into the c% ster 'i%% reO ire severa% attem&ts to reso%ve the co%%ision an# then it 'i%% a## to the c% ster. 1;. Define #o b%e hashin(. It is a co%%ision reso% tion metho# .=or #o b%e hashin( =BiCHi.hash)BEC. Bi.eC a secon# hash f nction is a&&%ie# to E an# &robin( is #one at a #istance hash)BEC+ )hash)B-CVVV. an# so on. )?. Define rehashin(. Rehashin( is the b i%#in( of another tab%e 'ith an associate# ne' hash f nction that is abo t t'ice as bi( as the ori(ina% tab%e an# scannin( #o'n the entire ori(ina% hash tab%e com& tin( the ne' hash va% e for each non #e%ete# e%ement an# insertin( it in the ne' tab%e. )1. List o t the a#vanta(es an# #isa#vanta(es of rehashin(. A#vanta(e. " Tab%e si*e is not a &rob%em. " >ash tab%es cannot be ma#e arbitrari%$ %ar(e. " Rehashin( can be se# in other #ata str ct res. Disa#vanta(e. " It is a ver$ e-&ensive o&eration. " The r nnin( time is ?BNC. " S%o'in( #o'n of rehashin( metho#. )). What are the 'a$s in 'hich rehashin( can be im&%emente#. 1. Rehash as soon as the tab%e is ha%f f %%. ). Rehash on%$ 'hen an insertion fai%s. ,. <i##%e of the roa# strate($ is to rehash 'hen the tab%e reaches a certain

%oa# factor. ),. Define E-ten#ib%e hashin(. E-ten#ib%e hashin( a%%o's a fin# to be &erforme# in t'o #is/ access an# insertions a%so reO ire fe' #is/ accesses. " 2. Stan#ar# #e%etion cannot be &erforme#. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,, )2. What is hea& or#er &ro&ert$! The sma%%est e%ement sho %# be at the root .An$ no#e sho %# be sma%%er than a%% of its #escen#ants. )4. What is meant b$ E-&ression Tree! An e-&ression tree is a binar$ tree in 'hich the o&eran#s are attache# as %eaf no#es an# o&erators become the interna% no#es. )5. List the a&&%ications of set. i. DisjointLset #ata str ct res mo#e% the &artitionin( of a set+ for e-am&%e to /ee& trac/ of the connecte# com&onents of an n#irecte# (ra&h. This mo#e% can then be se# to #etermine 'hether t'o vertices be%on( to the same com&onent+ or 'hether a##in( an e#(e bet'een them 'o %# res %t in a c$c%e. ii. This #ata str ct re is se# b$ the 8oost 1ra&h Librar$ to im&%ement its Incrementa% Connecte# Com&onents f nctiona%it$. It is a%so se# for im&%ementin( Qr s/a%Zs a%(orithm to fin# the minim m s&annin( tree of a (ra&h. )7. Define Disjoint set. A #isjointLset #ata str ct re is a #ata str ct re that /ee&s trac/ of s ch a &artitionin(. A nionLfin# a%(orithm is an a%(orithm that &erforms t'o sef % o&erations on s ch a #ata

str ct re. " =in#. Determine 'hich set a &artic %ar e%ement is in. A%so sef % for #eterminin( if t'o e%ements are in the same set. " Union. Combine or mer(e t'o sets into a sin(%e set. DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,2 UNIT D 1RA3>S 1. Define 1ra&h. A 1ra&h is #efine# as 1 H BD+ EC 'here D is the set of vertices Bno#esC an# E is the set of e#(esBarcsC connectin( the vertices. An e#(e is re&resente# as a &air of vertices B +vC. D H F1+ )+ ,+ 2+ 4N E H FB1+ )C+B1+ ,C+B1+2C+B)+,C B)+2C+B)+4C+B,+4CN ). Define Directe# 1ra&h. A Directe# (ra&h is a (ra&h in 'hich the e#(es are #irecte#. It is a%so ca%%e# Di(ra&h. DHF1+)+,+2N EHFB1+)C+B)+,C+B)+2C B,+1C+B,+2C+B2+,CN ,. What #o $o mean b$ Un#irecte# 1ra&h! , 24 1 ) , 2 ) 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,4 E#(es in the (ra&h #o not have #irections mar/e#. S ch (ra&hs are

referre# to as n#irecte# (ra&hs. DHF1+)+,+2N EHFB1+)C+B)+1C+B)+,C+B,+)C )+2C+B2+)C+B,+2C+B2+,C+B,+1C+B1+,CN Define S$mmetric Di(ra&h. Ever$ e#(e has an e#(e in the reverse #irection i.e for ever$ e#(e BU+DC there is an e#(e BD+UC. S ch t$&e of (ra&h is ca%%e# S$mmetric Di(ra&h. DHF1+)+,+2N EHFB1+)C+B)+1C+B)+,C+B,+)C B)+2C+B2+)C+B,+2C+B2+,C+B,+1C+B1+,CN 2. What #o $o mean b$ 'ei(hte# (ra&h! Wei(hte# (ra&hs are s ch (ra&hs 'here the e#(es are associate# 'ith 'ei(hts. These 'ei(hts are se# to mar/ the im&ortance of e#(es in re&resentin( a &rob%em. , 2 1 ) , 2 ) , DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,5 E-. Roa# ma& re&resente# as (ra&h 'here the 'ei(ht is the #istance bet'een t'o &%aces. 19 1? 14 DHF1+)+,+2+4N EHFB1+)C+B1+,C+B1+2C+B)+,C )? B)+2C+B)+4C+B,+4CN 4? 17 )4

4. Define a#jacent vertices. T'o vertices are sai# to be a#jacent vertices if there is an e#(e bet'een them. Dertices 1[)+ )[,+ )[2+ ,[2 are a#jacent vertices. , 24 1 ) , 2 ) , DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,7 5. Define &ath. A 3ath bet'een vertices B +vC is a seO ence of e#(es 'hich connects vertices [ v. The &ath bet'een the vertices 1 an# 2 is 1L)L2 or 1L,L2 7. Define Len(th of the 3ath. Len(th of the &ath is the n mber of e#(es in a &ath 'hich is eO a% to NL1. N re&resents the n mber of vertices. The Len(th of the &ath 1 L2 FB1+)C+B)+,C+B,+2C N is , FB1+,C+B,+2CN is ) an# a%so FB1+)C+B)+2CN is ). , 2 ) 1 , 2 ) 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,9 ;. Define c$c%e.

A C$c%e in a (ra&h is a &ath that starts an# en#s at the same verte-. i.e &ath in 'hich the first an# %ast vertices are same. E-. FB,+ 1C+ B1+ )C+B)+2C+B2+,CN is a C$c%e. 1?. Define sim&%e c$c%e. Sim&%e c$c%e means the verte- sho %# not be re&eate# an# the first an# %ast vertesho %# be the same. E-am&%e. 1L)L2L,L1 is a sim&%e c$c%e 1L)L,L2L,L1 is not a sim&%e C$c%e , 2 ) 1 , 2 ) 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e ,; 11. Define Sim&%e 3ath. A%% vertices are #istinct+ e-ce&t that the first an# %ast ma$ or ma$ not be the same. E-am&%e. 1L)L2L,L1 is a sim&%e &ath 1L)L,L2L,L1 is not a sim&%e &ath 1L)L2L, is a sim&%e &ath , 2 ) 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 2? 1). Define Ac$c%ic (ra&h. An ac$c%ic (ra&h is a (ra&h 'ith no c$c%e.

1,. What #o $o mean b$ a stron(%$ connecte# (ra&h! A Directe# (ra&h is stron(%$ connecte# if there is a &ath from ever$ verteto ever$ other verte-. 12. What #o $o mean b$ 'ea/%$ connecte# (ra&h! If the #irecte# (ra&h is not stron(%$ connecte#+ b t the n#er%$in( (ra&h B 'itho t #irection to the arcsC is connecte#+ then the (ra&h is sai# to be 'ea/%$ connecte#. , 2 ) 1 ), 1 ), 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 21 14. Define com&%ete (ra&h. A (ra&h in 'hich there is an e#(e bet'een ever$ &air of vertices. 15. <ention the 'a$s of re&resentin( a (ra&h! aC A#jacenc$ <atri- re&resentation bC A#jacenc$ List re&resentation 17.What #o $o mean b$ A#jacenc$ <atri- re&resentation! The a#jacenc$ matri- < of a (ra&h 1 H BD+ EC is a matri- of or#er Di -Dj an# the e%ements of the n'ei(hte# (ra&h < are #efine# as < RiS RjS H 1+ if BDi+ DjC \ E H ? 6ther'ise =or a 'ei(hte# (ra&h the e%ements of < are #efine# as < RiS RjS H Wij+ if BDi+ DjC \ E an# Wij is the 'ei(ht of e#(e BDi+ DjC H ? 6ther'ise E-am&%e. 1),2

1?111 )???1 ,???1 2?1?? 19. What #o $o mean b$ a#jacenc$ List re&resentation! ), 1 1) ,2 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 2) It is an arra$ of %in/e# %ist +for each verte- a %in/e# %ist of a%% a#jacent vertices is maintaine#. 1;. What #o $o mean b$ in#e(ree an# o t#e(ree of a (ra&h! " In#e(ree of a verte- in a (ra&h is the n mber of incomin( e#(es. " 6 t#e(ree of a verte- is the n mber of e#(es that %eaves the verte-. E-am&%e. 1) ,2 1) , 1 ) ), 2 ) , DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 2, In#e(ree for the verte- 1 is ?+ verte- ) is )+ verte- , is 1+ an# verte- 2 is ) 6 t#e(ree for the verte- 1 is ,+ verte- ) is ?+ verte- , is 1+ an# verte- 2 is 1. )?. Define To&o%o(ica% sort. To&o%o(ica% sort is #efine# as an or#erin( of vertices in a #irecte# ac$c%ic (ra&h. s ch

that if there is a &ath from Di to Dj+ then Dj a&&ears after Di in the or#erin(. )1. E-&%ain the &rinci&%e of to&o%o(ica% sort. =in# the verte- 'ith no incomin( e#(e. 3rint the verte- an# remove it a%on( 'ith its e#(es from the (ra&h. A&&%$ the same strate($ to the rest of the (ra&h. =ina%%$ a%% recor#e# vertices (ive to&o%o(ica% sorte# %ist. )). What is the #isa#vanta(e of to&o%o(ica% sort! 6r#erin( of vertices is not &ossib%e if the (ra&h is a c$c%ic (ra&h. 8eca se if there are t'o vertices v an# ' on the c$c%e+ v &rocee#s ' an# ' &rocee#s v+ so or#erin( not niO e. ),. What is the r nnin( time for to&o%o(ica% sort! The r nnin( time of the a%(orithm for to&o%o(ica% sort is 6B D )C.=or the a%(orithm sin( 0 e e+ the r nnin( time is 6 B E P D C if a#jacenc$ %ist are se#. )2. State the shortest &ath &rob%em 6R Sin(%e so rce shortest &ath &rob%em. 1iven as in& t a 'ei(hte# (ra&h or an n'ei(hte# (ra&h 1H BD+ EC an# a #istin( ishe# verte- s + the shortest &ath &rob%em is to fin# the shortest 'ei(hte# or n'ei(hte# &ath from s to ever$ other verte-. )4. E-&%ain 'ei(hte# &ath %en(th. NL1 The cost of the &ath D1+D)V.DN is S Ci+ iP1. . This is referre# to as the 'ei(hte# &ath %en(th. iH1 )5. E-&%ain n'ei(hte# &ath %en(th DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 22 Un'ei(hte# &ath %en(th is the n mber of e#(es on the &ath name%$+ NL 1B'here N is the n mber of verticesC. )7. What #o $o mean b$ Ne(ative e#(e! Ne(ative e#(e means a (ra&h havin( at%east one e#(e 'ith a ne(ative

'ei(ht. , L1? 5 )9. What #o $o mean b$ ne(ative cost c$c%e! A (ra&h havin( the shortest &ath 'ith ne(ative 'ei(ht is /no'n Ne(ative cost c$c%e. );. 1ive e-am&%es for &rob%ems so%ve# b$ shortest &ath a%(orithm. " Chea&est 'a$ of sen#in( e%ectronic ne's from one com& ter to another. " To com& te the best ro te ,?. What is the r nnin( time for the 'ei(hte# an# n'ei(hte# shortest &ath! The r nnin( time for the 'ei(hte# shortest &ath is 6 B E P D C The r nnin( time for the Un'ei(hte# shortest &ath is 6 B E %o( D C ,1. What is the a#vanta(e of n'ei(hte# shortest &ath a%(orithm! There is no ca%c %ation 'ith 'ei(hts. 6n%$ the n mber of e#(es on the shortest &ath is fo n#. ,4. What are the a&&%ications of (ra&hs! 1. Air&ort s$stem ). Street traffic ), 1 DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 24 ,5. What is a c$c%ic (ra&h! A (ra&h 'hich has at%east one c$c%e is ca%%e# a c$c%ic (ra&h. ,7. What is a connecte# (ra&h! An n#irecte# (ra&h is connecte# is connecte# if there is a &ath fro( ever$ verte- to ever$ other verte-. ), 1 1 ),

DATA STRUCTURE SNSCT De&artment of Com& te Science an# En(ineerin( 3a(e 25

Das könnte Ihnen auch gefallen