Data_Structures_and_Object_Oriented_Programming_in_C++

Embed Size (px)

Citation preview

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    1/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 &andlingTe%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!% netork $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 andCon*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, 5ata 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!, 5ata Structures and (lgorit!% (nalysis in C++6, 4iley student edition, 899:8 Sa!ni, 5ata Structures ?ean "aul Tre%blay @ "aul .Sorenson, (n Introduction to data structures it! applications, Tata'c.ra &ill edition, II Edition, 8998A ?o!n B&ubbard, Sc!au%s 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

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    2/13

    UNIT I

    PART A

    1% '() * (, *.,)*/*.

    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, loer caseletter, underscore and digits, but s!ould start only it! an alp!abet or an underscore2% '() * ( .56

    Deyords are ord !ose %eanings !ave been already de$ined in t!e c co%piler T!ey are also calledas reserved ords1ex2 %ain12, i$, else, else, i$, scan$, print$, sitc!, $or, goto, !ile ect,3% D./*,. 6,)(,) *, ++%

    Constants in c++ re$ers to $ixed values t!at do not c!ange during execution o$ a progra%4% D./*,. ( 8(*(:.%

    ( *uantity ,4!ic! %ay vary during execution o$ a progra% is called as a variable!% '() (. ;,( 6

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    3/13

    (l%ost like struct, t!e de$ault privacy speci$ication is private !ereas it! struct, t!e de$ault privacyspeci$ication is publicExa%pleKclass pointMdouble x, yN GG i%plicitly privatepublicKvoid print12Nvoid set1 double u, double v 2NON12% D./*,. *,'.*)(,.

    In!eritanceP ;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!yP For instance, grap!ics objects %ig!t be de$ined as $ollosKSyntax $or In!eritanceclass derivedClass K public baseClass Mprivate KGG eclarations o$ additional %e%bers, i$ neededpublicKGG eclarations o$ additional %e%bers, i$ neededprotectedKGG eclarations o$ additional %e%bers, i$ neededO13% D./*,. .,(

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    4/13

    5exceptional circu%stance6 so t!at appropriate action can be taken19% '() * )'. ;. 6/ 6% D./*,. ,(?* *,*,%

    yna%ic binding %eans t!at t!e code associated it! a given procedure call is not knon until t!e ti%eo$ t!e call at run-ti%e

    PART B

    3 Explain t!e basic concepts o$ object oriented progra%%ing in detail it! exa%ple8 )ist out t!e bene$its and applications o$ ;;"S

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    5/13

    7 4rite a note on t!e basic data types in C++> 4!at are control structuresJExplain its types it! exa%pleA Explain call by re$erence ,call by value and inline $unctions in detail using exa%ples= e$ine $unction overloadingrite 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 $unctionJrite a progra% and explain $riend $unctionV Explain constructor and estructor using an exa%ple progra%39 State t!e rules to be $olloed !ile overloading an operator 4rite a progra% to illustrate

    overloading UNIT-II

    PART-A

    1%'() (. )'. ++ 6 'ultilevel in!eritanceA &ybrid in!eritance=% D./*,. ,(?* *,*,%

    yna%ic binding %eans t!at t!e code associated it! a given procedure call is not knon until t!e ti%eo$ t!e call at run-ti%e7% '() 6 ; ?.(, % '() (. ).?

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    6/13

    T!e general $or%at o$ a class te%plate isKte%plateclass classna%eMGGGGclass %e%ber speci$icationGGit! anony%ous type TGG!erever appropriateGGON11% L*) )'. *, 6/ .@.

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    7/13

    19% D./*,. /*:: /;,)*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!ert!an by !ite spaces 1by de$ault2 It is used in t!e $olloing $or%Kcout$ill1c!2N!ere c! represents t!e c!aracter !ic! is used $or $illing t!e unused positions For exa%ple, t!estate%entscout$ill1X2Ncoutidt!1392NcoutYYA8A9YY6Wn6Nill produce t!e $olloing outputK20 %G*8. )'. ,)(@ 6/ .@. escribe t!e various $ile %odes and its syntaxA 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!atUExplain t!is pointer using a progra%

    UNIT-III

    PART-A

    1%*). 65, )'. ./*,*)*6, 6/ ()( ););.

    ( data structure is a %at!e%atical or logical ay o$ organiing data in t!e %e%ory t!at consider notonly t!e ite%s stored but also t!e relations!ip to eac! ot!er and also it is c!aracteried by accessing$unctions2% G*8. /.5 .@(?

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    8/13

    P Finiteness!% L*) 65, (, /6; (

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    9/13

    one end called t!e $ront o$ t!e *ueue and into !ic! te%s %ay be inserted att!e ot!er end called rear o$ t!e *ueue0ueue is called as Firstin-First-;ut1FIF;219% '() * ( P*6*) ;.;.

    "riority *ueue is a data structure in !ic! t!e intrinsic ordering o$ t!e ele%ents does deter%ine t!eresults o$ its basic operations (scending and escending priority *ueue are t!e to types o$ "riority*ueue20% '() * ( :*,. :*)

    )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 successor21% '() * ( 6;: :*,. :*)

    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 to pointers one to point t!e next ele%ent and t!e ot!er topoint t!e previous ele%ent location22% D./*,. 6;:. *;:(: :*,. :*)

    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 isa circularly linked list23% '() * ( *;:( ;.;.

    T!e *ueue, !ic! raps around upon reac!ing t!e end o$ t!e array is called as circular *ueue24% D./*,. ?(@ (, ?*, '.( 4!at is a stackJ Explain any to 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 $unctionsU Explain t!e array i%ple%entation o$ *ueue (T it! appropriate $unctionsV4!at is binary !eapJ 'ention its properties and explain its various operations39&o is !as! tables i%ple%entedJ Explain open addressing in detail UNIT IV

    PART A

    1% D./*,. ,6,-:*,.( ()( ););.

    ata structure !ic! is capable o$ expressing %ore co%plex relations!ip t!an t!at o$ p!ysical adjacencyis called non-linear data structure2% D./*,. )..

    ( tree is a data structure, !ic! represents !ierarc!ical relations!ip beteen individual ata ite%s3%D./*,. '*: (,

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    10/13

    7% '() * ?.(,) )(8.*,

    Traversing a tree %eans processing it in suc! a ay, t!at eac! node is visited only once>% '() (. )'. *//..,) )

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    11/13

    > 4rite suitable (T operation $or s!ortest pat! proble% S!o t!e si%ulation o$ s!ortest pat! it! anexa%ple grap!A &o do you construct a %ini%u% cost spanning tree it! "ri%s algorit!%J= Explain dept! $irst searc! on a grap! it! necessary data structures: iscuss and rite t!e progra% to per$or% topological sortingU 4!at is single source s!ortest pat! proble%J iscuss ijkstras single source s!ortest pat! algorit!%it! an exa%pleV 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!%s33 Explain Druskals algorit!% it! an exa%ple UNIT V

    PART A

    1% '() * ?.(,) 6)*,

    ;rdering t!e data in an increasing or decreasing $as!ion according to so%e relations!ip a%ong t!e dataite% is called sorting2% '() (. )'. )56 ?(*, :(*/*()*6, 6/ 6)*, (. 6, )'. 6;. 6/ ()(

    a Internal sortingb External sorting3% '() * ?.(,) .@).,(: 6)*,

    External sorting is a process o$ sorting in !ic! large blocks o$ data stored in storage evices are %ovedto t!e %ain %e%ory and t!en sorted4% '() * ?.(,) *,).,(: 6)*,

    Internal sorting is a process o$ sorting t!e data in t!e %ain %e%ory!% '() (. )'. 8(*6; /()6 )6 . 6,*.. *, .**, ( 6)*, (:6*)'?

    a "rogra%%ing ti%eb Execution ti%e o$ t!e progra%c 'e%ory needed $or progra% environ%ent=% '() * )'. ?(*, *.( *, B;:. 6)

    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!angingt!e to ele%ents i$ t!ey are not in proper order7% '() * )'. (* *.( 6/ '.:: 6)

    Instead o$ sorting t!e entire array at once, it is $irst divide t!e array into s%allerseg%ents, !ic! are t!en separately sorted using t!e insertion sort>% '() * )'.

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    12/13

    T!e analysis o$ t!e per$or%ance o$ an algorit!% based on speci$ication is calledper$or%ance analysis It is loosely divided intoa "riori esti%atesb "osterior Testing14% D./*,. % '() * *8*. (, 6,;. ).',*;.

    ivide and Con*uer algorit!% is based on dividing t!e proble% to be solvedinto several, s%aller sub instances, solving t!e% independently and t!en co%biningt!e sub instances solutions so as to yield a solution $or t!e original instance19% '() * ,(?*

  • 8/12/2019 Data_Structures_and_Object_Oriented_Programming_in_C++

    13/13

    3 4rite a s!ort note on analysis o$ algorit!% iscuss t!e various notations and t!eir co%plexities8 Explain dyna%ic progra%%ing it! a suitable exa%ple7 Explain t!e various notations used in t!e analysis o$ algorit!%s> Explain any to algorit!% design tec!ni*ues it! suitable exa%plesA 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 899U2U 4rite *uick sort algorit!% and explainV State and explain t!e algorit!% to per$or% !eap sort39 State and explain t!e !u$$%ans algorit!%