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

DS-Notes

Uploaded by

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

DS-Notes

Uploaded by

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

Atgpmittm

DeiAn algprithern uana set ot instuctiors jou


pegoni paiuala task/problem solig opeaon.
°paeda
-The nstuchons ae rothing but the staterment in
simple Eych langage
tAChucteustis/Propeties ot algotm
OGach algoritm is suppied usitt Zeo mone
Each alaoith must roduce at least one qutput
each algpmthm shouid have poitaness ie algonttrs
teminates opte a ginie numba of steps
5 Each algonthm should bave deioiteness ie the
steps showld be clea and unambinuous
Eacb algoritbm shoubd bave ekectveness. It shoule
be gasible to conet the alaoittm na pYqam
*Atorthodesign tools
Flowbat iFlow chat is a diaqammhc
AepAeeutahon
Flouschat symbols
staut /stop
POcess Indicato
Irput/output
Deisi n YorN
on decision staemet, USIalky yo

Aro
Pseudo-longuage /pseudo code
Tt is a combioahon o the consucts t +e
Pgammig laguage and npal Engish stateet e
A Step - count metho d /Fequery cont ethod
De";- It is a count that denotes boomany tines
patuula /eac inshucoo is eeuted.
It is used to calculata t>e toe omplexity
Void fun c
3 int a
a=lO

prntf "%, a)S

The equery or step count of abovepgrag is 2.


Armount feoyat
o tme
Compleity oq alaorith reuived g te pags
S Time cormpleEy 29 Space compleity
2)
*Anount ot time Aeained by Amont of spac meny
an algon thm ts ereube is Aeqiined by an algorittn
caLled the tine cormplezity to mD is called spaa Cemplet

* To deeuine tme complezity ot algoth


DIdentty basic opeations othe algoitbm
Isequeny count n basic
)Considea onde ot rnagpitude ob beauery count art
epAeo t in teus o biq oh notos
ATo compute space complity.uoe se tuso goctars ie
Constonts and instance chauacteushs
It is dero ted by Sp
S(p) ct Sp
ohee SCp) space com pleity
- Constant, it derotes Spaeof iptoop
space dependert upon instane chactastu
Fized paut ncudes space kon inshuchors, vaiables ek.
Vaiable pat ieudes spae kon cootolstatemests (leefs)

Asympohc notabons i
Osing asymptotie ootatons,ude cas give time
complezity as "fastest posei ble", 'slooest pocsible" o
aveage time.
Vaious notasons Suchas O,2,9 ae aalles as
asymptobc notasons

90 O (Biob) notatn
- Bi oh notation denoted by O. It pondes arsptohi
upper bound gpn aqives kuncon
-0 desaibes the complezity Othe code
fC) = Cgca) fon all k t e lel numbe
fCa)is said to be O(gx)),gthee euss tuso
t+ ve,aeal laes Constants CsK such thal
fCz): csCz ton al K
no tabon
2) Omaga
Tais pDndes simuttanDucy botbasymptosc

notaion poides asymptobc lose tosod


a gven kunchon. The fla)is said to -2ga)
tbee eistb tao posi hue ioteleal no Costants C4K

B) theta) notaion
Gpoides simtaneousy bots asum ptohr
wppe bound and asymptohc Louoe boundton
Tbe ttu) is sad to be 9(9()) 4 thee esto
C and Ca posi bve Constosto such tat

Dala obiect -
-IL a set o vauables used s a pogam.
JL u a plae cobeAe the data Vallieo ces be
stoned, eteved,and manipulatee
Evey data obiect e associatcd usitth data type.
*Dala i- It is a colectn t oumbes, alphatets
nd symnbola cembined tD nepaeent inkonahon.
- A waw dala s paoceed byy campule and t
poduces nekiDed dala as output
Dala
Dala is b aus OIgonan is poocessed
dala
Dala may an may Inpmahon isalays
not be mesnitub. mearinggl
Data may not be en hgonaton geneasay torae
SOe speeeende specige ondeig
Eg. Ea student's DE The averaae sca acass
SCane
maus seram is tbe dered konnehm on d

k Dala stucue A dala


