Data Structures UNIT-1
Data Structures UNIT-1
Dota Struchue
Non- Pimitve
Primitve Datu structue
Structine
chaade Boaten
Non-Linean
Deta
Linen a Struetune
Structne
Areys
Taees
stachs
Canphs
Quaues
Paiitve Deta Stucune numhey andthe
uctne Conist of tha
Priie dete str
chanactes Lohich cne uit n pramg. Thee con be
operted direchy by the machne level
mamiplted on nten,net chuacten
instuctian. Baic dete type Seh as
omd Booleam Come undenpmite det stuctwes. Thee
data tyees Oue alo knon a imyple daty types
belauethay conwist of chenacens that connot be
dinded.
Von- pimitNe Deta svucte deved
data s dructe cune
eue those tht ae
Non-pimitve suctwe, Camnst
Strutues. Thee data
trom primitve date divety bg he machine lave En
opeatad on manipulsted
focws on fomotion a cet hate
nauctiows. homaenocs (Sam deetu tye)
element thots eithe tyee)amd noninen
n hateronsous (olibenand dat
fnthe dlvidod to ineon
Thee an gruche amd anamgemet
dota stuchne bued on the
neen Deta ructue
that maintouhy uinean
u nelaionhyg
Adeete struchne called a linen detu structue
among s element is tauhion. But in the
Heu, the data is unamged n a dinean
nend may nat he sequential.
memory the onangemend moy
Ex: Avtys, lintedlist,stacks,queves
rNon-inean Dost stucne
Non-inen data shuchue is a kin deta structue
n which data elomens ane not aanged in a Cegenkd
ondes Thereis a hienachicol nlsthionhip between
individut dacta items. tee,the inerton amd deleton
data s not poMible in a lineen fahion. Trees ane
oiaphs esamples f noninen data stchry.
buces S3 shald be
mumhe f Vades idelemet that we dacle
The the numhe he
Eyual to bnactets
ünice he Squaredeclared S element
cas Pal,we have bnaces 3S
of
écumple i i i i l vaus within Aften
cnd in te for each elomend.
Cnel vales, one toy
one
we have Speat;e s Paual will hove fve inteyey y
this decJartion,a y intializtion valws.
we hawe erovided's
Coun be aiied Cu onedimonion aay,
aay
two-dimnionl auay on ulticimeniona
One-imansion Aryay:T4 has delmt
Tt as stened in asendng sdarane Joation.
Two-dimemion Arry:TA Conist f muttiple nos
as
amd adumns of data element. IH is aluo alled
matiX
Mudtidimonionl Arays: mhclimeniond anay Con
ag. thdimenioned
lae dened
are not boendod to two inices en two
dimamiony. They Cen incude as mony inicas ay
Jeqied.
LimtaonAays ane f AxeJ ize.
’ Dataelemeti sdone in Contgoas memoy
Lootion Lohich moy not be al available
’ Ingetin amd dolehin element Cam be robemk
beloue f shigng f lement from theiv
poition.
Haseve,thee limitotians Cam he colwl by uuny
inked ist:
Aeelcotians
’ stonina ist d daa elamats balongmm to Same
uciiny stoasg ton the data shvuchnes
>Shunay binan tee elemady ed Axed Coet
Shanage od maties
I Linked List
A Lineed ist is a data stYuchaein which each dat
elemant Contein apointu on lin tothe next element
an the ist. Thoush Lineud ist inion and eleon a
the data elemend poseibla at all lacey d a linean ist
Aoin
Also inLinked lit, it 4s not nacersany dhohave the data
elenamt stonad in consectve Locotiong. TH loctes Space
Fov eachn dtatem inits own lock od Thus,
a ined istis Coideed memory
as a chain 'eta elemest
Necovds Called odes. Each nodein theist Contain
anjormaton eld on a pointa Aeld The ntoation
feld Contansthe actual dt cnd the poita feld Contais
aoes o the ebsagued nodes in the ist.
vocles
AA
Bottom
Gem be smplometed
Compute's manuscles Se hematie slach
Jn the anays on Linked ss . iyue is a top od the
dng element aa is the
Here, Elemmot are
diagnam da stack.is the botom o tho tack.
amd elemend AA
top. Snce A follos IFO
frorm the doletel, and
added to tha stack be doleted holere FF Js
Podten, EE Cannt delehed bebre EE Jsis delek
Simila DD Camnat be
and o on
operston
Apeicaians: struchune ten Jacuave
’ Temporarg stonag! for natad opetioms, fenchi
’Auidny sarage soructneAumions
Callsdeleined(pestond
"Function clls eprenions nn Vanjous
’Mamag
’Evolotion d anihmate
Joumguae nto poslk eaplati
Progiammng, erprenions
7ConNeion iny erpreins in a proynamnang
’chocng Syntxo
envivonmand:
Matching panendheis
on backtaclny
pnbemy soutions tree owesc
- In al the Seareh in aph and
-7Usedin depth rst
Opewtmg
’ UNOO Sytamfnctions §n cm editon.
Anctons in
y and REDO
SS 22
qpeatin inraphs.
Appiations uedin breadth search prid bullen
’ 4is oeations of os Like a the
stare
’ Jdo shaduley
keyband butfei queue to
qeu, by wwes
Kays prened Disk
sehedudnd
’ Prierity eues eneued nAde donndng
coperstions in a brose.
’ Docta trenten boteen peiphenl olevicey ad
cPU:
’ Lnteupts genented by the wien apphatong
yCals handled by he customeny in BPO.
vJTrees shructo jn which date
ee js a noninean dety tee
A The data elaments in
bvanches. hieraschidsutu
S ongenizel in imposeya
CMamged ina sasted onden. I!
On the data elements coist ?nas.
atree which
Below Hyure sapneent, Go ot the top. Noce 24
oot af the tee is the node The nodes 6, 4, (2
The he hode Go.
dhe SuccoKols od thoy do not hawe cny
dhe temind noley a
amd 67 ane
Succeons.
E
Nales situatiany
made odwanle
Hdvantang: Bet
Dsadvanty:Some alyonhmy slaw and vey Complex.
ppltson:Reprethy natwoley ond notey in Commnicatig
tiampentthn ond drovel applictions
and othe ntuok-baed
natwoly
IntaGonmectony in Socid
>Applstiy.
Mapping appiatony wen prento.
pplsions to preend
prdlems Doted to
Ecomen ce
netwole to idontity the
’ Utlity Load Conponaobihty
municfed onwslzton amd ploy Cannechvit,
’y Rarowce mop ad a webit do ds
Dacemety Lmka hypaln ks
batueen ponyes hnaugh
newral metwovly
Rdotic moion
dat Shructue
structne vs Oyramic
Staie deta aunel onganinng dota
stretwe is a way d sdonin on them Con
on
Oota ogined openadiony
Guch chot the to time as wellay
elficed wth nee neduce
be Royomad be cn wed to
Dada Structne
momongSinmpy Ahe time Complexity ) the Cade.
Condaiy (mesity two types
Dota Strucne Can be
static Data strucne
O Sructue
Dota
3) Dynomic ghructue 2 sdructneis tixed
Datu
what is a steudic the size ed the but
dota strudwe be modifed
In atic soructueCan alloctedd toit
Content d the data
The the momory Space
wthod chamgn
2 3 4 S
Arrag
Frst indax =0
Lat index =
Dode sructues: Avrag
Example d shatic Doda
(12)
Data Stuctre' hot
whed is Dynamie Stuctue ig
&tructune the size e the penfomel
InI Dynamic dot madifed dusng the oprtons
deigedto kaciitote
Fixedand Con be shrchue aue
On it Oyamics clat
tho n time.
Change o det shuctues in
Mead
Dcta Next
Linked L!.
Dunamte Date Structne
tatie Data Structune vs Dy size whereoy
Staie Dota gtiuctne -has tixed memory
sie can be amdomly
in Dgnami Date stuctne,he
be Coniden
vpdla duny thich may
mime cole.
fha
to momory
ficied wth npedprovices anplenty aces to
mone eoie
Staic Dot Shructe to dynaic olet structe. Unlilee
elements wih epect hamic dade suctres
Static dat structures, dy
Openatony on Dal Structues em exackley
meany to aclexs each dat
havetg: I4 eoample, to prnd
ba proceMed. För
Once soicd it can Sucorsn a clas.
e al tho
we to nd the Loctioy ef one on mare
Searchne:H s Conehat. Such a ot
dat tms thot adisy tho gren
be posent intho gven collectio
Hem mayon may ut fall tha
o data ems Fo exampls, to nd ho mames
sudonts Who Secune loo muks h mofhemoes.
Tnentg: I+ is ued to cdmes dota itemy to the given
Lis oaa items. Far eaumple, to dd he details o a new
Stydend whohas neconly joined the Couse.
(1S
Doletmg:-TH meny to emove Cdelote) a pantculon dety
collecbion d deta iHerns. or ecample
jtem from dhe qem the Couse.
a stclent who has lof
todalode the nane
items Cam be ouhcmged n some, oneen
Sontng:- Dota descendang onde depenng
Ailce asconding onde on descomdng
eseemmple,amongng Calclotng
nme
an algonthm tadee, a
a dong time do
’ hitg
is tima-Conmng
7Bremchng and Losping statemenls
to shaL nAlgonhn.
Oiffenand apploach do deignam algeuhn
1 Top-OoLan tpproch: Atopdoun approach Stats wrdh
idendiyng majon Compononts of syolom, on piagram
hemnto theinloiweevel Componends
dntompongnd Jovel f th module ormpleid,
topmest m
malle
is achiesed. In this we stant
3 incremently acld mole, hd 's coll.
2 Bottom-Up Appnaach ;- Abotom-vp apprach
stants wh dein mos prihnáve
Compononts sproiets do highes dovel bomponent
(19)
SAantng from eny bottom, opertony th povide layen
cf abikocion an mplernontal
How o wite an Algenthm?
Thene ane no shandans
wdlhdofncd eronce en lwnitrg olgeuny
Rathe, t is problom and dapondand. Alaan
Cue meven witento sppot penticulan proglammay
Code. pragramnng longoes shane
As we lenow dhad all (d,foy, Jnile), Flow.
e aos
Dauic Coda Conatuct Thae Common Contruct Can be
Condol it-ele) ete.
wred to wnte on aleyorhm. mamme,bd is
in a shep- by-shep is a poces
bwe lwnste oleyorhns Alqoithm
the care. onidmg
Cnd s etetec She problom doman is wel-dofred.
le sholl
Ihat is Le now the eroblem domauh, for which lwe
a Soltion.
Exampli
Ladlstry to leon olae°hm-tvdnga bg wng an
edample
Problom- Deiem am
amd
Stepl -S1ART
display
declore hee ndecey bc
a,
SBep2-
slep 3-done als o asb
stepa- aclel wouay &
os- stona outpud of step 4 oc
Steps
s\epb prnt
Slep- STop
o0)
Algonhs tell the prociammory haw to Cade he paam
aleyonthm Qan
Can be wtenay
nllonhvly,ho
Sepl SJART AoD
&lep3- Ceatb
SlepA - displayc
Sleps - STop.
SOP
In deign and analy agandms eyhe
Secondmahadis UsedSodobe am olsyahm.
TA modees it eay foy the cunalyt to analy 2e he
al nantoch olenúbions. how the
-sgnomng,
obieve wha opersoy cne beng wed Gnd
plocevs s flowmg
whiting step numdoen is opiono.
we dengm a Golution od aren
proem: A prolem Can be Galveel in mane hon one
Zolutiy
Problom
Soluhion
hus, hen nis nesta tham 2,, wee cyet ti)gín).Tn ohen
than
wondst ay n beComescyen, the mng me Annee
Cowid This melardes Cohcudeyhed the eig-0hes
dedemo i luope bolumd! od the algoilhys m-tme:
initetiowy od Big ONottion
Thene ane Certoh imittiory otn the BicO notation o
eapronng the Comnplexidy of leouts.Thee
Jitatio ae a, follows:
’Mamy alyonthms smply too hand to amalee
mathenatey
There moy nay na be Sutfiiecd infomodion to
n he ayery
Calclste the beaviBuy o thé algerhm
toll us how the olanhm grous
’ BigO noyis ony prcblem,
wth the sie of h not hos fiiend
ast oes not 'Conien the progmmng
Tt enanes amartand Contnt Fo exanple, i one
6lonhm tales Cn) me to execete amd the othen
tales o boo00n)tme to eaecte ,hen as per BicC)
boh elgonthmhave equal timebe complozity Tn
Sealime yomhis may aseiows Canhdewton
Umega Votation Omega
the epeentin toy Ormega notaion.
's is lhich am algonithn ponory
descbe he mamne in
lopleity This nototion provices
time
in the bet Care time talen by an alghm
he mnimum amound ee< t is Conideredthat
hus
Go Compde aproadern. band"'o the adgonithm's
Cmega gNe, he AsloLJe
dojned as?
Suntm. Omega
inputs cn oulpds amd
whae, n As amy numbe o functiony. hee
ane two non-negatve
onlyt henes e Contd e
tunchiows ae dre ho uch thod n>no
(30)
Omoga Can aso oe clomoted as fon) S(go) oen
to Oneya o gf. Thu grophical
n is eqlol f)-si(eov)is shon an tig 22.
Sepnaentoion ef S2 (gon)d Ton)s
Seic to be in toy all
The yemcion toàs Content nutiple od ge)
by soms
baundedl balas y.e.il dheoeist Some poitive Contont
Vaes fn. ,Such that
Veugs mon-naçatve ioyen no,
c cind Son
) C x an) for ol nno.
Shows Omoga metation.
Hquo 22
c*gh)
n)= n ) 7
Hene )=)
22+5=13
Let n=2,thon
Heo n ) )
to)c*g6).dis Coneucles
hat meya
yed algonhm's m-tme.
(W od ho
(3)
Theta Votion
nepresentation fov "Thela natation.Thota
'e'sthe
vppen boun mel losen bone
noation s uied Lohen the mnrutude.
o an aloenihm ane in the Same onder of
*Theta en be dened as:
Clxn) ta)ca* o)
ingut, on cutpt and i)
lwhene,ns any numbe a Ther functiong
non-hagotve Funchiony
Cond g) ne Aso Contants marmely. c,
true-onlyi thene cne two
cUle
C2 emd a non whene t n
denoed as fo)= Cgo)) Jhen
Thoda Can aluo be n.The qrophi praontotion
As equal to Thake of q f Q.3. The function
=g))s shin in iyue bolnded both obove
cf t ) fn) s
)s Said to be àn o(g)Contant mutples of )
and belw by Some positve exnts Some peitve
mon-hegothve inteyn no,
Contn ca endamd Some
shauy Thata Notostion.
Fige
Mo
Subprablem
Comput Conpte
Compte Subproboms Compute
Subproblom (Subproblem Subproblom
we Cam olow he dideamd-Conquon
Chenony
approach ina thuee-sBep proes
Example:
On the
The specije Canpten olonhms ae baed
Dvide covquen apploch:
A: Maimum and minimm bblem
Q Bnny Seanch
3 Sontinea (meee sSot, qyuick sont)
A.Towen o d tanoi.
Fundamedal o Dvide Conqen hstegg
Thau ane too fundamondads o Dvido sConqyen Shetog:
} Rolationa Tovmula
a. stopping Condition
1- Rolationa tomde: T4 ishe onmulathd we gonerte
Hrom dho qNen tochnique. Afer aenensdon oy Fovmla,
we appy D¯c eetayi:e ie break dhe problom nennvely
Solwe tho boken Bopobloms:
Stopena Condition tohon we bneok the problomo n
aShepeng eng
9hatoytham twe naod to leno. thad s
Dide Conguen Conque. So,he Condition
much t e , twe nosd to appy dvido
acunsion sleps o Dsc is called
Lhe he neod to stop on
Soppng Condiion.
and Congusn Appromch:
pplcotims of Ovide anebacon he ConCopt od tha
Follema olegonitm
Conguo Technique: seanch olohmhol-itoal
Seandh The binay abocaled a
m,hich s It wandes by Compaing
Sesnehngan
Seanch Lognithmatie Search. elomod eistng n
mmddle companison,i he
voe both tho
tha tng Aften malng the Genno eonaih
a cortoe aay: ay. hoy had
aets iens dhon the elininatosollowed oy agn
Value eventuoey we ceill
the tateed oil Sech onhe
ho elomon and
sheho
Compne it ith thg
Contnmdle
Contiden Re midUeproces aeps on lapeotng
Nolua. Tho
mo. I we Boand th
can be
hoy
ohe Concledto be
tauqed Value
oue s s Ahe Reach,thent
then t can
empty oter d an thea y
enng not presend
taretis e algandhn,
thod ho Soit shats
pntition- eachane follaed by
enoLJn as
Lwichisao pvot voue hromelemeny cn iayotwo Swb-a
a of he elomsis
y sdacng eoch
whehof he
tho elomot
didingpantidion Js mnade by Compann
Tho Noe companes
volhan the pivaf an
twrththo pvo value onloner losei
holds aa cyreolen vey
them ,od ho CUys
3 Menge Sondi T is a Sondingy oyonhm dhod Gand,dviding
CUncray y malng Compai sons. TH Sknts by
costs
into sub-amay amdthon Wecnnvely thom
Ech o Ahom. A4e he conting s done, iH moigen
back.
Alantages Dride anl Conqen Rucenhaly Solve one
’Dvide and Conquen to as dhe Touer ttanei,
AendSuch
of problems
the bigget
amadhemadicol puzzle.T\ 2s challorgn2Reve no boic
Comoictecl probloms fon wichhe davide
you d Conge appo
am
idaa, bud wth the theý of on dwidng
effont a it worles
it hey lesened thetoothalves and then eolwe"them
man pnoblem into
SoceiLwely. This algondhm is much foiten thon
ethon adorthms cache m
eieny uses momory Gubprublemy
’ IH solwes nple
Space secaue it inetesd ol aceuing the
wthn he cache momory
slawen main nemary
DisalNantap, o Onide cmdConquen
’Since mos otits
Anconporahmg
Seion,
mañenemont.
my
alorish sott
,Jaisnddigh
necesittes
the Spae.
nay ovene
An esplicit tack msy The hecuisn
’It may even Crah hs
qreoten han Ahe
s perfomad ieprouly
Stack pnerend in hecPU.
(36)
Bacletec kng
The Backtrackeg s cm clgorihm-mahed to golwe a
Problom wth an &dditinal iny.Hes a elsave
pproch to explash he probtomy. e cam Say Thd the
is neocod to fned all postible ombnosion
backtralng
o solve an gotimizaon problom
4 Rodun "foiene"
detmnos the eaution Joy
Backhackng algonhm Jhe Rotwtion spae or
Sydamaticy SconchangSs Airet Seonck wih any
problem. Baclehackmg a depth- bacdetackn s
baundng tencton. Complec Qetof ondents.
a o imlicid.
be
be eplicit
eplict veotan
Consdunts moy may Jule,wichtrict
lod. which hotict each
Expicit Constrd
Ezpliat dhosenyrom the ojven set
elomont to be dotemine which each
ecd.which Saty
Conthent S octslly
Implicit
n the lodution space,
o the tuples
tho ariteion hnetin
Oynamic praammhg cimiln to lide
üs problon
Dynamic oeminng cowe o
teeniue Bothdecniqes b-proolems that
and-Conquen it don irto, Beweralman diheremce between
bretng meman
Jecwvely. "The he problam
Cam be eswed oupproch pontitiony Sub-pobles
,Pvide Conguen eale tha Gub.
Js Ahat
ind.ependont Sub-prsbems, Solttowy sto
Jnto thein
Sacuvely and dhon Combne dyvmic
wheneassbproblems
problem
Sowe tho oNynaluppicothe whon the
}s Gulb-pnbloms shere
andepnkond thad is when
mot Subpuoblems. Albo, A namic potemnaivy
ut once anol
Sub prdolem
aleyonnms Sowes every Bub table.horeloy aoidh
hon Saves ts cnwerin el
/ seymu
-the twonk ol oComputme the
ri eNser eNeny time the
Sub cbproblem is eneounterol.
Thenejone "Oynamic
Swb problem
progammng-is pplicoble when
ae nol ndepelend, tha is Lwhen Gub
prsblem shane b roblorns 1