0% found this document useful (0 votes)
17 views

DSA notes (1)

Uploaded by

kalpanaapj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

DSA notes (1)

Uploaded by

kalpanaapj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

23)a12y Data Shuctuje ond

|Agoritim Areastes oF 8 humbers.o Dor


Declare the ariabte ond usck
Step i qet ie 3 integer input Frorm
the Uder. Ca,b, c).

Step 2: Usig
Using f Statemenf; check tf as b
and asc. Tf tie tondiion ü
(ree Ren 'a' & greakoat.
greatesh

Step 3: T and
b>a and b>c m
means,
b ü greatest . Ofheiuise çgreatesk.
Step 4! Pint the 1eateg t number,

Swappig 2 ros oifout Usiny


Algorthm for a20
VOriable.
temp b 30

Step I: Declare tie varable (a,b) and


fom tRe user.
Jet lie nut
b
Step ! perorm a = at

Step 8: Pes rrm b a-b

Step 24! Rer form a a-b

Step s : Print a and b


Facby ial
Priram:Aevatve.
Procedurei Fact ( n) tosg ok

for ct=;i <sn, ++)


co ifactie factiit

end.
Recursive fnction
toid nain
begin -fact (n)
end
int rec - fact Cn)
begin
teCn-c)

yetge

re turn (nyec-fact Cn-tb)


end D

Fbonacci Series:
Tteyakve.
Procedure Frbonacei (h)
begin 8
aYr [n3; 2 3

Rcie 2; i<sn;lt4)

rn,o icn;it+)
Print arrCiJ
End
Rec ursive Funcion,

void main t)
begin t/w

perfmonce

-’ Spaoe (omple ciy


imecomplexby
Space :
" Voríables
variable Tt can be

ioOutpuomponen
"Thput
code.conbtant

Finding Space compiexi er the below pgram


iot Sum Carr, n)

Cnt s=0
6rli O, i<n; it4)
S st arr CiJ;
8eturn s;
3
Vorjables
n, s, i, arrCnI
t6e aboue Cocle Aives nt Space

and another appoach Same


Prgam
gives
2h43 mear
'n+3 space Pgram
wiu be faken,
Time complexi:
’ compile Hme
Run Hme

int Sum (aT, n)

int Szo, i; >ount =1)


In oun
S st aYr CiJ:Dx Count
ren S: count s) aldoiroy
count foi cheking false condrtdn,
Statement Total Steps.
Frequeny
1

n+n 2

3n +4

te
AddiHon 2 marices:
VOid main )
m=2, n2)

add Cm CHY;

int add Cint a [a3T J, int a2[2JEJ,m, n, hdd [aJcJ )

ddd CrJiJ lacig4a CiJ Cj3):


3 retunr
3
kekeen addcIejI;

Matrix Addihon:
void mat add (int mCJC27, Tni m2[J23. tow, coli)

int i Tes owIColJ;


2*0
6r (i 0, i<ow; it+)
>t(2howteot)
Br (í20,j <cot; J+4)

Steps eTime compleaiy).st


’ 1 + 2'0w +14 2:0wco| +, w.col
Averge -OC) ’Theta
Case
case Best -2c)
:tcat cae alorSt >0C)
-
ie tots. mp
Asy
’8n3t
Steps:
Sum; burn Te
numaYC1J;
h Sumt Sum=
2h+1 itt) i<n, liz0; fr
>i0-3)o s0; sum , int
n)Gelip
o, (num.arr add int
Pngnam
compexiy elemenb
Firding
time
. AFterMesUTemernk
- iPerformance
Before perßrmance )
3ol9l2y
printf("Aerage
2m
+î); per (*_sum+
D2scanf
,arYCiJ); %f C"
0.)ret ,it,? i<:n izo, (int or
CnI; arm fpat
ad "ydsn); ScanfC
tnt
-74.5 a.3r6 JCsarr ()main id o
<stdiv.
hs #fncude
Valuea Point tloating
pointers.
find pogram
bo C
c aWhte n
uerge Andsun
and
PoINTERs:
dagn) otn.
o(h)
(logn o
categoikea 0C1)
algoiina the
tie of MOSt
tfese Undey fall wil
Shuctures:
Shuct Shudent
int no,
char hame C30]

chat

Creating object strucure:


struct shdent:rrg s

S. name ...

creating anay oyject shuture:


&ruct Student BtuL4sI;

Exa mple:
8bruct Stuclent sfuCuI;
int i;
for (ie 0; i<4s, itt )
Scanf("d c c "eSta CiJ.no,
AtADS. name, &stdCrgralt
Sbucture înside a Sbucture!
Struct Student f Sthuct addr d
int n0; chay dno C63;
chay nomeC303; chay Street Cto;
hor rade C33, char city Cicd;
Struct addy adr;
int pin 3;
6 e a m p l e .

and Re sdent's roll. ho


checking printhg
"coimbabre'
whose cby
for C+so, ik 45;it+)hda
coimba tore" ))
#(shemp (&hti3. ady, city.
pintt(tucrJ. rno);

Sruct Sbudent

int no;
Char name CtsJ;

char rade CaI; Loehyeis


Struct addr

