0% found this document useful (0 votes)
21 views24 pages

Unit 1 and 2

Uploaded by

Priyanshu Panda
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)
21 views24 pages

Unit 1 and 2

Uploaded by

Priyanshu Panda
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/ 24

leaaar regd

BASICS aF ALGOfI1HM
whAt s an agoithm ?
"A e deg y woell defined netuctions that can be woed to
ting algo sowe a computatiomal poblm
St povaes tep lby ttep poeduve to conwent input into deaied
outpuz
. witen waing impe glish langunge |puendo code to make tt
to wndistand.
ALG ORITHM PRoGRAM
eig phae -’ mplemntation phase.
Brnain Knauwtedge veqd
Any angu iowchant, et
Can cotain
> btep by slep, abetact thambiguud ,
o
age r many algoin it
Trtig pefonkod.

ules to' obfain


cxputcd etput
Snput trm the given
input:
Agonthn
NEED FR ALG0

hutmate ocesses, male them more Teliable,quick >easy


to puform
Jo perfom tasks voing compuer that cannot b handled
Ved in maths, Cmp lui, tng, hinance, ett. nanally
3o optimite pocems, naye dala, make predietions A
pronde elutios to problems.
Time " " 5bae
ntal Sput 0)
:
tandittbns.
wdmtand
Sep eaay toAeterminitie;
Jhould
damegve eperationy
9
Sheuldnt
have Muat
CAaesfutenes: freyo
Muot

is wie
hope Hetivenes : - uitonpret
termi operatr A
Wke
vepresentatim
yeu
lo
Canaet tatemnt gonernte base
IRIS
C7
nali
a wndmtand that have by muat
fuctinn meeesany
it ater humendhould atleaat
output I TCANA
ingini aCHPT
ranig
leping output can a |eomp
iffut what be t be I
lipat, limuted
loops
for ep
unambigubus
ig ALGO
ths
cubput, dhouhepre to
4mplty brokn
r goren a r no.
eans. m haced. reeurve 4
--) Ltalemlni n nput teps
don
func imgbarypreaie
thaough pagramner vey in
inlo al
tne. witheut ast os. 2
ago small ersy

" " ’(IME toputput " "Cnaidrthu


ANALYS)S
SPAE ANALYSIS
StTIME ’SPALE)
memmony
muchHw
tpae No 3 is
tmt
fven Rgo Selve
St’|ep 3tep
PoWER NETwIRK
shauls to
ranables
veyd 2
naidered anaalye probum the
b ocunig
tauafer
duta tme ya
-tune ù
ConSUMPTIDN epeetc
by CoNSUMPTIO N
ae constaint prob
b
algo waed fast dyo? tn lo
that given
when be
toane eah tim
ceue - cenotrainto Lolred
Spaee acounted at prob
Aeant aimpe fiüent.
praion)(ey oytha
- yCsuld Cemputirin
he
to
aepend 3
power
3uered
=
tatemnent be ago
fhd constant an
max
sn Lanaumed
impooramtir clary
in by
Conyfant fln) 3 put conaumes analyaig
|supuat
o
kgo "
subput hedtted
tetn s,
(i-0;
fr agon'thn P
tum
im,etVaiabe
Loops, mpt(Censtaut
Iput,
calculation.
aingnge Roe
htpldnt ANACS
PRORI
conditiona on
(h, budput,
ikn Cmpaiy
patt Chu time algo
)
it)- ; ly mith tpaee (time,
exeeuted eruutey
sps, 4paLu
terative i it
Cost
twith needo
spae)
ntt tmes, n omce
fn " "
(fixed this. iinputi, Real
pasible
ontput Kattyomehbyas pmtaisonafl TERIORPos
poheChen

A
Spaee temp rdeperds
raniasleinplenentatiam
[dypendo Vasabl
tnpt
e tno
degnee n an, pent aftr
n

instane
chon) dynami cmeebe, depondnt TESTING
PreOutputar, nput
memony)(aateh
site kar,
malle
tiny
aty rue
IRL. pcuseson
- Propertiey THE NOTATION
OMEGA BIG
b
is MAthematieal
Coneise byd tim)bnclos
'nuning
bound eieeuhm Represent
TA ejined
lower
6aund HatementBelined
netu - spaeProntes analysis
ommauly
Auymmpott
0
te hymptotie
wad 3uterms
input
mms.
not
fur mo waage. NOTA
iwewnl 9E
neeessny wndomtay
anding NOTAT0
thu 4m as wdely
wald upper
biy relative h
fune thotestCondn thhuglest
e TION hotati
s. to tools N eeuhm
coudition Representibmund wayc
ary cxpen that possi ny
em
that poth hao waed amt in ble on ae
ns alway abore allous the that s
wortgrooth
ale bhnteur their to Avernge cae
tm.
4nntime
best
caae longest
outputval notatioms evsed tecknigye a
fr anabye algo
y belod
(ere allgus va to
amp
al compluutes eieny
of conplexity
-Cwe
ime to amsunt deoeribe
tm au yagoi
perjnnance complee nan'(marD
daa anayet cdage algo
of the represantng
complw'
spaey Loweruppe to nenning
statemint time vesult
wil of complatl tpau)tima &
algo posi dalaet
ble this y Cimutwg
BUBBLE SOR]
clemwo each tome
’ ampres conoee htive par y