A stuctuue ii a paheuta
aay otongonizi dala in aa com pua so that it
Cas be used
ttechvey
Foa etample i- Conside a setofelenents obich an
be stoned is aray dala stutue.
-The uepaeoentton set t
elenesta is as oUbos
2 t-inder
+ Dala type It's atem ohich nefeus to the
tind odat that aa vauable ryay bold
Eg nt 7oat, hau et
*Abshact Dala Type CADT)
-ADT is gally de7ned to be atoplet (D,FA)
obee D’Set t domains
F’Set of opeass
A > anuioms desoig thekchonF
- ADT s adata tupe ,obee ony oehano is
degoed but ot implementahon
- I n ADT, all the implemestabSm deau lo ae
bidder

KArray -Abstract Data Type


-Aay is asADT +hat bolds a set ot elemeu
accesSible by as jndez
Aray element
23o
20 4oso
A y de z
ADT aay Can be declaned as
stuctue ARRAY (alue,indee)
declae
CREATEC)’
aroy
RE TREVE (arroy
inde)’ alue
STORE (array,indez, value) ’ aay
6
Types/classiBaan Data
DataS u e s

Pimithe Dala sttue Non- mive Ds


E int, char,Noat
ioca Non-ineay
Eg Tree,Gras
Staic Dynamic
Eg Asay Eq Queue, Stack,inked ist

) Pooiive dala stuctwe


- These ane built n datastucwes type
Eg iot, kloat, chau

>) No-pimive dala stuctue


These dala stuctues aue deived
pimive dala stwctues
Eq AYYay, Stuctuue, ioked-ist, nioo.
stack, aueue,tree nd qrpb

)ineau ala stutue


stuctues
ineau daa stuctues ale the data

staight seyuere sequen aty


ist
Eq Aray
Non-ineau data stutuue
- Dala stutues owhich daba
biecbical manne.
auanged
Eq: Trces, Gyaph
- In tis, dala is not auarged sea uenhaly.
x Staic data stctue
-- Data stucues haing kxcd size ot memony
ue alled stasc data stctue.
EgAay
-MernOy LA allocated at the

A Dynam ic dala stuctue


Dala stuctuue suhich mnemoy is alloated
as pe the nequiument
-Tmeror is allocated duing edeo
çoed ist

Stasc ynamic
OTnemay is allo cated at
the time ot loadiog OMem
the tboe
alloca bes at

( s h c dala stutuue gay


oturig
( No such poblem s
Cause
Ovepto dua to unde dyamic data stuctue.
allocaion
Access speed is bigbe Access speed is sla.
NOAeusabiity oh memey use otrmernoyis
pOssible
mobd. Fa2
Codess Arony

Algoithmie Desigo sthatyes


De";- Aqouthmic desian stategg a gereas
appoad ay cohich marg pooblem an be
solved algoithically
Tbeae ptblems may be diffeent aueas of carmputin
- It ua also called as aloitthmic techoques oa
t
alaontmic paradigm.

Types sateg
D Dinde and Congue 2)The Gredy Meth
3) Dypami Pogamniog 4) Bacttackig
8)
ODiride and Conquer CDAC)
This echoique is dinded nto thnee pats
) Diide i-Tbis iovoves dindina the po blen
ioto snalle sub-poblens
ii)conquei- solve sub-poble indeperdesty
Ig the sub-prokblem is lauqe, DAC is Yeoppie
ii)Corobine '- Combine the soluhns e subpoobleK
tonet the solubon to onignal pobler
|Poblem o size n
Sub pmblem 1 Sbpsob lem 2

Soluon to
Eanples ot DAC Stateg y
)Qick sat 2) Meqe sont
Findi taima 4) Buay sencb
s) Towe t Hanol
Mege soat
- Meg S t n an ioput auay sith n eleerd
Consists ot tee stepPs
)Dinde :- Pason auay ioto tsD SUblists siad s2
usth n], elemen eacb
2)Conquei: Then sont sublist Sj and S2
B) Cormbine i: Meae sy ard s, into unique sortedqztup
Eq consider the elenents as 70,20,Bo,40, 10,SO,6
|7020|2ol40iolsol6o
Dinde yDisde
7o|20|30 40|1olso lGo
Divde Diide
Jol20 Bo|
Diide

mege
|lol4ol so \Go|

