0% found this document useful (0 votes)
39 views20 pages

DAA Unit 1 Hand Written

The document discusses algorithms including their definition, characteristics, types, design approaches, techniques and complexity analysis. Key aspects covered include problem solving steps, sorting algorithms like insertion and bubble sort, and complexity measures like time and space complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views20 pages

DAA Unit 1 Hand Written

The document discusses algorithms including their definition, characteristics, types, design approaches, techniques and complexity analysis. Key aspects covered include problem solving steps, sorting algorithms like insertion and bubble sort, and complexity measures like time and space complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

ALGORIHM: Set of opevations to solue problerng.

Peafox ing Calulation, data proc eing.


pxoblem

algovithm
Input omput a Output
YTime i less mem0Yy f mgye 6 uise Vesa

Chasac.testis ohalqoitho
unique name
Set of inputs apd Output.
lalel-ehléycdwi th unambíqouous opevation
Finite amount ef time
End at somepoint

Alqorithrm Proqram-
finite Need not to be nite
AJatural onguage Sei 04 staktmenty
Lnot natua lonquaqe)..
QLlyte the alqoithm ax addition o tuo numbox
Sttp 1 Stavt the proqYom
Step 2:Declare 3 vovables int, A, B £C
Step 3 dtB=L
Step 4. Stop the pioqyam:
tUNDAMENTALS OF ALGOR1 HM

Undeys tand the Pvoblem

Decide on Compulational meansThink obou


logic D34
Exact ys appxoirmatesolutign.aefan tcohnigue
Data r u cluxes Alqovithm
oleJignechniq ue

Design an_alqoithom
Yov e CoYyectner

Analuze the algovithm


ode the alqoithm

Qrite the alqovithm among 3 numbels


Stcp Staut the pxoqvam
Sttp 2: TDeclave 3 saaiable,ie A,8 £c
iep 3 Use the conditionif elte
tCp 4 Print the numbe ohích is gyeateg
t 5: Stop
3kep the pvoqyam
TMpORTANCE OF ALGORItHM
Need do ycccqnize limitations o yaious
alqovithm _of soluinq a problem.
e e d to undestand the yelolionthip bla
pYoblemSip G Aupning Aime
When isa Aunnin proqvam not qod enough.
Necd to leavn houw to enalyte am
algoví thm.
Yunning lime. without (oding t
Mecd 4o leayn tcchniques fov waitinq moye
efficient Code
Necdto fo ecogni bottlenecki in Code as
LOellouLahich parts e o d e aye casiest to optimie

COMPulaTLDALALPRoBLEMS

Sov tina
Seasching
Shoxtcst path in graph.

STEP Foo leniNGaAN ALG0RITH

Step 1 ldentifying umbt


ftp2iooment
3iYoiable names
SHep
Step 4 Assiqnment stattoent
Sttp
Step 5 laput and Output
Step Contolstatements.

DATABAE ARCHITECTORE
application client
applicalion ekent

application wev
database system Seuadàtabase Susttm}
9-1ey 3-1ie
ALGORITHM DesieGN PPRoACHES

Based on the achitectuve.


(TDA)
lop down appoach
Bottom dp appvoa ch (BVA)

into Small probh


TDA laxge problem is divicleel
TDA
eyease o f
BUA Also knouan ai
Solued pxoqyamming language
winq a
this is Lombined into A Complete pyoon
then
ALGDRITHM VEs1GN ECHNIQUES

But fovce conguea


2. Divide -and-Conq.uc & decrease
3. Gveedu alqoythms
Dynamic Ravarnming-
S.Backtackin methocs
6 Brach - and bound

