Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

ata Struut wr

QI laite an algon'thm to ptanch ohether h giwn temA


gen elemant
peanch (oA) not d nd ime Compleni y
inea

SAaat

i-0 lag:0
Read

Reccl beouth

Reaod aucy
OA (o, <n i++)n

a i - =Seaseh)

brecuk

(g)
rint ound ")
lse
Pon rof found");|
Akop
Loltecting ganizing docta talled data ShructuAL

inean Afon - linean

Trees Pphs
Steck Tue inked List

Haaithinetic Analyis

m tuu0 actor
algosthrm basftally depe ncs

am0um+
oime equi're
The is lalled
Time lomplexl and eneut he Procpom

Lompile
APOLe Cbmpleailg9 omplety
time

Calltd
*h Pam
Dk pare oCt upied by
yThe amoun

iH Apate (emplezi
56 IKb, 6 Kb
En the olgoaihm,
talulate
hhehime lompleu
I n oden
a . s y m p ot i c otation.
neeol
ane
hee pe ayrpotie otation
Thene

OR) upex bound

Omegca eest lase (o4) Lout bound

3)Teta (ase

Bh-Ct Lonstamt C, no ruth *hat


e n): C gn) ! I a

n
vo lue o

C.g)

m e

Lw tin

mega such +hat


no
lonstamt
Jetn) ngn)) a
) ( 9 (n) vvalueß on

C19n))

ti

Theta Po
Auch th3l

tni)t a
tongtant Ci, (,
Glg
)2 h(n) C 9(n) va lu
C 9 (n)
fimt
Cgn)
nd : m tn

n 2 6n
m ctim
n:t) 6 6

n 2

Read
3 Sum = O
Co)2 C9()
o r -1 , i n, 144 n1hC: 6 .(n)
um
6 C J) n
Sprit Sum Henu inu Lonpux O ln)

8hop
1 Dengn Om
aloyoni thm t
id ih anpleri ty
dimensmal mahix
Sum element tn tuo

i) Bubble Sont
n ineau Seueh
C g)

) S+aat

Reodn, AumO
Reod ouay (n)
or (1:o 7kn +) (n+

o j4n,j++) )

ptam ( 7d 7.3", a l , a olj);


a li
um: Am a nn

Prit Zduny

AhOP
Bubble Sort

SHant

n )
+n+3n n
Reacd , , i,
3Read 0AD n) n+6n +3
kOA (i:o, ?u:n-t i+a)

0jcnisl jj+) 3n+ t 3n +6 n+


Caljs a C ) )
n

aCalj0; n

i 0 ; ic n-i, 9 )
n

pint4(7a, alji0); n
ineoc
infol So1t

il, lag
Reced n

Reud Rarek

S. Riad olay
n+

o(i: fen) n
( se

breo

7print ound

prin no+ ound

AP
Aorting
Tuo tpes
TnreAnal orting
hel 0Nt
henp A0n
meuge Aont

B u t k e t bttt
unsention aM cn all 4he elevn emR
in ht 13 cosd 9a
Meg h (aidt

elemtnt Qlenent
(ompaAR hirs
nf eded, dhemufe
t ate

ppi needrd

ompar 4ird tiemevnt *h Attd Prs nd +htn

uithts lememt amc nmstut -hat elemtvut


a pproprak pou
ennue he Samme rotesS n ule
elemtnH
el Hd ade
plorm msution otlomingr
+ 5 92? 3 6

1 2 36

6
S

8 3 6 4

6 4

S
6

73 6

76
2 3 S 73

2 3 S

3 S

6 89

Thsentiom Sant

inttude 4 Stdio. h>


main ()

int

prin ent n)"


Aton t ( "1d", en);
int 3, ', , temp
a

print + (" n i t aMay elemen");

( .&", a);
ptan

i j-
mp: a Ljl
while Ci>= o empe alyV
2
Tnoenuam SontAlaole

ali ewp

print *e soNtd elemev a t );

en Ci: 0, 1 n, i+#)

pvit4( ) 24°, a [3);

The time
tomplenit k imsetinq 0Atinq best ta

rug Casa: 0 (n")

on)
Shell Sont

Lnshell soA e kind Hhe


9P wheha
9P: n2 and
hen irs+ ele meunt ith
P element.
TKen Coun Lompat geP
elemeuR

T une Compase s ele ment uith


th
6 elevneut

s than element
abo
thn Lomtinue
n D12 hen 6
9P
which àl P
agaun ind the
P T 4P
Nepe a t AOme Pro cessS ele vnemt

Compohec

betome ihi
again id Hhe
3°P/2 hn P
P P
peoAm Jmaeltion
1 3 2
I4 22 12 29

09 49
3 2 6
122 2 S )4

I22
2

L 2 2 S

61 5

9P: 3
12a
2 2 6 4 u 2

2 122 to9 2 6

09122 6 149/2S

6 lo 22 1 12 149 25 2

1 61 09
23

12 2 61
12S 149
34 6 (2

ShellShell Sont_Ceda
inttude <sidio. h>

Vocl mcin ()

int gop, i j , k , t ,

pyin enie n);

int a ]
print+("ene thu numbeis");

