Professional Documents
Culture Documents
TheRinngve aPaogham
tkpends eng
Bhe input dhe
2. Jhe quality o coole grnated y the compilo
used to oLate th shject. poam .
T(n) cn
n’ Snput siae:
C Constont
1. use FIBONACcI
Tn) =,3n+en
let no0=5,3hen ue can
shou thot
Th) Big Sh
T) n.
3000
1Ö00
l0,,5 a0a5
n
s/a/23
Suppose T(n) and T,n) ae the tuming: timus
We can wtit
Bubble Set
ijtemp : întege
O)
2 2
(n-) 2. n
2
n-)ut nln-)-
me
uk,i tiiuunning' Total
iketp intme ule, oduct bySe
).
ime oci) takes (G) te (3)
b the testingstatement ithe For
Çn biconci
endj
end, ()
end; (8)
.end: (1)
temp A=;I:= (6)
(5)
ALj-J temp:= (4)
(3)
de.:=hdoion-to
4
Veuy Jast Gouing hancin
A;) =
ALi, 1) = A(i-l, 2) \or iz 2
Auj) = A(-, A(, j-1)) tor ij z2
Aag) 2. 34
44 8 1G
2. 4 16
Ass.
Ackesomai Junction A Wsite a
non-tecuweive
yunction en
this(1ol&23)
Snvense Acketonarns Funetion
Slos ghouing yuncior
and ogln 0
A]s|23
Gensal Rde to cAnalye a Bogtom
I. Jhe suunning dine oc aach assigriment,
and utite atatements can wiually de take
Tón) = O)
q/&] 23
Babie ta 8tuctwes
Btock
LIFO
A
FoA a gien stack S
en
Amathematical wrpsesston
1-[{x* (e)/ (G-)f t /e-+3)
Ensuke:
I. Jhee ae an agual
atanthesis
Evehy ight pakontheik Jhas a matehing
Juht panthisia.
Valiol = tuue;
S= the empty atack ;
uhile ( not uad antiu sting)
uad dhe nct symbol (syb) e strng.
pdh s, syoib
volid -false
else f
i- popls) ;
valid - }alses
valid = talaej
ih Cvalid) s t ("Valid");
dlye putnt ("Anialio"):
Tmslenmentation & a Stack
# dalone STACKSIZE lo0
sut stack
nt top
jnt itoms[stA dkSIZE];
empty (rs)
stut so ck * s;
sutisen (Jsuue);
se
sulsn (false);
3
empty (Gs)
popls)
stuct stack * ps
}(emty (ps) )
baint | Stack empt, ")
ocit ()
ps-»top = ps top-;
3 sutwoi (po-tonotap +l))
Uhe: x = pop (4s)
pushlps
sttuct stack *ps;
, (ps’top == STACKs|ZE-))
oitu);
3
alse
A+B ’ Snhix
t AB’
AB+ ’ Postex
AB*C- Dt E/F | (G+H)
tapsymb = poplopstk);
add tosymb
l9ort
9-ot
mamoy
de seuse nst does method obeve The
-. te Aet is. eat Shitialy,
L9-hont
tt tems -q,.
c) (9. insect
[MAXQUEUE: tems it
queue stsuuot
kteat MAXQUEUE
l0O
kfront B
FIFo
A
Queues
<sl23
suct quul *i
pi 'qyua wndertao")
aiti);
== MAXQUEUE-)
ort -0;
Font tt;
Ünsent (pvÐ, x)
steuct quQue xP,; int j
sle
it U);
alinn,
3
Linkad List
stuuct rode
int into;
stuct node xvoct;
hanode (f)
NoDEPTR EP;
6/s/2s
Assume dhat p is a psiite vaniable thet pointy
a dist (i any) and to
to the yost node oef empty
NÚL ncase &
2quall NpL. dist. Sou have
ia a funchon [ SrsdhH O7. that. ins erte a
node wtth' an the ino ield ath he
ngde povtecd do by
tnsaltase (p. x)
NopEPTR ;
int c;
NOpE PTR
5l== NULL )
Juint,(Woid ingstion");
geiredat);
4>nt= þ n t
nct =
NoDEPTR 4
Note,: Can stoe
9 not;
pnot 4¬nvot;
puanode Ca).
Queues al tista
ta-ont =p;
(b4 a4)’net -P
3
tijiont
heenode (y);
(Pg- kont == NULL) puat =NULL;
3 etan(c
17/s|23
Some list oeatia
Let list' toint to oa gotud ist and is on
slemot to be insested wte gpeh poiion
List
HIHIO-H
Soted ist
place (list, )
NoDEPTR xpltsti
NODEPTR , i
9-NULL;
llp= *plist : pl=NuL 84 >pines
i, (4=-NULL)
pushl*Aist,
ale
x):
nsalin (, );
3
(wuLL) Hetisn
hetunn);
P)
NODEPTR
jntx, ustj DEPTR No
(list,
) Satch NoDEPTR
ist the ein nimbet letseasach knction
do Weta
to
t) -NULL nt (4-*plist, n
-p; *plist
"NULL) (*plit=
NOL', neete
getnodel); -
.y) NODEPTR
*}list; NODEPTR
(list,
x) Srsend
ist the
o
ndthe at Iumbes seed in nction Osiate
Wnit a huncitn to Jemove all ecouhencog
Humover (lst e)
NoDEpTR list; int j
NoDEPTR q
unt y:
4-NOLL; = * pist ;
hile (o!= NULL)
zonot,
l9,-= NUL)f
ynode bplist),
*pist <Pi
3
ahe
dialtin (9,4y);
P
Ciuculos dist Sast
node
nodlo
þnoct st node
ongty lpstack)
NODEPTR *pstack
utusn| (stock == NU) ?TRUE: FALsE)
3
push (pstack,, x)
NO DEFTR *pstack; int j
NODEPTR ;
þgetnode C);
due
4nit pstack)-noct;
*pstack)- nest -p;
NoDEPTR *pstack;
int , NCDEPTR -Þ;
t Cempty (pstack) ==TRUE
phinty statk wndslous"
cxit);
P= (*pstack)’ not,;
P inyo.
E} lp== * pstack )
*pstack = NULj
olee
pstackj-anet - nt,
Banode ();
setusen (c) ;
3
HW : Splomnt queue wsÊng cin cuda dinked lit
(empy, insett, emone)
1
sttuct node
int ünto
stt nocde *at, xight;
dpecla stuet nocle noDEPTR;
ote a sasutine that deletes the node ipointee to
usy p in a dousy inked dist and atoeu ta
connt in ec.
.
nect
lyrnooe bp);
ese ih ley== NULL)
ueanoda p);
pHayrit nt,
3 Heanodelp):
Wsite a nction to anseut a noole with x to
insa,tt (p, x)
NoDE PIR P, int xc;
NoDEPTR 9,4j
9getnoce );
Hetun,
-3242197849l62.
324
G7694 |
Seasch
Jist Dejth
Bstoudes (c) Grsds (Besndee
B) : (A)
TrnsuLiang
Jhue. Einasay Iaysing
a
2aveL Contoins
compue n
awinodey nunbek
of Total o). Lul
hgdes atmat
Qm containl levelld,
it hodes
af m
at
dea ony drel Maximur Dpth-
tue
binasy Complete binay Sbidly
Jevel2
child at
d`ild
suight
Root
chleen. dioo
Je Binauy
inum max havea can node Each -
TREES
a4/*/23
A Beg dos -
..|. Visit the oot
stack.
itav (tue)
NODEPTR t e
stsuct stoack ?
do
whielpl- NUL)
pushls);
3
ethav ltce)
NODEPTR te:
stuct stack S
while (p!=NULL)
push lp,s),;
t-psaiht ;
aatiovac (te)
NODEPT RJee;
Ltue =NULL )
etasn;
tn-thseadad
Binay he
Betheaadlol
Pest-thecacd
binesu tiee
NODEPTR , )
de
9,= NULL;
while (pl= NULL)
f-yight,
p=fosigt;
whilels! NULL);
3\]8|23
Binasay Seach Juee
J4
20
(6
NODEPTR J;
- getnocle();
Pin7e =x;
dat = NULL;
ight =NULL;
stid:TRUE ;
tutnl);
setleht bp,e)
NoDEPTR ;int ,
(p==NULL |lp-let|=NULL)
i} pintf(Vaid insetisn);
wcit);
3
NODEPTR q,= makete (e);
setsight (p, «)
NoDEPTRD; int )
4l!pdtoad )
tkintf ("Voidl insenton);
NODEPTR ,
e9, <maketu(x):
thuod =FALSE;
GeneclIee
Abe is a tinit non-emst set o aomt in
uhich en elemnt k called theut and the
duaining eemeit ae tatitioned into mzo
diyoint seta, cach a which itselk a taee.
Begus a a nodle - No. e childen that node.
An sdesud te is dlined ak ate in which
sot.
the subtes de tom an hdeed
ah no oe
The linst child & ahode in an hdeuedcidtae is
dten callad dhe ddst hild. Jha Jost e
callad the goungest
A\oest
-yungest
olelest ’
J-yungut
ololest
O alolest
Fsest
Ti
An ohdeed t eis called an hchac.
+dafine MAXCH|LD 50
stuct unooe
eit i);
3
.hild=l'st
addlchild(b
NODEPTRp; int x;
NoDEPT R, 9;
}(==NULL)
acit u)
9= pchild;
NULLj
uwhie la, !=NULL)te
4. =9nont;
4-getnocdel );
'q, net -NULL;
}lNULL)
pchild=4j
elhe
net
a Gensal Jhe
Paedes : I. Fust visit uthe noSt eh the jst
ttee in a joest. ubtees
a.Then taesue dthe oest oh
the jiust tue nkesadea.
3. Then tuavee the olst the
B
D
Tngile:
tees not on inoceo
a. Visit the aoot oh the hit ee
3. Thn dFayesge dhe
subtees un inado.:
Convested
achod
to a
Busdo: ABCDE FGTK H
E A
(H
Ealuodion tunction: he no: seus, columns
and diagpral bamaining pen Joen one laye miny
the numbe seamaining then ore i ponant.
3-, 3-%
=
Best
value
gthe
/Moves
cee
8l4<a3
Set
Operotians
1. MakeNull (s) 7. Union (A, B, c)
seMembels, c) C= AUB
8. Sntssection (A,B,c)
3. Snsent (8, x)
4. Dalet (s,) 4. Dilfoena (A,B,C)
5. Min (s) =A-B
6. Max (S)
Btt Vacte Smplementotisn
int s[ioo;
Make Null (s)
Be (i-lj i< MAXSIZE; t+)
sL]= FALSEJ
3
Jnsest (s, x) Qelot Cs, )
s[]=TRUE; sl-FASE;
AsMembes4 S )
hatsn s];
Union (A, B, C)
Sntesaection (A, B, )
o4 li=0) i<MAXS IZE ; +)
Dil (A, B, c)
en li=0; iKMAXSIZE; it+)
# deline MAXSIZE I00
typedl studt set
nt dast:
slost-j
3else
Ansert (s, x)
S>lasttt; chek lo
AsMembe s,«)
int 4, s, mi }eund;
jund=l;
se
Serting.
Bubble set
Bubble (a,n)
int al1:ivt nj
flali+j< alj)
S:seted =0;
int tmpa;+J,
otj] temP
i (stcl)
bsak;
3
Seluction St
Rash dun sod
selectienthase in which the
Contists ol a aament
phgten postbion
5, 2, 12, 100, &0, 75
5, 2, I2, 0, 75, 100
5, 2, 12, 75, %0, |003x
R, 5, 2, 15, 80, 100
Selechion (x,n)
tnt cL1,n;
imx=eL;];
Bwap (*[ndl],n-i-l);
3
1s]|23
Soding
Exchange Divide &"s.
Rule set
O7) Olnbgn)
Guick Set
Q1,8,1,1,5\(00) >4,1|