NOTES
DATE-16/1/2023
DSA
Note
-Subham mohanty> Dato Qtowefure fe a wey ols ie ond oxganies
data tn ouch a UY we ~ can perborm ‘¢
operations on these ota fo an Cbicient om
+ Dua aoructve fs - about render ofeta. elements
bor better organreattonI J
So} SUI 612) S23) sl}
1 want tog qhe highest monk, 90. oF 7
Comporsision, %3 OF mark 5 and acceding dhe. element
are ety by veasling confiniowss emer blocks -
Asso } Lroxed List, gto — Quente
Gree , Aaeph ,
New Ib
O Bevical pata grourture és clansbied e010
al carey ores ¥
— Poemitive DS % These are ofe
ong ove ojicceet wperoted upon,
, énf, bloat, foeble yO. (aa
Non = pains ive DS 1 These ore derived
pamitive Gato aoucture *
eg: frome fist 2tC.
@ pata Siouckyre can
Mointains ad oder
py ee het
@ersents:« ary fosertion Of F
wwii! Hor «chang? pep afVe
3]
of other elemenks
— Non Linear DS No order atn7e
Ensertion OF olojeproa mam
the. wejative order or0,
evcdTons on Dato Wrudure
_ cweadion
~ Snsertion
- Deleon ee
Travertine + Accessing oh Clercont 2
ro
eg: abssploye >, Coen
— Searchin:
= Sorting
- Reveaing
ate.
Scanned with CamScannerpy OME A a
Algesithro Analy sf 7
j
;
> These tS posevielialey ob multiple Golutions ona
pooblem :
> Then how FO tdentily chich olution €s better 7
we need 10 omalyee the Coiuetions /algeritoens »
> Analysts ob algarithans means to deforming aroun
ok mesources used by dhe. olgariths 4o Complete
execution ~
> g Ram usoge 3 Lpoce Cura a
cpu usege Pe Cope: 4
_
Total ormount oF Space arequired ( # RAM) fo
mention « (é bytes) !
complete The
Tieng Complensrd &
> Clanicol method ob analy27g
fs mot helph a ap Blepeads en
pie Complemt ig
aching Conbi—
ee, <
> $0 n é j
as a bunetion c data | £9
3 Te [ine - Count
he. dime. Complent bunetion +
foro number ee each fine puerFes «
For Enompig! Contholer the Foto Code
yo print RH Structure. ’
Scanned with CamScannerforam Cary tke tr) ote: ha ag
prcen day tet, I) Le pe
é o) "
cyseros cur pat C » ) ston) oe
/
3
agate ood ptiol ). a ee phen
3 re
Tne or gort
¢
Time Compleat function,
oof
909 mH poe th compen
eh .
oval w tt ckpends © prograrnre”
. jy eS. creprerented a he growth
~ functors (highet oun oa
Tlf jhecawwe when
jotbation ob other
fowords binol
Con’
jhe
Conta tout)
Scanned with CamScanner> Hence Fire - Complontt ts the oumber a Himes the |
bowie operation ob alge, pxeutes -
For enampre + Inthe above aigovth bavic.
operation ts point ("#") Statement .
> we one actually Eolerested bo order oF growth oF |
dhe punning time ob expqoitbeo, oop COHE ero.
wunning Hmg. This fs also crefente 05 2 optic,
KIS Asgmpronic oo
=> To cepresent
crows fecn Fo the Time Comp!
3 ro ee
dig FD Ferm
or by d;
Sy nal reed, tome Nota hiot: yi
1, Big 0h (0) 2
ae (54, - Omega 2)
3. BY -Theta ( 8’)
eta = 0(aera)
We ao”
a fr here eassk wo postive
Cc and. % Svc that
\7e)| e- [acm |
Aot od n &
(Here gto) i
Scanned witLot the — tiroe Complenity OF function of the od geatthn
found fo be T(n) = 8 nes Got! Represent
Yime bernie Bry -oh Netation .
02%
Ttoyne f° 90)
term tO the
hs own:
See ue get § : Such thot
choose
And chose © ona Mm
funeifon Ten)
tonelitron ii) saltsly .
rich eee ee
sno
gatr ants
chese ce atleost 4
becawe ki |, 2,3 Usnditruy
win Aer so
to bind no sets Seve the eg,
2
> 4ntl a)
we Con 2s fino thet bor one 1% ae
the Condition wi Not Satie .
fates ene” yy voles rene than & 5.
So m 25
Hence vy C= 4 ond Neh Smee ion
2
waite mai) = o(n )
Scanned with CamScannerOn
ee Repoesent Tin) 2 arrose & 1S By nae
| TEM SiG age)
2.
=» gnan+6 <3. n
c go
= ors $ 2 ce tmaitirn SaicbTes
‘si . gor on) NDB
%
Hence bv 023 ond M23 a Can anhe
tin) = O(n?)
oe sy byt ch ontadfen
G3 Reproent’ TCO). = Me 2+ 2 al oO
Fa res) £6 §O)
5
” 2
> Hers, SBF sess
9 fe ea
> adie £ 2B -
Hence. rev gbajeand 0077 Be
Scanned with CamScannerrr
we Cm Woite Tn) =
oly bh Here eet two
goth thet Ito) > ¢ Ja] for asf 1%
Pale Matera = BPs t) + Kopreset EF ir)
SLC 90) ), B= Ib and
positive ‘Coartants € 2M,
big omega retadion .
alo) Z e.g)
0, 3 a
2 gorrant) Zz a 55) pas ight growing Ferm
cS > we cannet chase 5
Cane) condi Her)
wil OF satishy .
2
> orl 7 0
Gabis bres fer an ODS
a
Hence Cond 400)
No
we can not Jake
“ + eng 0 zero bear
for’ ‘CigB 2 gad diate) ese een
wite Tln)= Line) , postive
By Tefal) Netaten (8)
we @an eseires | Cop 2 Olger)) , e on aaa ik
there exists 3 pessve Contant ¢,, Co # % Such Hat
®
e facra] < [rena] . 6 Jace
kur ol NZ.
Scanned with CamScannerExly
Repeerenl TC) = gerhn +r] bo Brg theta nak
eee) < 700) < @ 1am)
io
2? i ;
From the Big On and By Omega noted FO
epresentotfoo ewe have elneady opwerved thet
Here pee SL Bead ep Ot
toon OP? Gehs % Doe
} 0 &s ate
amen. sets
Hence poor Gee , 224 Lm:5 “oe
5.
fe
> Faom
Scanned witLehi Rane EE
Froom the above explanation: pRiealigg IH :
"Big Notion : BS ah acsh ot
fig Chega Notin ¢ Gives pest Care
big Theta Nations Gives Aver
Wok x 4
SEE ey
EY often g ok
(Tf
ree
ff at
ae
300nd eels, 2 Pome
pars. Meee ce oe Sa
2 Shoe oth aeted anti
Arete
{oR Cnitipvedted rated
oR Sel ap the agaitn
‘ad
4 4 4
asd eriinnaio es
56 RP Witaer ath x
rile ge el oI
he a q
‘se MERE oF tisha TA tien
GME tS 4 Ab ey
Cgitraen. at Sain
ors an sy) heMotivation
Lets eonider a problero to Stove the marks of a The
students tna class
cortt the 48} otutfow Comes Fo cur mind ts do we
ob students fot gio 7
@ we have #0 Gmsidey on am that fs Lovge
enough fo Stove ay Atuolent mones, (let 120)
Chenoa But here number
[el 1 |= ee | al z
sea
tb Claw Contoins 50 ae Harain, insole
Then the memory Locortions From the tnd:
urased ow Loved.
goz > IP we have prin é
of Students fx dhe clas then
Ger kon be Seived by onjocating exact ornount of
poe blocks . £0 Phere wh be 90 none
eles] === “le fol
ees ue 44
ud de pooblem with Sotmbion a fs IF eval
Student atlattee| fo the Clos, ther theme Tt
no extra Speue 40 Store HHS marks . And we
updote the Eirerermerme aioe cha bined of
dre time ob cmea4Ton) «
both Sal) ond Sond ne5od extra §
Er meres ove Jo be énserted
fon. wher Size cneve aces , ese
lex. 50 to 949 Fem
pormaften) about num bey
the. problem ob Ash
Moreover
Operations
Gpecibic post
and eelettion foe omer Complen «
Scanned with CamScannerol *
So brow" dhe above déetucsson &F fs cleoy that Awa
data SouctuTe hos Some disadvantages
° Momo Locs
+ Fixed Size
4 Bosertion | Deletions Oe lttricult «
Hence we Neeol to meproent Our alata ee ine
dibterent data GrouchVee to overcome fhese problems,
thar és Leoted Uh:
Ln Linxed List meprvsentotion: doth loda value are
Ghore] Eo, Separate, memory blocks ( moy “ot Be Continusus’
Z
amd each memary bloc, tS Lonel to nent memory lecK!
these eporare. memeny 1 lOc’ one Cane Neocles -
Open eePeeP
the noes ‘eo dee Linwed Vis ere anocated
olynamfcod!4 when every required , Lo tf Sbives
{st and andl pootlem + Ager qe 3% problem
eon beg Ol nop. be there gn Lineal URE ab
ens) omd deletions «Con be olene by crest
Some fixed number oF Lee -
Leper y ds
Scanned with CamScannerLtoed Ltst
A Linked List ts a Linear Cotlection a Ao objets
Called. ode, where each node has two parts coho
oma Link. The €nbo part contains cata value ond
Link, port contains ‘the weberence ab next rede «
the node at
Nie! QOVO. .
A linned List fs 0 Coniectton’ of thES type Slr nedes,
stot
ee) {ood 01 300 %
Lope OF
node ture, Linx, port of Ash ni
mekorence ov 2nd nod Linx par pst and Node
prseeo..ong fo 0° Link port 6b Joat
nal tnditoring end or the Jiaxed> Web -
Contains Aiady re: value «
contoins oborence ae Ast
Shoat
le 2000 |
pode eAroins
Gnko port coh every node
Neder oF the Linked JT ont cungcated’ algnam’ col ta
a Go the nodes roy foe Quocateol tr
non. Comboiows me Locoffons . The torr
Zs odlocoted 60 VIALK ATED «
ae
Scanned with CamScannerStor
iz fine
Representation, ob =Node
A node tn #inxed tid has 2 “ports Zoo amd Aron,
and beth ore oF L enpahagtyemee ee part can be
oe ong type olepending on the obta value we wont to fore.
he bake pont esa weherenct of another oode+ 60
node tom be rseprented using a C]axs «
o
class Node
2
ent tok»
Node Link .
is
if we, ereate 9? objet Ob Nede Chous then th Cory
Tepresent node tn. the tinned List-
thot 78%
Node p= pew Node (),
RPS cwvahe ohjeu”
ar 1]
Scanned with CamScannerae
x
® toa
Ao Ts]
Shows Steps por “Basen )
~F|
E]
®
. a
a
zi
PY
(Fave OO
»
void create € >
© stot = oull ;
Node p = new Node C),
Sgetoms ceubs println( "Paper rece fro’),
pegnko = sce nertlc),
prlinx = null;
étarb> Py; M
System + owe printlo( De fem wont Mave nodes"),
7
Ent ch > d¢eneet¥C),
while Cth }=0)
L
Nedle q,= new Medel).
System outs prmila( "Thpu ade frbo"),
gq: tnbo = Se+ nent). i
g Unk autl
pr link = a.
Ee ch " : ”
Gystem » oust porntlo (De you wont more nodle( 0) ioe
Che &¢r net IC), ia
Scanned with CamScannerLean
co foot
s
pisplog +
etouy
o byrai Pel @ Ler Hfad
stot
0 Perper) o
ercation » Loe eshooto] Stout fore
null -
aionk
/
© Leslee]
Pact
hour Pooverse Ops
p. becomes
Figures Oto ®
yst ode and tonminate
ode! vord «= AlisployC)
a
poe cuute prion ("Skat = "+ G0).
when
Syite
Nede p= stort »
while( pl) e null)
f Stem, cut »parorlo( Pe fole +" "+ Pelion)
a reve, a
5 Ler
g ‘advance the
are” to next node .,
we need 40 Uplate 2 Counfery.
@ aisplog method + only
Seme
code Serer! a
A
int (C20;
Node pz stat ;
while CP 1204)
i CnLe
poplin, tle) = O09)
3
rpetutn CC; .
3
~ Scanned with
canned with CamScannerSeorrch
eorcth $s alooa Some Kind of draversong operation: —
whan exact match bound we Ghoulof forminate + IF 00 ene
match bund bor al odes then alto algo, feinates «
Code!) ent» Seomeh (Ent eve)
Lae Pos 20 »
Node po stort »
. while CP 1 ul)
post »
th p:éoko => ele)
‘refurn. Pes >
aeturn -l +
/
“Le algeosthm Con ‘be updated neg on “mequsrred,
Ib we need aeberence ob the aequsred Nede then We
Ghoug aetvrn P-
ee
Lnsestion openetions
ee —————————
O Drsert at Begerrng’!
> when» we Sek Slot = Ps “the \prwies Linx, Ave
> Result abter Ensewtfor +
cs polyol}
a SP
Scanned with CamScannercolt! vot ens Boge >
Novle p= new Node ()-
System outs peioty ("Input node obo"),
Pr Soko = oe+ nentlatc), Re
Pr Gores oul;
t6C dark = null) Time Complentty-
Glark =p 9
RSL
i
prbows Short»
@elovt= Pp.
@OAnseat_at_End
mt Qn Brest Shep we have
font - B
oto Lerpe ie oe ok Lastnod
a 40 |x ne ti a oF
white (Lak J =
of ya o-UmK: 4
© 1: Uon= P;
code! void 8 fod C)
Pe, p= 1 NodeC). :
tystem out-pointin(” Toput zobo"),
7
pe tink = null;
cb (slont == uit)
oS
font = Ps
else th we agnere the Gost
i ede Y= stort + ob Search eperation Hes
while unk pout): [ress OCD]
ye a PK 5 emafent Hime,
qtok= Ps
e -
Scanned with CamScanner@ Dsest af any Lveatians (Wede no, given’) et is te nodea)
4 O Find (toe -1 IS node ep?ing,
Ly Be [Ta] @® pe Uaks qn
perozuceg Greg O Yilians Pp,
bo 0b Noeles =
: ce4 &
Code? void tnsLoc( )
i
Cystem-cut< pomila(Doput node 90, ekene pinsot’),
Ent doe = seenertDot ey. 4
ent c= Count):
| tk loc K= cr!)
P(t 221)
ZnsBogl).
else ab ( tocz2 C+1)
tnsEnd C)-
ese
Node pemeo Nedet),
Lysterm-cutepontlo( "Snput foka"),
Petobo > Se -nexthter, 4
Pe binx = pull »
| Node qg= Start ;
Ikwe égoose He tnt cnb=|
| inher See a while Cont & loc-1)
| ‘pe
OP ne
} pilin qe linx.
| plik = Pp.
fre:
“peltft operation
a
pelete brIOm Beginning
1 es
wort
2 ohpe! seb p to potet 10 tet
fs me
pares inode. #2 Stout
hep! Set stot point to and nude
stout
Cf ig wet stort Link,
yo fal [ao [ple] pep. Seb | P: AK = Noll
P (to moe tt bree beemarg
Link, fo Hak, it whl! he
availabe for garbaye.
Lode conection .
ote
» Void delbeg ( )
a aes
tb( stow == nuit)
syste gedeprintto(!
ett ¢
voderHlow 2 "
7
3
Rae Sia [rem = 0(4)]
parece Us;
p: UinK= null
3
Delete ror) End
“Ta: soe =o ae
Spf igo b) node.
4? £ @ set q Uke null.
oie Linked, yist — Contains 4 node then olelBeg. cheuid
be weol +o delere we only noel? «
Scanned with CamScannerCode!
void ofelEnd C )
z
tb Start =- null)
i ‘
System « out painito( Loolerblons” )
roeter » 4
5
th (start Link == null) ff 16 (need
é. hay L node.
del Begé >;
3
LIke
Node qe start,.
toot
j 7 bi - cs
ge ae: while Cos tink Link | = pull) oe
ae wp oe
ye qin » al
; od
ge Link = null +
2 @ Find vet? eb
Eero gph] site ond
A Ets pooviow
@ ger pe Unk = ‘
try wes) then lel Beg (), ;
tk were hen lel Endl), 2
(here Cis fhe number oF odes)
Scanned wita . ~s
colt! org dolor)
z:
Ib ( Start 25 null’)
4 " ”
Syston oul poioslo( unofertjora 2
Tetum »
: ”
System cub pont (" Dopot rede 0, to oblete }
Ent doe, =. 6c mentlnte).
fat c= countl), UY Counts nb. ob, nodes ,
tk( boc (<= .¢ )
i
te( loc ==!)
delBegl).
a
else tbC Lot == ce)
delEnd C)
else
is
Node Y= null, P= stort »
int cate), opus We?
white Cent < bed pind HE
ni onl &6
o ent tt » noel ond,
a yeh; mys prer
¥ Fo 4 pep: Unk » node -
at 8 yy) ; oi
re | q Un = pe Lins a
4 pum enue; if
§
g
Scanned with CamScanner——.
Rorerse
code
void reverse l )
zs +
tk C counti) >= 2)
i
Node ps null »
Nodt Y= stort;
Node = Storts Link »
q- Link = null ;
) while (* d= null )
i Zz
cok PzY,
. ao) qe;
\ woo unk :
q links P.
Stovl = Ys
Sot
code? Noid Sort )
Node 7 J +
bor( t= ‘stort ; Zolink Jenul » Fede i
bor ( j= start,» Jling | 2 0uil » iejoume )
a i ee (Ue tnko > J Unk. énbo )
é ent temp z je enko »
(gobo = f+ Vox: énboy
Jetinks fako = temp r
3 i
Si
Scanned with CamScannerCereutoy Linked List
ne ofreutoy Linced IRE Is simslor fo Gingle Linked isk
that Link port ob doit node Ccontamg
with ene dibrevence ,
mweyorence Ob the dst node that is. Hort -
Stowt oe
[0 20min acy \ SE. see
op lar lel elS
upolected -
Class Noole
i got enbo,
Node Lok,
operation Ove alo
Sry he.
create )
void
£
stort = Oully
Node p= ree Node).
System. cube printing” '‘Doput node éoto').
prenlo = gee nexiDore H).
stort =P,
pelink = “stort,
+ System: out printio(” Do pet oont more Nudes Cb)"),
tnt che f+ netSatl), 4
white eh $20)
i
Node y= 09 Node ().
pear aa n
Spend ede Foto"),
abirte).
pr unk = Te
Page Oo
pe link= stort »
eyctem + out + printin ("Degas waar mare nodes (1/0) ")
che ge nedlel 0, 4
Scanned with CamScannerDisplay
Void disploy ()
Z
Node pz Start » :
System aut» poinilo ( Start =
oo
.
og eee) .
Ce, ; Uae
System. ceet-paront ( en ae i »: t
p= pelink,
i f= »
: D while (P! ster)
{fp we use a while
without aroversing ony Dede +
Jp witty Same Conddition , 1eP bins
Search +
tnt seoach (tot ele )
int poste,
Node p= stort ;
do
a
pe piUnk; :
7 wet et=sor).
aotuco —) »
Scanned witJos Beg
void énsBeg( )
z Node P=new Node ( y
System, out prinfln(Loput node tobo ) ,
prénko = Se nentIntc).
ib( stort => null)
stark = P+
pelions stort »
3
eIse
a
Node g = Start +
while VINK |= Start)
a q Link, °
5 T(r) = 04)
pe biok= stove ;
starvb = Py
gq: Unk = Stovt
3
Scanned with CamScannerby
void tnsEod()
i
Node p= new Nodec),
System» outs pointe (oper ede tok"),
prénbo = st nertintcy. <
start
cb RE= nude )
a
4
Start = P
pelinn_= stort
3
£1se
Node 4= Stort »
write (9 Link sean 1 = stort )
i g = yb,
pode -2-getotc = \7t0)
qt Unk = Fare
Pp: unk = sharh »
00)
3
oimplorly GA! other opewations Cn be: pertowmed —
ara Ts aort operation ore
' ;
os On sgoment ‘Decble Linked List
—_—_——
Go a double oxed List every node has 2. parts:
prev: Contains oeb? of previous node,
tnbo $ Contains node value,
Lox; Contains eb) of next node.
Panble Linted List maintains 10 List croberences; Shark 2 End),
Ast node prev & Loat nore LINK ‘Contains Null «
stare me
Pee pes = aaa
(ea aa t
pepo P PUK
next ond preniowsy Bode Tee? ore
J et the
ys p és fhe mob? of Cusvent node
given node» 1k ;
pelink end Previcus node
then nent node woh tS
ab) ts ps Pev’
ian
we tan Praverse prom — bonverd and heexword clirrection.
ee
Node Ropresentalio)
class Node
Node prev;
tnt énto;
Node Link
J
—_
Scanned with CamScanner