oa i:0?en) itt)

Aant( d', 9aliJ];

oACj:gp :jan, ji*)


oA( i- k> o E:
t-q6p

break

Qise

t [k J;
o
[r) o
[«4g°P]
C q J : *;
7
1
Pvint(" d elenmtnH a n");

prin+f( 7.1d", a ();

he Hme
templexi ly e L best coe O
amd im
(ople lo Dhst go caM
O(n):

wket Sont
BucRe Sont i s aAorting algonithm -Hhat dfuides he
ptueal houpf talled
UnJOA Rd
ANay elemenH
bucker

The bueket
3e vauies hom o o
9
hen Pla le hou
In numbe 3
Rrst
an
in hrcd plau. Lonsiders it vnit plate
based o unil
Unil

Aim laly plaue Hhe immlas

Neac lare
bucketuu'se
ele nent in
cul he
he neu P eotlec
numb
tens
ten plate
by +aking
Repea h Aame

mauke

it om est
es
amd
n d pla u
plau
elemen
onhltht cll
Repeat +he me protess

AOA ed GAde
321S
qu3 , 138, us6, o l ,
u s b u , 2%61,
S G
321S
3
H564
C4 32
661
3
2
38
oll/

S64, 456
311S, ai28, 7u 3 9 , 6 6 / ,
I

S 6
66
qu39 yS6y

2138

213, 3AS Gu3, us 6u, u s , +66


I

66 u
2133 3 S

Ot 239, 3215, us64, ust9, +661, ? us7

22u
uck Sort
GucK &0At uses he Shraegy taited divide
divide omd (orq uelt

when ekA s pa9 le Jne unsion


e use

ied a p i u o t element
TK k lenent

The Rest efemeut nitially uit amd Jas j


etemet
Ps nd he
e moue
om ett to uight eue

qAraka hom pivot Onht Hhen muemin


moue ughs he elemtnt
hom Jepe t ind
ham pivot oni he de hement
uth Aituaticnt Ae may antse
tondit'oms
m wap. oliJ : al
1 +hen
wap al, Pivot
Cal
Ca neuiely qutk AoU nctiom
ub olue Je
md ight Aub anhay
NoLe he
element he
h e lel de o pivot iu a lwa
eSSham
pivot amd elemenK in he
iqht bide
pivot o
olwo
0 eaeham pvot

33 66 8 SS

33 66 83

21 33
66

37 2 1

q 66 88 SS
PL
66
SS
66
J
66

66

33

2 33
11 2 33 SS 66 9

Muge Soxt

MeMge A0At uses Arcihegy divide amd


Cong u e u

*Puendhe mid whe mid owth


Cgain
gain n) A diuided nto +uo hal re n
Ke
in both Jt d n
ub aMaY CUnd
xiqht b auay
epeat +he
abo ve pepi noni
Cm
a
binqle
inge element
element

+his
meHging he elemen
nH nlu whi ch Omg
elemum
Again tom bine o)»
and)
and
n element which oms
mau eltmênt memt which
u in kd
bon
ohdlA
(A

N
1 /
7615

3 l1 6
2 3 6 8 9

tintludls stdio.hs
tmouin )

nt heap Lo), no,, ), c, hoot,


prin (" \n énH no temP
o elemens");
tam("r Eno tu
nos")
O Ci 0 ien , ++)
Atam f" 1d", htap
liJ
o Cil; i<noi ++)
C

A9Ot (-1)
herp [ool hsop Ce7)
dop hecp Caoo),
htapt);
hap Faoot]
heapt) t

while C! o)

e Ci:ns-I jè0j-
emp heap [o3
heapCo heap lji
heap ) tmp

do

0 0+
heap tlt heap t ) e
<j-i)

taj)
tnp heap [aoot J;
htsp aeotJ: eo
heap le) temp
plo;
Prin+" AONHd aMy is ")
Ai:0 en o it)
pintl" 3d", hep ))
Jetu o

Tme Lomplev9

lm}2) +
( ) +n O

n)+(»/u) + +nlu)+"/
t(nlu) 4 2n -
nn

4n«) +un
+(n) (nl,:)+ +n*i
n
iog. =deg
r n : i )4(n): nlo2n

(n-1) \n-2|+ (n -3) -O


J
P
(n-(n-+i)

C-) 2

o(n

You might also like