BRUTE FORCE
l 0 Solue a pxoblem based on the problm
statement and definitions of the toncepk
inuolved
Dsed to colue the small Sze instances o
problem
t Computing a
omput[ng
Sele.ciion Coyt , Bubble Sovt.
Sequential scavch.

JDiWIDE AND CONQUER


Step 1 Splft the giuen insiancc. of pvoblen înto
Seveyal Smaller sub-inttancct.
tep Independenlly Solue _each of the
Sub-ins iance.
lep
lcp 3Combine thc ub-inctance Solutions.
ALGORITHM
3 GeEcos
Talke what you qet houo.
A t each Step the choicemuit be locallu
bptimalL
minimal Spinning tyee.
Stoxtcst digtance in 'qvaph.
Greedu alqovithm fov 1he knopsack_ pyoblem.
The coin exthange,
Used to solue the optimizalion pvo.blem
Optimization pxoblem is we ae giuen a
Set of ínput values, ohich ayei xequived eithey
to be maxi mized oy mini mized i.c., Some
Lonstyaints ov Condition.
£g Huff-man tyec foy optinma encoding

DNAMIC PRoGRAMM|NG:
Bottom -up dpproch.
Eind the solution to Subproblem Ond
Stoxe them in memOYL for latta.! ue
a l e solue all possible. somall pxoblemc¢
then Combin them to oblain Solutfon fov bigy
pYoblems
by itcvation
Lq Fibo nacci Dumbeys Computed
lalayshall's alqovithm implemenicd by
ilCyations.
5J BACKT RACkING MEHOD
Dsedfox statc -space Search problemn
Repesen ioautfon
Initial state
ú0alsiate
statu.
1A set of intexmediate
tzans40xm
yA set of opeyations that
one Staie tu anothey
+Acost function
utilityunction.
Salution is obtained by seayching the
tyeefound
DFSproblemn
Ma pxoblemi.
6 BRAN CH AND BoUND
uedohen we evaluate each node
uing
using the Cost and utilty
Bated prioity
On
funtiion.
qu cut
buildbuild in a Byeadth-fircd manne

fg 8-puzzle problem
N queens prO blem
CORRECTAESS Of AnoR1HI
Tvacing the oulput o cach possible
inpui solve problern Pi
The olqoithmto
CoYYect1Ond only iffoy all problem
fnstance i e l , i icyminate ond producedss
COYYectOutput0eD i e L,0) ER
PL1, 0, R) I-Input
0-Output
R-Relation blw T60
CORRECINESS DE ALGOR11H PRoDF
Lounia losíableCourntey Example -Incvect
proa
Induction Dixeet pyoof
Loop In vasiant
INSERTIO SORT
Adage4he qiven elemcnt acssending ovder
Compayision bated algoxithm.
Used foY Smalleyalqorithm.
TuOD Typeu D lit
Povtially ovdered 1 t
WtcetYEA An UnsDyded list
22 3 45
d- 22
54
element onfdeved adyi
m Step : fi S
ally So1dc

emp4

Dri

empLo

1062

so 2
SL
S
4 S6 O2
tmp-2
LO2 2 6
3 4

LO 328
tehrp 7

Aemp +
Lfi lo<3

u 73

4 3
23111

) <2
X11 3 2
23 41o 3 unote
Sovd
[Y) 103,3 4 8101
LOLL
31
L 2 3 4 7 83 1o
31
Inserion SoYt
Begt Cae 0xde ol n-0(n)
Ilovi Caue- rde on-D n
in
fov i , i+ t);
Aemp a :
i-1
while > ab 6&aL33>Lemp)

a C+0 aC];

aLj+ icmps

LxarOple AcmpEI0

91:1

bUBBLE SORT based


Salau to insutíon Soy4, Compayibo
olgoithm
tach paîy is Compaved oi th
eleneoh
each they Ond they Ond Swapp.edi4 hot ina
ade
lime Cempexity
Best ca se - 0 )
toY Case - 0(n2)

5
S
I5
1S 8

fas
8 S

5 1S 16

L 6

SPACE CoMP LEXITy


anmount of memoy Space ued
Total
byanalqovithmincluding Spaceal input
valuefox eeulion.
S p ) :C+ SCI)

Constarnt Tapt
ME COMPLEK[Ty
The m e Complexiy of an
alqorthm
esen the amouni o fime_Yeg,u
ied by
Yepy
the alqoríthm o yun o comple tioa
TLn C An

no bf Step

Cime Hakn lox additíon o 2Bitu.


Tuoo methodd O Cound metho d (1abe metho
oY izo i)i+t) n+

hello) h

TComp
ND ieq COuntv O
C
C

n+Ctnl
2n+C
TC oln)

ALgorithm Sum A, n)

S0
fox izbin +A) nt
SS+ALiI

Yetun S

NO.
COUptyal
C
nt
C
Cy
C tnc, +CatnC3, +(y
an t3
OCn)
f1
Sum b
while Ci<an)

Sum-Sum+

Count.\NaL

Cu-

C+tnC3 +( t nly.tDC
30+3 OCn)

OY bJKh _jt+) n(t)


printt hello '
NO. OF foeo ount VaRi
nt C
n(n) Cr
hyn
hCt thC, +ntna3
n + 9 n +) oln

syiP614 dic DTATIDN

klogn
klog <0 < n<nlvgh nKn
k2"3"---KnD:

Lowel
0 biqoh eppes bound DWOMt (aJe
bg Dmiqe Gobd&ound Bes cae
Avq in tee
L t e -ph notatfon (D) LLtle bmco notos
CoUNT VARIABIEMTHOD

it Alqbvith Suo(a,n
S 0-0
oyi Lton do
S aCiJ;

&int Sum int AC), intA)


fo(int izo iku;i+t)_>n+
SStAC1 n

ttun >1L

n+3 0(n)

ASMPTOTIC AnAyL wh Duld oe analyiis


To kno Valuey
Bet caAe oOYSt Case
XTheoryof appr0imatýon
Specify the behaviOuy ofalgovithm Loha
Ahe input si0

unningq time losoc he best tal


analyi
Running0
Cunaysis
LIme hihe 4he LooYt caje
BiGOh NuieJwN O)
A unclion iln) f safd to be în
4Un) eOtgtn)), 14 tln)
O Cqun),
bounded
denoled 0s
aboue by Some Conttan multiple
the ye
gn) OY all laxge n i.e., 1 SOme
constant e and
eitSome po&Ttive

no
intcqe th +had
hon-neqative
t n ) á Ca tn) Joy a l l n 2 n o
Bigge-oh pats oeSymptotC upp
boundon O unctiorn C- integuvalus
q in)<cg (n)
Le
5 5 e na2

2 BiG -OrgEGA No1oT1ON 9 )


Ca Cn)
1 epyesenH h e 1 o O e bou d of the
resouNCe cauYed fo Solue

3 THETA NorARON 0)
n>n0.
c29n)<ttn) s clgn) for a -

9 gon)= olg(ni) 0 l g tn))


4Cn ant3
en+3 S doentt
n s 9n+3 SD n2 mort

'Tyu
uTTLE O No11ON Lo)
wedHo dts cvî be. the uooY 4 Caye

tn) Cqn)
im n)
gn)
TLE-ONIEC NOTA1ON (w)

The unctfon ln)=wlgCniy i4


m fn) Ad lim n)
n . n Cn

RECURRENCE RELATLONs:MopEL LRRM)


RecusNedCallinq the fundtíon calling aqain £again
T w 'use mathematícal 'enteph to caleut
the time Lomplexity o an alghithm. is called
etuehCe Aalation modeL*
Denoted by Tin)
Typu 0 Bauc section
Recsive Sectíon
oid f1blint b
i nz0) D> Base secdD
2 Recuas ive section
Co:uk<n
fn-)
EgFgbonesi S y
aRecuvwence Relationi. Methods
3Iype
j Substitultíon Method.
3Reculsfon TYee
3 Mastethcovem metho
Substifulion Fovunvd. Subs1itution
Backwatd Subsfitution

to) Tn-)tn 1lo) 0


T)= TD) t|
TU
TE)-TO+2
FoTdaxd Subsiitution Jt uues înitialtndition
ha
n ext
i o\hcînitial Ham and valu& oY
Hea i s 4tneLcatta

Stcp I Guts lh Solution


Stcp Vie the maihematial Inductfon to ind
h e kounolaay tondition and shou h e

Backwasd Sibstitutioni In hi backuoaxcl valut are,


Substituted sutuiuely
TLn): T (h-1) +n TO) E0
na TL:T(o)t1 TU:\0
D Ta) T ) + a T2) =3
TU)T(2)+3 TC)=6 3
he4TIu)T3)+9=) TU=L0
Tn): otnt|
2
D(n
Backwaxd Substitulion.
Tin-i):D-2)+(n-) Replace _all n by (0-)
Tn-2) Tn-3)4 (h-)
T(n 3) 1(n-4)t (n 3) (heK)
Th-k)t In-ki) +lh-k+2)
Tn)0t1t2+3t tn
Tn) ntnt) 2 n
2

Tin)-T-U+L n ~o
T(h-Tnt-Ut
fdwaud
TO)
TU): To) +1= 2
TL)TO+13

T(3): Ta)t=4

Tin)= 0t1

Tn):T(n-1) + Backad
Tn-D» Tn-2) +|_
Tn-2) Tn-3)t aSsu
Tln-3)Th-t)H
n=
n-lcO

TR T(n - t K>
h-n)+n
=)oh)_
=)L
/

TLD)1|) +h_ To)


ind upto n tIme4 T(o

1 17AY
2(2) +2
I3)2TI+3
2 Tuy+1/4))+3 2(gH) +3
3 4 8t3 = l | _

You might also like