DS-Notes
DS-Notes
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
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
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
Stasc ynamic
OTnemay is allo cated at
the time ot loadiog OMem
the tboe
alloca bes at
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
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.
*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)
) 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
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