whun all olemcnto


have ben compod
me, itt Called a
PASS

3 Result lageot/heaviest
elemnt soted
b Ist as,
= n-l, whene n ho efelomns

elemen ar
Noo, 2lvgeat
Anted
n-2 campanins pfomd.
1 2

Cutceme
Loted
Cutomes

Buferences Vaidtr det of


TiM CoMPLEXITY
n elemnt,

n (n)
2

Ma no nn-)
2

Why bubble cot igteotJumallstetumet


mys Heaviest dement sinke down 2
flrab up ike bubbles n noater.
S peform K paaes, whas lhe NAt?
n elementi, if
Kluvgéat elments Wny imp? heat pe
lument,
age goup lumeno, SCan jat pefom 3),
’ time fient

n)
Vord Bubblelnt (ot A[T, mt

(i- 0; ien-); it+)


Code alao painb
Jolio je n-1-i;j++) trudo thal

breaxs
Hono to teu i lis is alaeady nted ?
Q wnp, that
Aw Sn a Lìgte pam, (Ist pas) t thee a no
indicawthat elemut ane aloeady sooted:
Caunr vanasle.
Cek ky minducg
Thus, minmm
aaimum
IS ADA PTIVE we made it adnptie
Bu BBLE SoRT

4 4 4

element, memony locatims do net


fx dupial it is STABLE
obanged Thus, înt temp- AC;l;
At code
=],n-); Bustlekot t )Count
return,
tount-0)
CURS]VE R
regondles
sy exra ytmt
(on)Complauity
lnear with it hu
almest-snted i
tn emoY tny deteut to
esmpeiler ’Ved
in
wesd? itWwere
is
GORI14tM2
memory
ofamt coot Lexta
Tates
fkopoRTIONA
THE L 6f LES|
ayo plaee in
an isLot Bubble ia) n- to
tr(j=1
tth pai'n a
[n) Bubblednt
(A
M ALGOR PLACE IN- AGOR1THM-|
adyaceut tampme nght, to
left l>we
m uep
Reeurve
Slerative
oln) aui ling
kamptity simptet,
A
both h dame
7me compleity for Tale more
Tales es memoy memog
Hvantages y Busble dort " Reptace

J. Eany t ndenataud & imalament by o


2. Qoes net regune auy addithmal memy pa ce
3.
Sable
fain their eatie ndr in sutput)
Qindantages g Bubsle dot Seloet
J. Tome conpleity o() makes it veny storlonge datat
lompanten based iatig algo - ys comp opentor
to aetemine elatie orler eemeno
t can init in certain caes

WRITING
Slsort(amay, si2e)
epeat (site) times
tt itwnst element as min
for eae wnsted element
it elemnent < min
set element a ne min
wap min with int nnted
delee
fom
Auxil

Ne
SELECTION SORT
ypas Soted et
simplont,niost intuihve method.
ting
2 3 4
leeting min fren h
emony Uheted
" Eepla c ca ch consdrtion
imored l e t
by max
vehe (infiuiby)
ce Larger the
Zh wie A, kager will be tenporany eusilia
y menyBot in-plae seting ago
rtoUT VLING ERA MMEMORY uae
slertim lort (A, n)
datast ifolto to n- 2)
rafsr index
Stores ind ey min elemnl
for GitH to n-)

Lmj} upoale indeu min elmnt


3
temp : 4[])
A] [in]; Time Comyleity Ol)

lelectio ort repeatedly lbua alleot llavgest elannt


rom unsoted pant 2 was it ith It element
Aueilliay space o() values
eba memoy is for tenpoy sppig
vaniablestr
mores it to nt
mes. Surapp
mst in n-)
mn lmes it

Adrauntages lo wndstand

Siadvantages
Time complerity sucks.
Qosint wK vel
well on
on lrge daasls
oder
Nat stable (doeant preaeve reative aer ibeny
with eyual key)

StABILI2WETION SoRT
dorpping anes an temetines Dnterckange key:
that he eual vaues ’ mating ew gut o deoired e
Sin in elemnt can be put in postisn by
everyelment he puoting
But this is Again demanh time y
(MaLes it ie nartisn aot)
Alt algontham
leleebiinsart (A 1)
Sngpg cost decsnt maltliy