char Street[to3;
har
pin;

When
vhs Ihe,memo'd wiu be created ony
Sbructure .
we reate the ohjech or
Poirtevs în structure! sSruct) Shdent sp = S):
Shuct Studtent S;>Siqle dyee
stnuct Student Std Cys];> Anay of oJecra
for Cint izo, iz4s;it+).it.)qm)
Si. gra de A')toist
oiable
dlructure pointer
Sptr +i ’rade;
ite a C
pnogram b maintain a Sbucent

data base and all he Sauden b who

hade 'A
b 'coimbaore'.
and Budent whol not
beiag'"y
Struct Shudent)

int no;
char name [ 20];
har grade C33;
(Stract Addr
char dho [s];
Char sheet CisJ:ersat rods
har ciy C2ol; i shrR
int pîn ;
I4r;)x char cibye3;,,
;
fnt ;
primf("Enter Student detaíls :";
Stuct Shuslent StuCy6J;

forci=0; iz5, it1)

Scanf ('%.d \h .3/n s n Ys"sh no,,stuCiJ.ham

Pritf"Grvade 'A' Shident) h i e


for (iso,ikys, it+)

if (scmp (sbuCt) grade, A))


printf (" dln'",shul3dino );
("Sudenl who ç not belonging to
coim ba tove " ).

if(strcmp (stuCi).eiy "coim batore) )


print (" /.l In'", suçiJ.o ;

26)

ACx) 23245
+5

Strucl term
-6
int Coeffent;
ezpon ent
téiable4
term
Shuct potyromdal ACws,
Shuc term B Cio3;
int t, t2, t ;
2 Poynormi tompieu

Procecdure Adpoy
Sbruel term pagnomia)
int n, n
BaRRY>int tao,.9, k=o;
while (2en e e em)
Tf(ACiJ, exp = SCj3. ero )
c[kI. esco ACrJ,ee;
Co eff;
cCK3. coeff - AC. coeff +BC
ooelae ie ACiJ. exp 8c[1.exp )
C[k3. exp : A13:xp;ih
CCkI. coeff ACi3. toeff;

tbe BC) =2 4 32G


cCk]. exp BC 3. exp :
cCkJ.coefP : BCJ. coe ff ;

End while.
While (
Ck]- Coept AciJ. Coefp

=it, k k+)
end
White Ciemn )

cCKJcoeff- BCJ.Co efp

t, k -k1;
end,
Assi
Develep
matPd
s]1oSparse matrix:

arix A atrie B

col

8 3

Sparse a v : Representaton
birolal slisl4
arix A sVALI5,5, s7
|o, o, 4]
Row 2]

Co| 2 2 3 |Co, 3, 1]
3
alue. 2
L
a o o l C , 3. 3
marix B.

Row
Lo. 2, J
2 3
Cot Co, 3, 3]
3
2 lc', 2, 2]
Malue
Poceclure ado'Hon (Suet SMQt AT I, BCIe
Sructadd

înt 0w

int val;

3huct add Cto3;


Shuct adlol cCI;
br (Tnt g- 0, ie ; it+ )rhaeoob

Assignment
Add'ion
Sparsenah

Inoertio n:
S = "HelloAlor ld len 10

Sava
Inser ton ’ (Si, s1, s)
DP HelloJavator|d

patfern natching:

patfern nartchig s (s's, )

0+incudé
Vojd maint) f 3 4 6n8i
Char si J= Hellolelod,
char soC): "aa";
int en : Arlen(si)+ Shlen(s2):
char 3 [leny;
fat fndex = S;
element ht
tDa)
element; S[yeorS
biol Main
C)
element Srear=
eor- Yeort +
sCrea; etement ttRont
ese -) font= rf( etse
n-) if(reaY
==
element) (s, d
CS) remave
Front
Rueue: pobie"
(octy)*Z
-a expresbioo daion
cf
rehurn. and cau functon o
Staclk. Application
of
s) Popl elayo
etement) (s, push
)D5uty) 3Empy Boolean
ste
s)Tsfull( Boolean
síze) moe. (3, Stack reate
Dperatna
5 -Stacks: lo/24/ 22)
ADT Queue:
'ot Of element.
Oljeck Ordered

kunchona:
CYeate OueueC , max. size)
Boolean asfull ( max. 8ize )
Boplean

Add (Q, #em)


Aemet Remoue ( Q).
Tmplementation:
main ()

int mar.íZe lo,


Shuchere Queue
fnt ifem[ma.síz];
int font;
int ye0T;

que. front = -);

int n, >element

Vofd Addolque, n)

if Cque, Year < max. bize)


que. ftem CH4Year] n,
else

priot f (" Quene fau);


Remove Q(9ue )

i (font - Tear )
prtnt ("Queue Empy:

rehurn Cque. hem[9+font J ) e


cclor uee
Fvauaion of exprebibn
(5) (a) C3) (9)

5 t6 4
Stack n4 op -1

push(ite m)
iFCbop = n - )
> postfz

ee
abcd/ t bop--1
’ atlbo(c /4)) S[upJ Herm

Pp CAem)
ifCtop=-1)
Ao itemy to oaplat
Stack a
emp
or Cint i= 0 ,ikeop ;i++) ese
printf('l, sliJ);
postfrx evaluaton:

express fon abe * d / y d o c i


532 * 4/t

Step 1:

’564 + >293))
SBep 2!

(416)
5 -o-6
Step 3:

’S.6 >(o-64s)
6

Muliple statks E Queues

You might also like