You are on page 1of 13

147301 -DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++

L T P C 3 0 0 3
UNIT I PRINCIPLES OF OBJECT ORIENTED PROGRAMMING 9
Introduction- Tokens-Expressions-contour Structures Functions in C++, classes and objects,
constructors and destructors ,operators overloading and type conversions
UNIT II ADVANCED OBJECT ORIENTED PROGRAMMING 9
In!eritance, Extending classes, "ointers, #irtual $unctions and poly%orp!is%, File &andling
Te%plates ,Exception !andling, 'anipulating strings
UNIT III DATA STRUCTURES & ALGORITHMS 9
(lgorit!%, (nalysis, )ists, Stacks and *ueues, "riority *ueues-+inary &eap-(pplication, &eaps
!as!ing-!as! tables ,it!out linked lists
UNIT IV NONLINEAR DATA STRUCTURES 9
Trees-+inary trees, searc! tree (-T, (#) trees, .rap! (lgorit!%s-Topological sort, s!ortest pat!
algorit!% net,ork $lo, proble%s-%ini%u% spanning tree - Introduction to /" - co%pleteness
UNIT V SORTING AND SEARCHING 9
Sorting Insertion sort, S!ell sort, &eap sort, 'erge sort, 0uick sort, Indirect sorting, +ucket sort,
Introduction to (lgorit!% -esign Tec!ni*ues .reedy algorit!% 1'ini%u% Spanning Tree2, -ivide and
Con*uer 1'erge Sort2, -yna%ic "rogra%%ing 1(ll pairs S!ortest "at! "roble%2
TOTAL HOURS 4!
TE"T BOO#S$
3 'ark (llen 4eiss, 5-ata Structures and (lgorit!% (nalysis in C6, 7rd ed, "earson Education
(sia, 899:
8 E +alagurusa%y, 5 ;bject ;riented "rogra%%ing ,it! C++6, 'c.ra, &ill Co%pany )td, 899:
REFERENCES$
3 'ic!ael T .oodric!, 5-ata Structures and (lgorit!% (nalysis in C++6, 4iley student edition, 899:
8 Sa!ni, 5-ata Structures <sing C++6, T!e 'c.ra,-&ill, 899=
7 Sey%our, 5-ata Structures6, T!e 'c.ra,-&ill, 899:
> ?ean "aul Tre%blay @ "aul .Sorenson, (n Introduction to data structures ,it! applications, Tata
'c.ra, &ill edition, II Edition, 8998
A ?o!n B&ubbard, Sc!au%Cs outline o$ t!eory and proble% o$ data structure ,it! C++, 'c.ra,-&ill,
/e, -el!i, 8999
= +jarne Stroustrup, T!e C++ "rogra%%ing )anguage, (ddison 4esley, 8999
: Bobert )a$ore, ;bject oriented progra%%ing in C++, .algotia "ublication
UNIT I
PART A
1% &'() *+ (, *-.,)*/*.01
Identi$iers are na%es $or various progra%%ing ele%ents in c++ progra% suc! as variables, arrays,
$unction, structures, union, labels ect, (n identi$ier can be Co%posed only o$ uppercase, lo,er case
letter, underscore and digits, but s!ould start only ,it! an alp!abet or an underscore
2% &'() *+ ( 3.4560-1
Dey,ords are ,ord ,!ose %eanings !ave been already de$ined in t!e c co%piler T!ey are also called
as reserved ,ords
1ex2 %ain12, i$, else, else, i$, scan$, print$, s,itc!, $or, goto, ,!ile ect,
3% D./*,. 76,+)(,) *, 7++%
Constants in c++ re$ers to $ixed values t!at do not c!ange during execution o$ a progra%
4% D./*,. ( 8(0*(9:.%
( *uantity ,4!ic! %ay vary during execution o$ a progra% is called as a variable
!% &'() (0. ;,(04 6<.0()60+1
T!e operators t!at act upon a single operand are called as unary operators T!e unary operators used in
c++ are - , ++, -- and siEeo$ operators
=% &'() (0. 9*,(04 6<.0()60+1
T!e operators t!at act upon t,o operands are called binary operators T!e binary operators used in c++
are +, -, F, G , H, I etc,
7% &'() (0. ).0,(04 6<.0()60+1
T!e operators t!at act upon t!ree operands are called as ternary operators T!e ternary operator available
in c++ is 1JK2T!is operator is also re$erred as conditional operator
>% &'() *+ ?.(,) 94 (, .@<0.++*6,1
(n expression is a co%bination o$ constant, variable, operators and $unction calls ,ritten in any $or% as
per t!e syntax o$ t!e c++ language
9% S)(). )'. -*//.0.,7. 9.)5.., 7 (,- 7++%
C C++
1i2 "rocedural progra%%ing language ;bject-oriented progra%%ing anguage
1ii2 .lobal variable can be declared It is an error to declare a variable as global
1iii2 Function prototypes are optional (ll $unctions %ust be prototyped
1iv2 )ocal variables can be declared only )ocal variables can be declared any ,!ere
t!e start o$ a c progra% in a c++ progra%
1v2 4e can call a %ain12 $unction, ,it!in T!is is not allo,ed
a progra%
10% L*+) )'. 8(0*6;+ 66<+ 76,7.<)+
Four %ain ;;" concepts
(bstraction
creation o$ ,ell-de$ined inter$ace $or an object, separate $ro% its i%ple%entation
eg, key $unctionalities 1init, add, delete, count, print2 ,!ic! can be called independently o$ kno,ing
!o, an object is i%ple%ented
Encapsulation
keeping i%ple%entation details 5private6 ie, inside t!e i%ple%entation !ierarc!y an object is de$ined in
ter%s o$ ot!er objects Co%position IL larger objects out o$ s%aller ones
In!eritance IL properties o$ s%aller objects are 5in!erited6 by larger
objects
"oly%orp!is%
use code 5transparently6 $or all types o$ sa%e class o$ object
ie, 5%orp!6 one object into anot!er object ,it!in sa%e !ierarc!y
11% D./*,. 7:(++ (,- 69A.7)
ClassK It is de$ined as blueprint or it is a collection o$ objects
;bjectsK is an instance o$ a class
(l%ost like struct, t!e de$ault privacy speci$ication is private ,!ereas ,it! struct, t!e de$ault privacy
speci$ication is public
Exa%pleK
class point
M
double x, yN GG i%plicitly private
publicK
void print12N
void set1 double u, double v 2N
ON
12% D./*,. *,'.0*)(,7.
In!eritance
P ;bjects are o$ten de$ined in ter%s o$ !ierarc!ical classes ,it! a base class and one or %ore levels o$
classes t!at in!erit $ro% t!e classes t!at are above it in t!e !ierarc!y
P For instance, grap!ics objects %ig!t be de$ined as $ollo,sK
Syntax $or In!eritance
class derivedClass K public baseClass M
private K
GG -eclarations o$ additional %e%bers, i$ needed
publicK
GG -eclarations o$ additional %e%bers, i$ needed
protectedK
GG -eclarations o$ additional %e%bers, i$ needed
O
13% D./*,. .,7(<+;:()*6,
Encapsulation is one o$ t!r %ost i%portant $eatures o$ a classIt is t!e process os co%bining %e%ber
$unctions and t!e data it %anipulates by logically binding t!e data ane keeping t!e% sa$e $ro% outside
inter$erence
14% D./*,. (9+)0(7)*6,%
Creation o$ ,ell-de$ined inter$ace $or an object, separate $ro% its i%ple%entation
eg, key $unctionalities 1init, add, delete, count, print2 ,!ic! can be called independently o$ kno,ing
!o, an object is i%ple%ented
1!% D./*,. <6:4?60<'*+?
"oly%orp!is% %eans 5!aving %any $or%s6 It allo,s di$$erent objects to respond to t!e sa%e %essage
in di$$erent ,ays, t!e response speci$ic to t!e type o$ t!e object
Eg t!e %essage display-etails12 o$ t!e "erson class s!ould give di$$erent results ,!en send to a Student
object 1eg t!e enrol%ent nu%ber2
1=% L*+) 6;) )'. 9.,./*)+ 6/ 66<+%
P Can create ne, progra%s $aster because ,e can reuse code
P Easier to create ne, data types
P Easier %e%ory %anage%ent
P "rogra%s s!ould be less bug-prone, as it uses a stricter syntax and type c!ecking
P Q-ata !idingR, t!e usage o$ data by one progra% part ,!ile ot!er progra% parts cannot access t!e data
4ill ,!iten your teet!
17% L*+) 6;) )'. (<<:*7()*6, 6/ 66<+%
P Client server co%puting
P Si%ulation suc! as $lig!t si%ulations
P ;bject-oriented database applications
P (rti$icial intelligence and expert syste%
P Co%puter aided design and %anu$acturing syste%s
1>% D./*,. -()( '*-*,B%
T!e purpose o$ t!e exception !andling %ec!anis% is to provide a %eans to detect and report an
5exceptional circu%stance6 so t!at appropriate action can be taken
19% &'() *+ )'. ;+. 6/ +76<. 0.+6:;)*6, 6<.0()601
In C, t!e global version o$ t!e variable cannot be accessed $ro% ,it!in t!e inner block C++ resolves t!is
proble% by introducing a ne, operator KK called t!e scope resolution operator It is used to uncover a
!idden variable
SyntaxK
KK variable na%e
20% &'., 5*:: 46; ?(3. ( /;,7)*6, *,:*,.1
4!en t!e $unction de$inition is s%all, ,e can %ake t!at $unction an inline $unction and ,e can %ainly
go $or inline $unction to eli%inate t!e cost o$ calls to s%all $unctions
21% &'() *+ 68.0:6(-*,B1
;verloading re$ers to t!e use o$ t!e sa%e t!ing $or di$$erent purposes
T!ere are 8 types o$ overloadingK
P Function overloading
P ;perator overloading
22% &'() *+ )'. -*//.0.,7. 9.)5.., ,60?(: /;,7)*6, (,- ( 0.7;0+*8. /;,7)*6,1
( recursive $unction is a $unction, ,!ic! call it ,!ereas a nor%al $unction does not
Becursive $unction canCt be directly invoked by %ain $unction
23% &'() (0. 69A.7)+1 H65 (0. )'.4 70.().-1
;bjects are basic run-ti%e entities in an object-oriented progra%%ing syste% T!e class variables are
kno,n as objects ;bjects are created by using t!e syntaxK
classna%e obj3,obj8,S,objnN
1or2 during de$inition o$ t!e classK
class classna%e
M
-------
Oobj3,obj8,S,objnN
24% L*+) +6?. 6/ )'. +<.7*(: <06<.0)*.+ 6/ 76,+)0;7)60 /;,7)*6,%
P T!ey s!ould be declared in t!e public section
P T!ey are invoked auto%atically ,!en t!e objects are created
P T!ey do not !ave return types, not even void and cannot return values
P Constructors cannot be virtual
)ike ot!er C++ $unctions, t!ey can !ave de$ault argu%ents
2!% D.+70*9. )'. *?<60)(,7. 6/ -.+)0;7)60%
( destructor destroys t!e objects t!at !ave been created by a constructor upon exit $ro% t!e progra% or
block to release %e%ory space $or $uture use It is a %e%ber $unction ,!ose na%e is t!e sa%e as t!e
class na%e but is preceded by a tilde
SyntaxK
Tclassna%e12M O
2=% &'() -6 46; ?.(, 94 /0*.,- /;,7)*6,+1
C++ allo,s so%e co%%on $unctions to be %ade $riendly ,it! any nu%ber o$ classes, t!ereby allo,ing
t!e $unction to !ave access to t!e private data o$ t!se classes Suc! a $unction need not be a %e%ber o$
any o$ t!ese classes Suc! co%%on $unctions are called $riend $unctions
27% &'() (0. ?.?9.0 /;,7)*6,+1
Functions t!at are declared ,it!in t!e class de$inition are re$erred as %e%ber $unction
2>% D./*,. -4,(?*7 9*,-*,B%
-yna%ic binding %eans t!at t!e code associated ,it! a given procedure call is not kno,n until t!e ti%e
o$ t!e call at run-ti%e
PART B
3 Explain t!e basic concepts o$ object oriented progra%%ing in detail ,it! exa%ple
8 )ist out t!e bene$its and applications o$ ;;"S
7 4rite a note on t!e basic data types in C++
> 4!at are control structuresJExplain its types ,it! exa%ple
A Explain call by re$erence ,call by value and inline $unctions in detail using exa%ples
= -e$ine $unction overloading,rite a progra% to illustrate in detail using exa%ples
: Explain arrays ,it!in a class ,it! an exa%ple progra%
U 4!at is $riend $unctionJ,rite a progra% and explain $riend $unction
V Explain constructor and -estructor using an exa%ple progra%
39 State t!e rules to be $ollo,ed ,!ile overloading an operator 4rite a progra% to illustrate
overloading
UNIT-II
PART-A
1%&'() (0. )'. 7++ 6<.0()60+ )'() 7(,,6) 9. 68.0:6(-.-1
SiEe operator 1siEeo$2
Scope resolution operator 1KK2
%e%ber access operators1 , F2
Conditional operator 1JK2
2% &'() *+ ( 8*0);(: 9(+. 7:(++1
4!en a class is declared as virtual c++ takes care to see t!at only copy o$ t!at class is in!erited,
regardless o$ !o, %any in!eritance pat!s exist bet,een t!e virtual base class and a derived class
3% &'() *+ )'. -*//.0.,7. 9.)5.., 9(+. 7:(++ (,- -.0*8.- 7:(++1
T!e biggest di$$erence bet,een t!e base class and t!e derived class is t!at t!e derived class contains t!e
data %e%bers o$ bot! t!e base and its o,n data %e%bers T!e ot!er di$$erence is based on t!e visibility
%odes o$ t!e data %e%bers
4% &'() (0. )'. 0;:.+ B68.0,*,B )'. -.7:(0()*6, 6/ ( 7:(++ 6/ ?;:)*<:. *,'.0*)(,7.1
P 'ore t!an one class na%e s!ould be speci$ied a$ter t!e K sy%bol
P #isibility %odes %ust be taken care o$
I$ several in!eritance pat!s are e%ployed $or a single derived class t!e base class %ust be appropriately
declared
!% M.,)*6, )'. )4<.+ 6/ *,'.0*)(,7.%
3Single in!eritance
8 'ultiple in!eritance
7 &ierarc!ical in!eritance
> 'ultilevel in!eritance
A &ybrid in!eritance
=% D./*,. -4,(?*7 9*,-*,B%
-yna%ic binding %eans t!at t!e code associated ,it! a given procedure call is not kno,n until t!e ti%e
o$ t!e call at run-ti%e
7% &'() -6 ; ?.(, 94 <;0. 8*0);(: /;,7)*6,+1
( pure virtual $unction is a $unction declared in a base class t!at !as no de$inition relative to t!e base
class In suc! cases, t!e co%piler re*uires eac! derived class to eit!er de$ine t!e $unction or redeclare it
as a pure virtual $unction ( class containing pure virtual $unctions cannot be used to declare any objects
o$ its o,n
>% &'() (0. ).?<:().+1
Te%plates enable us to de$ine generic classes ( te%plate can be considered as a kind o$ %acro 4!en an
object o$ a speci$ic type is de$ined $or actual use, t!e te%plate de$inition $or t!at class is substituted ,it!
t!e re*uired data type Since a te%plate is de$ined ,it! a para%eter t!at ,ould be replaced by t!e
speci$ic data type at t!e ti%e o$ actual use o$ t!e class or $unction, t!e te%plates are so%eti%es called
para%eteriEed classes or $unctions
9% &'() *+ .@7.<)*6, '(,-:*,B1
T!e purpose o$ t!e exception !andling %ec!anis% is to provide a %eans to detect and report an
5exceptional circu%stance6 so t!at appropriate action can be taken
10% G*8. )'. B.,.0(: /60?() 6/ 7:(++ ).?<:().%
T!e general $or%at o$ a class te%plate isK
te%plate
class classna%e
M
GGSSS
GGclass %e%ber speci$ication
GG,it! anony%ous type T
GG,!erever appropriate
GGSSS
ON
11% L*+) )'. 3*,-+ 6/ .@7.<)*6,%
Exceptions are o$ t,o kinds na%ely
P Sync!ronous exceptions
P (sync!ronous exceptions
12% &'() (0. )'. .0060+ *, +4,7'06,6;+ )4<. .@7.<)*6,+1
Errors suc! as 5out-o$-range index6 and 5over-$lo,6 belong to t!e sync!ronous type exceptions
13% &'() (0. )'. .0060+ *, (+4,7'06,6;+ )4<. .@7.<)*6,+1
T!e errors t!at ,are caused by errors beyond t!e control o$ t!e progra% 1suc! as keyboard interrupts2 are
called async!ronous exceptions
14% &'() (0. )'. )(+3+ )'() (0. <.0/60?.- 94 )'. .0060 '(,-:*,B ?.7'(,*+?1
T!e %ec!anis% suggests a separate error !andling code t!at per$or%s t!e $ollo,ing tasksK
32 Find t!e proble% 1&it t!e exception2
82 In$or% t!at an error !as occurred 1T!ro, t!e exception2
72 Beceive t!e error in$or%ation 1Catc! t!e exception2
>2 Take corrective actions 1&andle t!e exception2
1!% M.,)*6, )'. 3.4 560-+ ;+.- *, .@7.<)*6, '(,-:*,B%
T!e key,ords used in exception !andling are
P t!ro,
P try
P catc!
1=% L*+) )'. *6+ /60?() /;,7)*6,%
T!e ios $or%at $unctions are as $ollo,sK
P ,idt!12
P precision12
P $ill12
P set$12
P unset$12
17% L*+) )'. ?(,*<;:()60+%
T!e %anipulators areK
P set,12
P setprecision12
P set$ill12
P setios$lags12
P resetios$lags12
1>% M.,)*6, )'. .C;*7(:.,) *6+ /;,7)*6, /60 ?(,*<;:()60+
'anipulator E*uivalent ios $unction
set,1int ,2 ,idt!12
setprecision1int d2 precision12
set$ill1int c2 $ill12
setios$lags1long $2 set$12
resetios$lags1long $2 unset$12
endl 5Wn6
19% D./*,. /*:: /;,7)*6,+%
T!e $ill1 2 $unction can be used to $ill t!e unused positions o$ t!e $ield by any desired c!aracter rat!er
t!an by ,!ite spaces 1by de$ault2 It is used in t!e $ollo,ing $or%K
cout$ill1c!2N
,!ere c! represents t!e c!aracter ,!ic! is used $or $illing t!e unused positions For exa%ple, t!e
state%ents
cout$ill1XFC2N
cout,idt!1392N
coutYYA8A9YY6Wn6N
,ill produce t!e $ollo,ing outputK
20 %G*8. )'. +4,)(@ 6/ .@7.<)*6, '(,-:*,B ?.7'(,*+?%
T!e syntax o$ exception !andling %ec!anis% is as $ollo,sK
try
M
---------------------
t!ro, exception
---------------------
O
catc!1type argu%ents2
M
---------------------
---------------------
O
----------------------
----------------------
PART B
3 Explain %ultiple in!eritances ,it! suitable c++ coding
8 -e$ine poly%orp!is% Explain t!e di$$erent types o$ poly%orp!is%
7 Explain %ultiple catc! state%ent ,it! !elp o$ suitable C++ coding
> -escribe t!e various $ile %odes and its syntax
A 4!at is virtual base classJ Explain using a progra%
=Explain elaborately t!e exception !andling %ec!anis%
:.ive an exa%ple progra% and explain %ultiple catc! state%ent using t!at
UExplain t!is pointer using a progra%
UNIT-III
PART-A
1%&0*). -65, )'. -./*,*)*6, 6/ -()( +)0;7);0.+1
( data structure is a %at!e%atical or logical ,ay o$ organiEing data in t!e %e%ory t!at consider not
only t!e ite%s stored but also t!e relations!ip to eac! ot!er and also it is c!aracteriEed by accessing
$unctions
2% G*8. /.5 .@(?<:.+ /60 -()( +)0;7);0.+1
Stacks, 0ueue, )inked list, Trees, grap!s
3% D./*,. A:B60*)'?1
(lgorit!% is a solution to a proble% independent o$ progra%%ing language It consist o$ set o$ $inite
steps ,!ic!, ,!en carried out $or a given set o$ inputs, produce t!e corresponding output and ter%inate
in a $inite ti%e
4% &'() (0. )'. /.();0.+ 6/ (, .//*7*.,) (:B60*)'?1
P Free o$ a%biguity
P E$$icient in execution ti%e
P Concise and co%pact
P Co%pleteness
P -e$initeness
P Finiteness
!% L*+) -65, (,4 /6;0 (<<:*7()*6,+ 6/ -()( +)0;7);0.+1
Co%piler design
;perating Syste%
-atabase 'anage%ent syste%
/et,ork analysis
=% &'() *+ ?.(,) 94 (, (9+)0(7) -()( )4<. DADTE1
(n (-T is a set o$ operation ( use$ul tool $or speci$ying t!e logical properties o$ a datatype is t!e
abstract data type(-T re$ers to t!e basic %at!e%atical concept t!at de$ines t!e datatype
Eg;bjects suc! as list, set and grap! along t!eir operations can be vie,ed as (-TRs
7% &'() (0. )'. 6<.0()*6,+ 6/ ADT1
<nion, Intersection, siEe, co%ple%ent and $ind are t!e various operations o$ (-T
>% &'() *+ ?.(,) 94 :*+) ADT1
)ist (-T is a se*uential storage structure .eneral list o$ t!e $or% a3, a8, a7S, an and t!e siEe o$ t!e
list is RnR (ny ele%ent in t!e list at t!e position I is de$ined to be ai, ai+3 t!e successor o$ ai and ai-3 is
t!e predecessor o$ ai
9% &'() (0. )'. )56 <(0)+ 6/ ADT1
P #alue de$inition
P ;perator de$inition
10% &'() *+ ( S.C;.,7.1
( se*uence is si%ply an ordered set o$ ele%ents( se*uence S is so%eti%es ,ritten as t!e enu%eration
o$ its ele%ents,suc! as
S II$ S contains n ele%ents,t!en lengt! o$ S is n
11% D./*,. :.,DSEF/*0+)DSEF:(+)DSEF,*:+.C 1
len1S2 is t!e lengt! o$ t!e se*uence S
$irst1S2 returns t!e value o$ t!e $irst ele%ent o$ S
last1S2 returns t!e value o$ t!e last ele%ent o$ S
nilse* KSe*uence o$ lengt! 9 is nilse* ie, contains no ele%ent
12% &'() (0. )'. )56 9(+*7 6<.0()*6,+ )'() (77.++ (, (00(41
ExtractionK
Extraction operation is a $unction t!at accepts an array, a ,an index,i,and
returns an ele%ent o$ t!e array
StoringK
Storing operation accepts an array , a ,an index i , and an ele%ent x
13% D./*,. S)0;7);0.1
( Structure is a group o$ ite%s in ,!ic! eac! ite% is identi$ied by its o,n identi$ier ,eac! o$ ,!ic! is
kno,n as a %e%ber o$ t!e structure
14% D./*,. U,*6, 1
<nion is collection o$ Structures ,,!ic! per%its a variable to be interpreted in several di$$erent ,ays
1!% D./*,. A;)6?()*7 (,- E@).0,(: 8(0*(9:.+1
(uto%atic variables are variables t!at are allocated storage ,!en t!e $unction is invoked
External variables are variables t!at are declared outside any $unction and are allocated storage at t!e
point at ,!ic! t!ey are $irst encountered $or t!e re%einder o$ t!e progra%Cs execution
1=% &'() *+ ( S)(731
( Stack is an ordered collection o$ ite%s into ,!ic! ne, ite%s %ay be inserted and $ro%
,!ic! ite%s %ay be deleted at one end, called t!e top o$ t!e stack T!e ot!er na%e o$ stack is
)ast-in -First-out list
17% &'() (0. )'. )56 6<.0()*6,+ 6/ S)(731
P Z "<S&
P Z ";"
1>% &'() *+ ( G;.;.1
( 0ueue is an ordered collection o$ ite%s $ro% ,!ic! ite%s %ay be deleted at
one end called t!e $ront o$ t!e *ueue and into ,!ic! te%s %ay be inserted at
t!e ot!er end called rear o$ t!e *ueue0ueue is called as Firstin-First-
;ut1FIF;2
19% &'() *+ ( P0*60*)4 G;.;.1
"riority *ueue is a data structure in ,!ic! t!e intrinsic ordering o$ t!e ele%ents does deter%ine t!e
results o$ its basic operations (scending and -escending priority *ueue are t!e t,o types o$ "riority
*ueue
20% &'() *+ ( :*,3.- :*+)1
)inked list is a kind o$ series o$ data structures, ,!ic! are not necessarily adjacent in %e%ory Eac!
structure contain t!e ele%ent and a pointer to a record containing its successor
21% &'() *+ ( -6;9:4 :*,3.- :*+)1
In a si%ple linked list, t!ere ,ill be one pointer na%ed as R/E[T ";I/TEBR to point t!e next ele%ent,
,!ere as in a doubly linked list, t!ere ,ill be t,o pointers one to point t!e next ele%ent and t!e ot!er to
point t!e previous ele%ent location
22% D./*,. -6;9:. 7*07;:(0:4 :*,3.- :*+)1
In a doubly linked list, i$ t!e last node or pointer o$ t!e list, point to t!e $irst ele%ent o$ t!e list,t!en it is
a circularly linked list
23% &'() *+ ( 7*07;:(0 C;.;.1
T!e *ueue, ,!ic! ,raps around upon reac!ing t!e end o$ t!e array is called as circular *ueue
24% D./*,. ?(@ (,- ?*, '.(<1
( !eap in ,!ic! t!e parent !as a larger key t!an t!e c!ildRs is called a %ax !eap
( !eap in ,!ic! t!e parent !as a s%aller key t!an t!e c!ild is called a %in !eap
PART B
3 Explain !o, pointer are used to i%ple%ent linked list structure
8 Explain various operation per$or%ed on t!e doubly linked list
7 .ive linked list i%ple%entation o$ stack operation
> 4!at is a stackJ Explain any t,o operations per$or%ed on a stack ,it! re*uired algorit!%
A State and explain t!e priority *ueue ,it! exa%ple
= Explain, ,it! exa%ple t!e basic !eap operations and ,rite t!e algorit!%s $or t!e sa%e
: Explain t!e cursor i%ple%entation o$ list (-T ,it! appropriate $unctions
U Explain t!e array i%ple%entation o$ *ueue (-T ,it! appropriate $unctions
V4!at is binary !eapJ 'ention its properties and explain its various operations
39&o, is !as! tables i%ple%entedJ Explain open addressing in detail
UNIT IV
PART A
1% D./*,. ,6,-:*,.(0 -()( +)0;7);0.1
-ata structure ,!ic! is capable o$ expressing %ore co%plex relations!ip t!an t!at o$ p!ysical adjacency
is called non-linear data structure
2% D./*,. )0..1
( tree is a data structure, ,!ic! represents !ierarc!ical relations!ip bet,een individual -ata ite%s
3%D./*,. 7'*:- (,- <(0.,) 6/ ( )0..%
T!e root o$ eac! subtree is said to be a c!ild o$ XrC and XrC is t!e parent o$ eac! subtree root
4% D./*,. :.(/1
In a directed tree any node ,!ic! !as out degree o is called a ter%inal node or a lea$
!% &'() *+ ( B*,(04 )0..1
( +inary tree is a $inite set o$ ele%ents t!at is eit!er e%pty or is partitioned into t!ree disjoint subsets
T!e $irst subset contains a single ele%ent called t!e root o$ t!e tree T!e ot!er t,o subsets are t!e%selves
binary trees called t!e le$t and rig!t sub trees
=% &'() (0. )'. (<<:*7()*6,+ 6/ 9*,(04 )0..1
+inary tree is used in data processing
a File index sc!e%es
b &ierarc!ical database %anage%ent syste%
7% &'() *+ ?.(,) 94 )0(8.0+*,B1
Traversing a tree %eans processing it in suc! a ,ay, t!at eac! node is visited only once
>% &'() (0. )'. -*//.0.,) )4<.+ 6/ )0(8.0+*,B1
T!e di$$erent types o$ traversing are
a"re-order traversal-yields pre$ix $or% o$ expression
b In-order traversal-yields in$ix $or% o$ expression
c "ost-order traversal-yields post$ix $or% o$ expression
9% &'() (0. )'. )56 ?.)'6-+ 6/ 9*,(04 )0.. *?<:.?.,)()*6,1
T,o %et!ods to i%ple%ent a binary tree are,
a )inear representation
b )inked representation
10% D./*,. G0(<'1
( grap! . consist o$ a none%pty set # ,!ic! is a set o$ nodes o$ t!e grap!, a set E ,!ic! is t!e set o$
edges o$ t!e grap!, and a %apping $ro% t!e set $or edge E to a set o$ pairs o$ ele%ents o$ #
It can also be represented as .I1#, E2
11% D./*,. (-A(7.,) ,6-.+1
(ny t,o nodes ,!ic! are connected by an edge in a grap! are called adjacent nodes For Exa%ple, i$ and
edge x\E is associated ,it! a pair o$ nodes 1u,v2 ,!ere u, v \ #, t!en ,e say t!at t!e edge x connects t!e
nodes u and v
12%N(?. )'. -*//.0.,) 5(4+ 6/ 0.<0.+.,)*,B ( B0(<'1
a (djacency %atrix
b (djacency list
13% &'() (0. )'. )56 )0(8.0+(: +)0().B*.+ ;+.- *, )0(8.0+*,B ( B0(<'1
a +readt! $irst searc!
b -ept! $irst searc!
14% &'() *+ (, (747:*7 B0(<'1
( si%ple diagra% ,!ic! does not !ave any cycles is called an acyclic grap!
1!% G*8. +6?. .@(?<:. 6/ NP 76?<:.). <069:.?+%
&a%iltonian circuit
Travelling sales%en proble%s
1=%&'() (0. AVL )0..+1
(n (#) tree is a binary searc! tree ,it! a balancing conditionFor every node in t!e tree t!e !eig! o$ t!e
le$t and rig!t subtrees can di$$er at %ost by 3T!e !eig!t o$ an e%pty tree is de$ined to be -3It ensures
t!at t!e dept! o$ t!e tree is ;1log /2
17%&'() *+ )6<6:6B*7(: +60)1
( topological sort is an ordering o$ vertices in a directed acyclic grap!,suc! t!at i$ t!ere is a pat! $ro% vi
t!en vj appears a$ter vi in t!e ordering
1>%&'() *+ +*,B:. +6;07. +'60).+) <()' <069:.?1
.iven as an input a ,eig!ted grap!, .I1#,E2 and a distinguis!ed vertex,CsC $ind t!e s!ortest ,eig!ted
pat! $ro% XsC to every ot!er vertex in .
19%M.,)*6, +6?. +'60).+) <()' <069:.?+%
<n,eig!ted s!ortest pat!s
-ijikstraCs algorit!%
(ll-pairs s!ortest pat!s
20%&'() (0. )'. (:B60*)'?+ ;+.- )6 /*,- )'. ?*,*?;? +<(,,*,B )0..1
"ri%Cs algorit!%
DruskalCs algorit!%
PART B
3 Explain -ijkstraCs algorit!% using t!e $ollo,ing grap! Find t!e s!ortes pat! bet,een
v3,v8,v7,v>,vA,v= @ v:
8 4rite (-T operation $or "ri%Cs (lgorit!%
7 Explain t!e topological sort algorit!%
> 4rite suitable (-T operation $or s!ortest pat! proble% S!o, t!e si%ulation o$ s!ortest pat! ,it! an
exa%ple grap!
A &o, do you construct a %ini%u% cost spanning tree ,it! "ri%Cs algorit!%J
= Explain dept! $irst searc! on a grap! ,it! necessary data structures
: -iscuss and ,rite t!e progra% to per$or% topological sorting
U 4!at is single source s!ortest pat! proble%J -iscuss -ijkstraCs single source s!ortest pat! algorit!%
,it! an exa%ple
V 4rite an algorit!% to $ind t!e %ini%u% cost spanning tree o$ an undirected ,eig!ted grap!
39 Explain -ept! $irst @ +readt! First Traversal algorit!%s
33 Explain DruskalCs algorit!% ,it! an exa%ple
UNIT V
PART A
1% &'() *+ ?.(,) 94 +60)*,B1
;rdering t!e data in an increasing or decreasing $as!ion according to so%e relations!ip a%ong t!e data
ite% is called sorting
2% &'() (0. )'. )56 ?(*, 7:(++*/*7()*6,+ 6/ +60)*,B 9(+.- 6, )'. +6;07. 6/ -()(1
a Internal sorting
b External sorting
3% &'() *+ ?.(,) 94 .@).0,(: +60)*,B1
External sorting is a process o$ sorting in ,!ic! large blocks o$ data stored in storage -evices are %oved
to t!e %ain %e%ory and t!en sorted
4% &'() *+ ?.(,) 94 *,).0,(: +60)*,B1
Internal sorting is a process o$ sorting t!e data in t!e %ain %e%ory
!% &'() (0. )'. 8(0*6;+ /(7)60+ )6 9. 76,+*-.0.- *, -.7*-*,B ( +60)*,B (:B60*)'?1
a "rogra%%ing ti%e
b Execution ti%e o$ t!e progra%
c 'e%ory needed $or progra% environ%ent
=% &'() *+ )'. ?(*, *-.( *, B;99:. +60)1
T!e basic idea underlying t!e bubble sort is to pass t!roug! t!e $ile se*uentially Several ti%es Eac!
pass consists o$ co%paring eac! ele%ent in t!e $ile ,it! its successor 1x]i^ and x]i+3^ and interc!anging
t!e t,o ele%ents i$ t!ey are not in proper order
7% &'() *+ )'. 9(+*7 *-.( 6/ +'.:: +60)1
Instead o$ sorting t!e entire array at once, it is $irst divide t!e array into s%aller
seg%ents, ,!ic! are t!en separately sorted using t!e insertion sort
>% &'() *+ )'. <;0<6+. 6/ C;*73 +60)1
T!e purpose o$ t!e *uick sort is to %ove a data ite% in t!e correct direction, just
enoug! $or to reac! its $inal place in t!e array
9% &'() *+ )'. (-8(,)(B. 6/ C;*73 +60)1
0uick sort reduces unnecessary s,aps and %oves an ite% to a greater distance, in one %ove
10% &'() *+ )'. (8.0(B. .//*7*.,74 6/ '.(< +60)1
T!e average e$$iciency o$ !eap sort is 9 1n1log8 n22 ,!ere, n is t!e nu%ber o$
ele%ents sorted
11% D./*,. A:B60*)'?%
(n algorit!% is clearly speci$ied set o$ si%ple instructions to be $ollo,ed to
solve a proble% T!e algorit!% $or%s a base $or progra%
12% &'() *+ 76?<:.@*)4 (,(:4+*+1
It is t!e analysis o$ t!e a%ount o$ %e%ory and ti%e an algorit!% re*uires to
co%pletion
T!ere are t,o types o$ Co%plexity
P Space Co%plexity
P Ti%e Co%plexity
13% &'() *+ <.0/60?(,7. (,(:4+*+ 6/ (, (:B60*)'?1
T!e analysis o$ t!e per$or%ance o$ an algorit!% based on speci$ication is called
per$or%ance analysis It is loosely divided into
a "riori esti%ates
b "osterior Testing
14% D./*,. +<(7. 76?<:.@*)4%
Space co%plexity o$ an algorit!% is t!e a%ount o$ %e%ory it needs to run to
co%pletion
1!% D./*,. )*?. 76?<:.@*)4%
Ti%e co%plexity is t!e a%ount o$ co%puter ti%e an algorit!% re*uires to run
to co%pletion
1=% &'() -6.+ (+4?<)6)*7 ,6)()*6, ?.(,1
(sy%ptotic notations are ter%inology t!at is introduced to enable us to %ake %eaning$ul state%ents
about t!e ti%e and space co%plexity o$ an algorit!%
T!e di$$erent notations are
P +ig ;! notation
P ;%ega notation
P T!eta notation
17% D./*,. 9.+) 7(+. 6/ (, (:B60*)'?%
It is t!e s!ortest ti%e t!at an algorit!% ,ill use over all instances o$ siEe n $or
a given proble% to produce t!e result
1>% &'() *+ -*8*-. (,- 76,C;.0 ).7',*C;.1
-ivide and Con*uer algorit!% is based on dividing t!e proble% to be solved
into several, s%aller sub instances, solving t!e% independently and t!en co%bining
t!e sub instances solutions so as to yield a solution $or t!e original instance
19% &'() *+ -4,(?*7 <06B0(??*,B1
-yna%ic progra%%ing algorit!% is a general class o$ algorit!%s ,!ic! solve
proble%s by solving s%aller versions o$ t!e proble%, saving t!e solutions to t!e
s%all proble%s and t!en co%bining t!e% to solve t!e larger proble%s
20% D./*,. G0..-4 ?.)'6-%
T!e greedy %et!od suggests t!at one can devise an algorit!% t!at ,orks in stages, considering one input
at a ti%e (t eac! stage, a decision is %ade regarding ,!et!er a particular input is an opti%al solution
(n exa%ple $or solution using greedy %et!od is Xknapsack proble%C
21%L*+) +6?. (:B60*)'?+ ;+.+ D4,(?*7 P06B0??*,B%
'atrix-c!ain %ultiplication
;pti%al +inary Searc! Tree
9-3knapsack proble%
(ll-pairs S!ortest "at!
22%L*+) +6?. (:B60*)'?+ ;+.+ G0..-4 (<<06(7'%
-ijikistraCs algorit!%s,"ri%Cs algorit!%s ,DruskalCs algorit!%s
23%&'() *+ ('.::+60) (:+6 7(::.-1
S!ellsort is also called as di%inis!ing incre%ent sort
24%&'() *+ )'. 9(+*7 +)0().B4 6/ ?.0B. +60)1
'ergesort is t!e tec!ni*ue ,!ic! !as sorted subarrays ,!ic! are %erged to $or% a single sorted array
2!%&'() (0. )'. ).7',*C;.+ ;+.- )6 7'66+. )'. <*86) .:.?.,) /60 C;*73+60)1
T!e various tec!ni*ues are First ele%ent,Bando% pick 'edian o$ t!ree portioning
2=%H65 ?(,4 <6*,).0+ (0. ;+.- /60 C;*73+60)1
0uicksort re*uires t,o scans one $ro% le$t to rig!t and anot!er $ro% rig!t to le$t,so t,o pointers needed
$or t!e scans
27%H65 ?(,4 <6*,).0+ (0. ;+.- *, ?.0B.+60)1
T!ree pointers are used in %ergesort X(ptr $or t!e $irst sorted subarray,C+ptrC $or t!e second sorted
subarray and XcptrC $or t!e %erged sorted subarray
PART B
3 4rite a s!ort note on analysis o$ algorit!% -iscuss t!e various notations and t!eir co%plexities
8 Explain dyna%ic progra%%ing ,it! a suitable exa%ple
7 Explain t!e various notations used in t!e analysis o$ algorit!%s
> Explain any t,o algorit!% design tec!ni*ues ,it! suitable exa%ples
A Explain divide @ con*uer tec!ni*ue ,it! a suitable exa%ple
= -erive t!e best, average, ,orst case ti%e co%plexity o$ a linear searc! 1'ayG?une 899:2
: 4it! an exa%ple, explain !o, you ,ill %easure t!e e$$iciency o$ an algorit!% 1U2 1(prilG'ay 899U2
U 4rite *uick sort algorit!% and explain
V State and explain t!e algorit!% to per$or% !eap sort
39 State and explain t!e !u$$%anCs algorit!%

You might also like