tems

oired dn
INSERTICN SORT

elument 1)
" tat
n than vale asrt elmut
- wud
No ned totind peutisny inantirn
Jime
Cae unioted

t5

Smt 2
213)5|]8|

No
No 1+24 -tn- = nl-)
2

Tine mp'ui ty - 0n)


No
amppoints
fenmediate passes wil hol ve any seful yeslt,
Benefit f hont on tot is moe in iheod ist than
beeaue hene, we do not hawe to lift the elemnt
"
follonn an nemental pprvach
A1GOKITH4
yid Suatimkoat (A[,)
o (:lto n-t)
2nested loops
j: i-1;

j-)

PsEUDOLODE

Luntime is Completely dipndnt


yinput is soted ol)
ingut is in reve der ’
Uepl- stnt with nd lment of aray [ut element asuned
obe sostbed]. Compane wth soted pnt

3- 4o to 374 element, compne wi th 2d, let wap as


ep4- onie ntil oted
paee Yhint (eha var
siBLE
Adaantages
Simple 2 eay to Cmplament

Cpae tfiient Adaphive


QiSuaiuentr
cadantageo ange liib
as meng tort/ guKyort.
what s an
BASICS GE ALGORITHM
algonthm 2
Afne deg y well
sowt a defined inetmctibns that can be sed to
computational
9t povaln ep by tteppoblm
. Jmiten waing poeedure t conwert input indo deoied
dimple engik langunge pends code to maKe
LAy to wwdistand. output.
meke it
AlGORITHM PROGRAM
Qesigu phae
Smpementation phaat
Knourtfomchant,eh
ny bnguae edge rgd Fogamming lnasladge reqd
tf)2 os dependent
Uhambiguows, can coutain
hnaligezing pofoma algo, r many algoin it
Tstng ofakad.

ules t obtain
crpeutcd eutput
trom the given
input?

NEED FoR ALGO

hutomate pocesses, make them more meliable, quick A


form
o pefomn tasks nng compuer that cannot be haudled
Vsea n maths, Comp lui, Eng, finance, et.
optimite pnenes, snalpe data, male predietions
Prende outious to problem
ALGORItHMS

8E9RCH
e ement wwth ddle cloont at
Compane elemout ,Hhen
he mlle we
I; it u Lost han
fo tu telt pa tron He middle- bthsywto
ghtpart The seorin9
L'conos find tue elmeut hai no
2eanch
h part to

6
3

beg.0 ed Gln-)
oCn-1)
Mid bte0tb 3

7mid),
searehcpale woet to
(key <mid)
< m!
Reuaei
seareh at
nycanch ", Srqcnd, )

tetum binay o ey)


cle

end,
ceHrn binasy seer chl an, mid+,

CoMPLEXIY

Best itoic aot of al found

ComparUcon
l4
Cempaiseo
FIBONACc sEARCH
tehni u that
compaHiton bad elennt in a
3lt u a aneh an

Stnilaiauith B.s gaing

ime
4at leg
Corh

dids an QTay fto uny-a pan ?nde

doRan't any doicen opera to dyid rngs


ne

= 0, !, , 2, 3,5 ,8,13, 2)

=|fn-a).

Csmpano the withindex

KQleir n

new m,
new
2

eut n ofsetr
gubttrattl-)
indyr
preulou ln 2)
nem fm
num ba doom
ceo hew jump a
jeit
go n ew

R
3

33
2

3 fn : 2

winT,J
-L00

(
e t
ALGOR|THM:
engt sert Conr, bsg end )

Merg i t (onn, koq imid)

MIngia,laegmid,end)
Pos Cinti-0, i<ni;itt,
ENiD Mag sert LATiJ aTiagti)
Meg funchn For (inlj-0jrit)

i<n)

Uuhie (i<ne)

tt
)
aNALYeIs
-

cupport

to stoYo lored data

jitt)
wh e no

STABE
gUCk 30RT
Congturr lethnique
Dlvids
keypocan pakhoniA
A

posi
idof
Cubeiwey on each
Parctikon u done
sC

ALGIORITHM
Advantage
’ ekcóen

amouut

Quick ost (a ,2, |): Disadvan to


Suis Bort
t(e1,); Klot a
Poxkhen (Ri)
pivot -a);

do

whiu ti]spivot)

whi (AC]1 pivot )


14Cis)
suap(4C), At;)),
Yeurny)
Middle Laleet
pivot etemant
elewenta ardom
lot
cheiu
far
utdala small DuodvantaPoodg
ein fun to amoumt
entetfico ’
Advarkagel
&tABUE NoT
paxthon
tamatu pivot when OCn) WC
logr) oCnt irot t
elugumiddls pivot

You might also like