mege /mege
2) Greedy stbategy
-Tbis metbod is populan kon obtainin the
Ophmi zed soleons .
In Greedy technique,the soluton is constuctad e
througb asequee at steps,each cpandi
patia ey constucted solubao, ss a ornpleke
solubon to tbe problem is neached
In Greedy methad 7olousiog achinhies aue pogoma
1) Fust select some soluson KDm ioput
2)Tbe chek uobetbe the soltion is easible o not
3) Fom tte set ot jeasible solusons, paheula
solubons that satisjes aneay satiskes the
objeche o kuncon, Sucba soluton is caled
Opmet solubon.
- As Greedy method uDuts s staaes, at each stage
ny one input isi consideed ateac tir
Eq ' 'Con chanae problem" Io tbis you bave Set o
Cos denorinahos and you uDant
oant to te

hane 7ona qiven amount ot mmoney usirg pas


possible cons

63 cests
Poblersi You want to nake
a d 2s cenu
Using 1 cent,3 cents 10 cen
solution using areey appoadh
1)Stat ust cents
2) Tbe lagest cos less thar on cqual o G3 cents
Is 25 cents. Subract 25 cests, leavinn 32cera.
3) The lauqest con less than n equal to 32 cests
is 25 cenls Subtct 26 cento, leaiy 13 cetb.
4) Eind lauaest co less thas an equal to 13 cents
is l0 cento. subtact t0 cento
leavig 3cets
S) largst coin ess thasa cqualto cents is
1 cent : Sbtract cent nes.

Iot & case, tbe GYeedy sateay aesults in


using 25 cents+ S cents t iO centst 1cest+ Ceot
t l cent 63 certs
Unt 2
inca Dala studues usig seuenal ogpi
-Ib Sequenhal onaani2ahon,elementa
elemento a e stoed s
Censecutive memoy loaton
* Fopahes sequental ganiaahon
DSimple to use 2)simple to desiq
aConstant access toe a3moppig by caple

*Advantages
) A t e elenents ae stoned at conouous
menoy Loc Hesce serching o elenento
SDm sequen al nganizaia is easy.
2)Elemeo caro beaetievd nstoned vey
edenty ushtbe belp ok iodea or mem locatis

* Disadvastage
)Iseboo and delen eersento becones
compicaled due to seguehal natue
2) Fon stoni data, lauqe cooiouous thee blect
mena 4 eleests
3) TMerany aqentacn
ane Aandoy aemoved
8. W e an ADT
ADT KDA OMays
Abstrac bata Type Aray
InstaSces i AnaAay
An auay A Aot some size, inde i a e
total n0.of elenesta s tbe asay
Opelasens
1) Cheate C)
2)5sutC)

Dsplayc)

8. Ezplain 2-D amays wsths


w a d columo
majn nepeentahan

) Rouomajoa nepmesentahon
- 4 the elements ae stoned is ao-ose
manner tthen it s called oo
najanepeetatin
we uOant to stone 10,20,30, 40,SO, 60 +he
2D
ausy tbe elenents usil be stOned
2
bomzontally o o 20 30
60
2) Co lumn nmayn nepeserntahon
+be elenesta ue stocd o calumn sise
mannes then it à aalled columo majonAepre
we ane to ctome elements IO,20,3o,(0 Soo
Considen
QYay a(3)(2)
array 20

2 30 6o

Qi- Eaplain the concept oot anded ist


’ Ondee ist is notbin but a set o elerments
- IE iw also called as ieau list:
Aset ay be eMpty
Eg Listo orne diqt numbe=3o,2,3,t,S,o, 7 a
ist b auoeek S, M,T, w, T, F,s{
Colons n Yasbow- v, ,G,B,Y, o, R

Q.Erplain poy nomul epeentatin usig auay


4 ’ Poyomad
al is
is tt
the sum o terns obee eacy
tem consisto avaiaabe,Coettteut epoad
32s I 0 9
2

917 s3
6-obat is Spuse mati1 ?
mati amati cootoini
e o n 2 e o elemesls
the nati

ry l0eements , o e bas
-Tben koa accessing these
tthese
to mace OO00 times Scar!
- AHSo ony JO spaces u U be wsth non-2eo
usl be kkUed ui 2es s
Remasig
ie ue bave
mat
to allocae memey o
A

You might also like