i=:
r
Samiti vi
. ne ide al)
wm o, J? amemory Layout .
of C progyam ”
sat isPrime Cink 4
for (int i= 25 i* 1410000; pine }
K
. if (n2-i +=0) \:.0(4)
Apis — rebyin 0) + 06s L
Raa i he ila
va L j Dab aia i
‘Asvays and Absbradd Dake Type C07). | Aevays: Coniguows. blocks
oo Maing Te only Soe on wage in_nenovy.
+ ADT: wlays oF clagsifyi oe ing a. minimal expuled
inturface & some sot | gp poclen th 3
y wrt! Funrhonably _
Operafiond i “as
>
Minimal funcional: » ge elenunt cb ith postion
2) set, num). aD on
yy)
a 2 ) a Sr
Weald 5 ib pverwettes |
+ 2D Stabic Arrays size con't be changed Araditional onnay
q i 2 Sf Gh i
tax) add (avr) =
— om + gtk)
set Ci, num)* Operations on Ayvays
D TWaversal: Visitin ng every element of an ovvoy wee.
) )-Tasertions An element can be ingorted in OrrOY. at & specie)
— position .
{ “31 Deletion : fl element: at: specified can ho deleted creating a voi}
which can be Filled by shifting. all elemedds Lo the eft x Pe
is IMP. Tf aver is nok IMP thon when “— the lui ;
Pere.
Stil be tae dure order is imp. then shift all elemands 4 wright
e — Gae 2: TF odor ig NOT imp. then shift the element gf ek
ot index ob Vath onsitions ie saat. en - ier ;
the clement af specified index.
ee lame ss Seonrehin Je done | droversi ay whl the.
’ 9 eel toed bs iglied aa on 2
ar seu ie tg a al sy es
8 Song: rong lemons f array in specified onder.
——————
OPIN il eho ye
memory, lototions..
ng 4 pene In linked Tice, elamards av se
ot Satie Fban: apt memory locabors
le ir soe
yo
a
t
oT of ona eT Tn cane of Linked. Lick,
adding A removing élements without any cagacity exalts
phaikeof biked ish
rhumey'y. spate for ind for ony mode. plr is needed),
Gelade al aa remery
Traversal of ‘0 node = On) Tine Complexity
x Tnsortion in Loked Lists => diets
Head %: ;
i 5 BES ES SEES nt
4 bs r
1 inning: LE \=\ prsnext=head; head =phy,
CBee ue ary
enbire array bo tind ue node or
eelEdity 2 %
SAL
x Lintay 08 > Array, Linked list, Stock, Guene
Non-linear S=> Gemphy Harh table , Tree
“Algoritha & Peeude code ave 00h relevant: 40 any program,
Language. In ques. where yon ave to wie Zhese viride las, ,
Steps which can be implementa in any language. i
~ Operations =
)Inswtion —_ Ddeletion _ Sovting 4) Tnversal _5) Mersin
6) sexrrching J
€ Algovibhen Daign “Technique
)\, Divide pi! Conquer + Dissolve the problem inko sub-proh lems,
them A bhtn merge Hem —.
D Coredy :
etn
Diasert in Sebween: is 1-] we have bow specify index.
| eg At index 19 phr>next= a>nexd;
I a> next = ph, T.¢.2 Oa)
—Wamurt after. inert of ltr a nole whose prsition is
f alveady specibied-
I meee:
———== ——
nes —
qo declare an emply list jak. dos .
ad —> NULL ee te NULL
Pep ilpestas Nein an umply L LL s gut
it ull priser singly kinked lise
anther eprientadion)
Hend ar
Node Sa
THe Node iS SWE wed fo acus Me List
btu no tabi.
Tn oie oF emply Ll. vejuk do:
CEE make eR TaRet Punk to keel!
ote: Valet
2h in C ois only for Yink!
; ‘ler!
3 em i J ", -* “Data Structures — "i
Tada mm ev? é etfivenbly
= bused on raaurte ui
Viggiid costs ean cae
“oporabons. ‘on-dato sbructuva: a
1) Creabe the 0S.
N
lnakinn
ake Paint Hein: in 0s
2) Taerk trends... arcana Sli
— 3d Traverse
seg" ae SG S ciiiias so aa
Data + Ceroyp of items.
—_— bala item 3 nit) of a value.
| tem 4 single Cun a ;
| item
ie i. a = tan be vide inky e
ee he
se rm tg. Name way
eau. a ecco Telephone no
— nts 2
(onection of group items = Record a
ae ee File ation ering example)
xi 420.
ora veinaames alsovcon have tab a 4
m
ype struc tut { Cn) is the enbire shrucluve da whith
pS asinbeO Sasa -% points:
Be (Me), C2). is He varinble a! in toad struch
ah hal ee ‘
bl
(2). 0240, Amada
> A250; LiLiaeahits Pesci
X>p= &m,. : oo
Pps a
1 1 we it:
- ok: ink i= @NULL, chov_c=NULL —> Works! Gab deat we it
> Hue He'O" will meard Pre
nuilis wplaced by 0 “
ss ak ie fi indeqe sc M0: TL NO"
an int. NULleah
Bg ina memory /memoty
i ne Pst a at
te malloc ‘Cotsen - —
pape es cdaage tae
~malloced mumory i is lost ae “hort 15-00 no. way of. sein a
x “& Segmeodabion Fault — eee ee
_- Program accaasing an “illegal * mem. localn.
th euth peeeut ‘is punished by the OS by derminating it.
: ilers decd ih hie s8me_men,
fiolations. Use ea
ati
>This code should 609. fault. 5
ideally at c= 16, buck this
does not happen always.dngemate, i‘
(Jes
idelines to avoid Seq Faulks bili
-iniFalize pointers to NULL 4
= this won't avoid $@9-Faulls , but may lead do eortly detecions of a prblen
2) whi ING arrays, rnake sure dha array index is valid,
ever vebin adds of local variable of a function.
[Link] Lé& NORE comnpiley's warnings.
=Complets Fen warn abb- potential dangling ferences, ype conversions
~—-which-have.o. plaka Sov sy ful. i
i i i ideo) DSA lechue-@
f tts ; inphuk, computation
4. Frogyam has, 3 pas
lef — output si OS
[ E “nput: Brings dada fromm input!
mS ints mom ——
> at \ Output funds: Take dob ftom mend- men.
C* :
t 4 ae ae
fi) an File “Shand our data ox sayuesce of bytes.
»\
al
=
De Asan as _
. Za at gears + Computation haggent vhing ‘vonoble,!.
aah Sa “Diff 1/0 envisctnedts =) (eraphical,
wel
Semoved phy
After fee Cp)_=Tve flr‘p!&___._Nebwotk , Files. eb.
omaind same ae
; Re ther), 2 ebe. i
: ’ . 2
ing fox opan ©) Fut cal in-taskof-C.h ilyiey. peed <Rae |
“Aaymplebic Nolabons ae “
Ldn - ue vps Up we Bout. (ogi ha Pay
4 i ‘omega — ah lowe fut (bi
d big Weba > © shila
0 pb ypet wee
lll ve a nr da
t (rs gomaren a iat
paper
OM,
“wh ante “30 Ser
04 Bt eN KX es
Gq 6nt ees
Og 3nt2e3n K —
04 3nt2€ 4N
4 30)t2 £ 40)
ofse4
30)t2 & 4C2)ee,
ent 2 came, from adding time fo individual stepe on
a program.
qt 2-20 Cn) ont 4n +2001)
10-9 00) ___ 10+ An Ge)
ee
ge lone hare £ cor ‘a
cell 4=86fte= et,
e lontehnt2 ¢ U.N Pests 4 7124215.
eB >» OF 104299 Daz
nz 4 > Of PEI OX
LOS lomyunt2 £lnt .. S25
wz
(0) = 12.(g00)) where _¢ & Me ove positive contunts St. i
o£ c.g(m F(a)... NE Ne ip =e
eg: fi)= gnt2
ot ene
pei > 041€5
pet net) a ess
o£ fun) £ 19 (0) n> 4
—
meer . q cagter bound |
Nee ad a ea ey foeanree4n ne 2
02 0232 ..nzt |Ppeerteecsacmady
8 Fea) = (Gem). if £0)= O Gon). he Hind = LG Cny)
See A eg flo fon Sy
————) . Bnr2= O(n) ‘
8 Lecture 8
Twn sits of functions
ope, wad, write, Xscek, close, fent Rab etc.
it) Fopen, fread, Funte, fscank, Fprintt, Fell, Fyetpos, Fsetpos, Faieg
ee irs nes accels Ble wig open), ry u een wei of fy
ee Some thine far Spon(). ooo ws a as
—_ {Seer jor y fopon() categor
eae Ti eaac) wut “Hie®
ide byte-by-byte access to__i) ome Funes provide byle-by-\yie g
ile. orne record by-recotd accel.
ii we bode gl Wyle! i) onab mY_we'n saved trom ‘We!
FE Fes sates Fae Ch EE SPE
. due ate }, Fprink FL) a sig
: ~~ int float. obbur data dype conversions
NG fdy_void buf , a ae count); =
urn, no. oF bytes actually wad.
mainta ined by uresbbrary) 2 2D. acts
ou open dd, pre default pos is ab beginning of i le,
A write) perform work ot current typos.
i ill advance $pos by no- oF by#es they work ofvad() rekuens. 0 hen fpos ‘a beyond the laut byke in the file.
i h presentation Ae
beqers ave stomd in 2's complement
arwacters ove slowed in. mappings he ASCEL of UTF-2
oq: SQ! is 97 1-€. O1OQ00!
“publ. & Floals in LEE. notation.
|
eq: Th-we ve 7a plc dog td into
eed in
_ the_mem. of em omp
eee
|: 41:- 00000000 O00
Thon 000009000 _i
J We ger this ii
¢ /Biq Endian is ao
-byte
Convert from binary to+ Reading from a File
#include
int main ©)
FLUE "FP;
char ch;
th fp: Fopen Cdata bt", “y");
while (2) £
ch= Fgete Cp);
if Cch== EOF) 4 4
break;
while (a= fgckcde py) \_ \.
put char (A),
OR),
print C°/e" 5 ch);
sen
TE Felose (Fp);
% ehwn 0; a
{3 ioe
te
sl Tene Me tat Pt 005
chas ch (6); Et
——.fip=fepen dala we)
oe es +e ke pt
Spink Ep Sah de
FcloseCsp), a 4.include
ut main 4
BME SEP,
“chav chy
ye fopen (dala. dort, ‘ w')
dina hs
for (i20; Lel00 5. int). bb i
penis sed. “F \n" "iy sind);
sin gui 2
ane Aen eli ie a eer
ek ontpt ‘plat png; :
ree , E waith ling \'."), Bini ati
ac stance
whure 0, esr
Cavsiage Return. in. C Cr)
ale World! \w Ht) 3
we bsoipes l
alist
Sal tinadlhese ts
tieeg: print CHello World \n \r Hi");
Prints Helle World & then a newline An). Then dittor g
oF kame line Ciohich is We newline). Then Hi is wren | “hy
no overwriting eceurs a4 AEits a Rewline |
Owput > al World
Nok Gartiage Return may nok: “work in Online Compiles
due 4o limited console rendening behaviouy.
Ditty lihimrnsty sea! . os
* . Model in fopend ) oils
FILE “fopen Const dor enone, ante der rade
ee Male itn a GT
Read {| ) “v" => open for 3 for [Link] file must exist
yb" => open Fe-veading in binary mode. The file most exsh:
as Coa “un! > ye by. nig Creates a new File CE not exiding alvad
‘ brancated ne eT S st
s | existing one.
dbiek — > open for wriking in binary. made. Same behaviour of
art i 3) “or i pin. Be le dea isk ok wiles za h
“ab” —> Append in binary mode
wy yt 3 open fe bath reading . writing. Ble mut exists
rbe or “v+b"—> Read & unite in binary mode. —>—ti—
ey lexus File is not truncated . when we sovite, it open for rinding & writing. Creabe a new file or tem coted on
existing File be length 2000.
, “yb or wth" => Somme 05+", bub in ie mode
“py ta" 0p fir reading. & appending Cot end) Fle is ered :$
doein't exist.
Toe gor arb" —> Same oat", but in binary mone
fgehe Crate “stream
dj ; Eee Wie b ophy 4
OF on end-ot-file ov ovvor: Nie Ascii value ae
IAC enggoptiad. ae
chiara ADE rnnorten apie doers
+Fyets Coker ‘shy, int fy PRE Senile
- Reads a line upto ‘net chats frum the file stream inky the |
stops ak newline (includes in buFfer iF space is availabe) “ey
7 4
-& oppends a null temninabor Reburns sr on sucess. “Nyy fy
[ahen od of le occurs while no chars have been Wal, “2-er5, M
‘ picid aa ee R
Fpubs Ceontt char *sbry FILE “stam)
_weibes 0. null-terminaded string to. specified File stream Rady
| ReariVe AO. on success, EOF on errox Nl,
—t
q Fread Guid “pb y Sizet siney size-t unt , FLLE “steam
Reads “Yount! items each of size ‘size’ bytes fom te fle jn} y
| buffer pr. Relurns no. of items succesfully wad. 8
7
Furite Gonat vid “ptr, cam LL Gul same a Frat)
Writes —— = Fee
“he eee oe
!
Eieot CELE “iran Vacate Ml nd ah die’ Shee
checks F end of Fle hos been reached for given bream. Returns ny
if ENE 0 alerts tsa Mill eae 5 "ge
f fer ror CFILE *stram) 2 eee
a _ Checks iF an error occurred on the given strom. Geturng Nbn-zero ifn
; Levyoy hod occurred.
AY
9) Fseck CE ILE *sbream, long offset, int ovtgin.) _ :
| thoves tre File pointer toa specific lowa'n in a file Cor reading or wri)
of Fsek: Number of bytes to move the pointer.
_ovigin : Reference position like
| = SEEK- SET = begining of file... ave offset or O
I ~ SEEK— CUR cwvrent position... -ve ow +ve offset or 0
I — SEEK-END-—> end of file ss have to use sagative oF4p comple - .
5) sorting A a )
Ab: sir i =)
sont je “dna, cnt: char *formaby Sct
Read for formutted_ text fom a. file
vovma = Formal vorinblas do store the values
ote reeds a strig- until it hits:
act (ot SNe ot
i nok dene. Counc
ba ee ak dae Seat aia)
ana ye
ee
use o biffer ver lou)
x ee
a ala Tena,
[i ah tn the hen Ander is: a Bike ates
| pne_ov mirt_dimensions. uth 2
[fg Oo tat fie A dient
Loo) 5 Condy Cora), Clit Cut), aaa
Sor 2) ett.
Fund foal Ae eens iain Ren sige
be Gj list): hana he dentin hoe st ib
fe io. hems ave. walefined.
= eit) ce Ba ase ah le :
value iin a
= (i in index) lum on ovray wilh jw i
aa “bel ae A
End Array : : zzvtec LES I IO
a a
0) fre
Ph i agi ol Bg a Petes
ae | yeyles Rebs.
zeae itty = a
% ‘
4
iv) Jul one | - sate
| 2s ing Sy Ox2t 1x24 x2’ t 1x2”
4} bCh 0 [PaaS deals rab.
ae t= ge ea ae
feted ee ee rend
while Cy > 0) ch =.
if Cys 2 Fe -6) a
; ges
es prod aaa .
ieee pty ED hus bd cAoving all: x from 0 to an
_ oils cane bye it. stu nde
Jaode; ald Set AMferetial touche
. — Aye Lg = cing. Avail. pb. hich pb pinks to ook wed nena
Ceype of 6 Bt yin gan
lao
Daisy aah
Aes WHS Ayiy SS Is MEW] LL, eohich contains a
—— memory which is nok wie |
Bis aint hoa aed
—_ KAvailable List is aluays empty
ae oi; ig Tnuestion of a new node :
a Consider a Ailable Lich Avail =TLeihe obo
| Head= null flow when ue ardor wank to invert, end pik
eal Ash node of Available List- ee neo He
| arcde-potnlstr THO Avil Hhon pinks 40 be neXt?«Ned otha nade points ds NuLL.
TAC
We ge (vil
_ Heed}
ne tdeos ext « = NULL.
eo
then initialize
| in the bic Cook ens nod = nut
s: set Lemp—>nech = newnnde.
mpty then se1—_—
"
step 1:
Sip 2:
ee as
newntde—> next= ND
Name: Naik Ameya Vaibhav -
—_ | Division: 2 CBateh sb
fate: 20-09-2025
Linked List Assgnmat
UNOS No: 612405118
3) Tneertion inks the lisk pes
do wut; declaring an empby Ligh
Head => NULL
Sek-new- Create a newno
pL. Tuer
Tribinlise Head phy
Lu! node 4
‘
int data;
~ struct aade™ next ‘
ylama sidan atad
do with newnoderdata=6 2h
ib ind ist by doing Peed = reves
Hood —> Fee nites oi
az (reste. ae a oe in pith neyande-—vdala=t. &-newinede-rne- AND.
ark temp = end Ao Hemp> temp-vaest anil temp oe
Head —> eT3-> Ti) +> met
Step 4: Repent step 3 imines
Bead (> D> snl : |
a ai E |
3 wit hange newnode-» data= 4
=a
: Crate a newnhiae
i> ht
‘ ape step 3 with only hg sea ‘
Lo]
«heals >No > Btw
hep 6: ith newandeodabn=1* 10 =\0 (os
repeated Zed dine) Ce newnede-> next = NULL: Repent dep 3, wih Mt
d Gb Te E> bb ie net
> Elonwake: Ahunys we unk) test A then repeat! unless
you wank to do a do..-while operation
[Link] with aeunade—rdata= 1°00 100 Cou 2 is npended fa
im8). Now, we want ty insert this node after the node ankaining 1.
Head di do temp=temp-raext ulil Lemp-data = *.
— newnode-rnext = temp-rnext & bemp-ynext:= rewncde
> > ee Teh A nue
y peat Step & with these 2 changes =) d-nean
Jes data =\"1000= 1000 Cos 1 is repeated for 4 4 bime).
ar = tyotil. temp data= 100...
= UT sfno] > Wooo Tb > ETA Tal sel} 8 b> NL
io: 3 with oly cutge reunede—rdeln=B
Te Toa) eed Eee EP PD ue
2 Si ha hs 2
=H in
2 inhi > = Lempert
= [TT Tae Eh Ee
Ley Sa i |
- a v, “E, Le ce oc
sink _pritk prio print prime prinh sop
4 =«hep 4: Free temp
ee HEHEHE,
ae a
aa ei on
»- pelle He smal hunbee 200.
“ Repead algovitho sn ‘a! pat uit ony dhange “buat: Uni eripl
a
ead FT LEE, 1
ev Be
Oreo a
a
Step 1 Set +
Step 2: alata teh ——
‘Shop 3: Free temp.
Head ir a
GSS BLA iE EE Gr ni
‘es :
i aa
step ES Until kenp—viert= NULL wed
prev= bemp i aid
| _senp ep atck
ee estat aR
Step 4: Free temp ee :
ial ELe T-TEST SeH beginning ee
e=sdata= value ‘eeu 10 seb newnsde »data= vale
TN ala ie loeb tmpbead ar
S ——|B-tepeak step 4 while ae
= | temp -> nexk t= yun
; 4 F
i mn 5 net = newnede
= 6) $1 =>. ext = head
5 hil ) exit.
-> next }= head i
, p= hempyred :
cet newnede->nesk=head
é = newnode , temp—ynext =
if
|
Fivgk node felde Iu rode
) ejoal .
i ile
temp-onbet |= head Lemp-rned-) $- heed
set temp = emp-rne__3)_sek_ pix > temp
= temp=
= ead exexk 5 bebe
4 B b temps, next =
7 nak= NLL. 1) Free temp.
8 1) exit
+Doubly Li oked List
a 1 doubly. LL isempby =) Pwo Head = LL
edd bis,
nl Yates tsa Nese
i, aii 4
{wee : Pai
vent a
oll So
Nv %\60 uo <—“[ioog 65 BEE egal NULL ;
V0 Wo 1500 —-Vous aimerez peut-être aussi