DS Unit 1
DS Unit 1
Date 5Sept a
UNIT-L
dATA TRUCTURES
DS
roblemn
SolutionS CAlgorithm
roqram
Efficient"
imihye
Non- iminye deniveda om pimitve )
Page No.
Date Page No.
Date
DS
Analuses a Algorithm
Non- Pimitive DS
Bimiive
ime Space
Chahacteh line.ax Nan- lineaa Comblexits- Comblexi
LFloat nteqer
CHirarcha) DS) imeomhlexitu=ltanaluse the time takenbu olgo
t o eneu te iHs task
Liti Tree Garaph Space Comblexi t analuse he spaae taken bu ann
alaorithm exclo de it
Arrau kinked list Stack Queue DS
aini Comblexitu
ALGORITHM:
Time Comble xity- iSpace Complexiy
His awe)l- defined Combutotionalprocedure
thai
akesr omeor het oinputitand produce one or
Aetso Joutput no. okinbuts3 no.o noo mo
inSmuchons inbutsS
Cn)
instruchone
An it also satifies theollowingpropexties
Asymotic
nput O atn Natations-
Outbut20
Finitemess Nheu are unctong hat are Sed to analyse
Deiniteness the behaviou o an algorithm
eciveness
Q Bia oh 1ithe ob
B i q omeaa 1ittle omeaa
O Theta
Page No.
Date
PageNo.
Date
mlt uill un
dan timesSo i belouo o n read as
Print (Hello )
Can be_ LutlHen
cbositiue
Constants
atheir exist) Gome the Constant C
Qnd no- (such that) na no a no O-
t wil un n
times or s
Pint( Hello), loob then again 3 dn 3n
n imes or Sec tna
Loop So On)
mmm) mn ntn Cn
dn m
OCn)
c3 n +n 3n
A
V
Page No.
Date
Page No.
Date
Su- n r n &(n2)
nin
n10On c n owt Pp21 }aANEE bound L e bo un d
Ppet
2 C-
5 + 10
n n+n n2-
Aet n-
C 155 Qu-2 n2) ind ac
Sn 10n 5
lo reachclosest Value
ne 10 Lueknou m - an n
5n* 10n Sn
For toLAbound,
(3 Notaion- (Aeraqe boun d ) Lowe
Cn n
C g(n)
0t n= 0-
n) Cnoi catis tied
At n6
3n n An
D
Page No.
Date Page No.
Dato
dosen t ne ed auxi
tmeis more and we
inta lsl
int a fs 214,210 ini.af2121 12 4
K a 1 al al2) a3] aC4? Cin dex no)
2000
Kous maoT Order
oo o0 4 d006 008 (addresses)
eha a Ls1
a Lol aC al2] a[33 alu1
o2000 0ol dooa do03 a0o Coumn maoYAYder
|Page No.
Date
Page No.
Date
N Ue-le * no oColumDs
Arrau
Lwe have aiven Al2.1, 381 BA= 3000 and
2 Ug 8 widh L bute nd i loc la3irul-
locCa [ulrs)
So
Ma a - 1 2-2+1 (noa Here 2 U, 7
N : De- le +1 9-3+1 no ol columns BA-3 000
AdvantnqeA=- LCoe-
Drawbackg
TOH3
ToH
C To ToaC2|3)
H.23 ToH 1,
TH (0, ) oH
To (,3 2 p) oHCo23
Stop Stop
Sop
top
To,13, ToH3,13)
Stop
Stp Srop
q
paint " Entex the value o memoyMu Qllecated then ît retung vold-
seanf Z d &b= p AShte be ainter
=p nt2
7 9 memoYu S Yot allocafed ben YefutnS
INULL
int Zd"b
inth lint * malloc (n eize of lin 1 aehuns_Void tube address o r s t block allocakd
hu e 0S,obexahing Byslem
NDLL
the uequested memoruar not allocatRd h e n
Dxint N InGuf Hcient memnors
rennsNULL alue
ehun lo);
3 ee) de-qlocathan
else
Void lne þånteu
Suntax ee (pointer)
be atoTd
int p z (int mallog Size o at)
mallc bu delali slpie btatements
qaubaae
eeCptr
Page No.
Page No
Date
Date
untax realloc pointer neuasize- ForLwad and hack uasd MONemnent in a combutez
it
Ayskem imhlemenled bu linked lisi En-media-
int 7hh= (nt ) malloc ( n s e blauer
Atakemet
tunction in C- MOidCreate
1 head= N u )
printf( iet is emPhy
Hous to creale a singlu inR.ed lst 2
printE e t ig mot embtu
head
data n dad ne
Create O ncHon
Psevdo code NL nen
nead G equol
veid create (int n) iSt iG emp
heiS nat emb
3 0heHLoise
Dtrut node tem
(Stuct ngde ma lo e sizea Aruci nod
Page No.
Date Page No.
Date
heNuMhes
u rie aunctionh count Write abrngram in C t ereate N node and aSa
Yode preent in a singly liaked list_ he ODImaion of each Node.
int o 0-
while temb 4 nent e NOLD- int data
Auct nodenext
head
Lemb ztemb9 next vaid oreate (Int n)
uono 3
Page No.
-
Date PageNo.
Date
reate (n)j 1)
Drintist printf C faund ");
else
Void printlist( ) DxinT Not kound ";
AA last node
iretnodo lastnDde
p nexd s temb
D nent eNULL
head pei
heod Dnents4nent
1 R 3
Page No.
Date Page No.
Date
ppnext
anent Circwlax Snaly Linked List
NULL) intexnal node
Head
pnent :0 nex
reela
else lastnode
in_a cireula nked iet we can directlu MOVE
he CPQ
aAt Stont
DrOGesS om
bAt end
memoruspaCe_ eAt internal
rauwbacks-i E reauired eyMra
o eut nodle
ore Qddress
2 We Can move
onls n onedirecon
(aInsenhnon o no.de at Atast
circulax singu linked ist void stast (int insext element)/ insent-at stant
Hou) to reate a
stuct nodetemp
Void Create int n)
temb Atuct node)mallac (sizea (Shuct nade
temb2mext-NULLS
Bruct node h temb -
node temb data a insext element
b (shuct ndde ) mallo.c Aizeof Lshuct
Enter the data ") temb nent head
pint shrct node
head temb
Scant( 4d 8p data);
p net : NULL; Dnext : temb
lot data
head =p -
nead Shruct node next
while (n 1)- 7000 headlast
inser_at dast
D next - head_
shuct node * temb
emp stract node *) mallo.c (Aize.ok (stuet node
write o nction to inset node in a ciraula orintfEnter data of ne node
inRed list Scanf(d temb datal;
temb nexi N0L
Page No
Page No.
Data
Date
n doubly ink st uwe move in both orwara a Insertion în Dnubly linked list
and backoand dixechon.
head
head 000 30 00
lous
2000
oo
000
prev
temP
neT m
next
PageNo.
Date Page No.
Date
OA
At stant insert at start Transvere inreverse
Smvet node p - at
malloc (izeof Lstuct
Srucf node *em
p=Lstuet node femp head
prof CEnex data o newnd ratta2E Y- last NULL;
Scanf("7d" &p> data); p 2 prev NUL
while temp NULL
next = NU11
pnext head
last tempprev
headpeyp temb temp next
head =p
last last next
temp last
A last: insert-at labt O while temp = AULL
^next
nent =b;
pprev4
nt DLL in reverse order
Page No.
Date
Page No.
Date
o DLL
nsert in behueen (internal) Noid delL-astart)
head
3 o00
Sruc node *p
3o phead
head-bead nexti
head prey NULL
new node
ree p)
Void insert.at-mid (int key)
At lant
Shuct node a node s head
=(shuct node *) malloc(sizeo (sheuct O00
print("Enter data o node);
ScanfZd" 2h data);-
b prev NULL Vo d del-ak_last
next- NULL
4 =head Sruct Node * last lemb-
while (qdata=keu) last head
Rmb - head
= next ohile temb NULL
Date
Page No.
Date
Gint keu
Vaid delat mid Cabes
SMuct_node prevnade netnode
Cobes
h cdeg rext h2
pdeadeg4deg)
pf cot
5 L733 4ON
h2
i p - nezt ls NOLL && 4 next NUlL
ptr2next p