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

basics

Uploaded by

soovamsg
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)
5 views

basics

Uploaded by

soovamsg
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/ 12

Ducta Stvuehunes& Alaoituws Prof.

Trupesh Patel -
LDRP ITR
CHAPTER I INTRoDUCTIoN
Veiniti&M
A_cdatu strueture is a Speeilined tsmat
Orgixiu pwcesiug redrieNiu uLe. stosiu dutu.
Basic eminele
ata Zatu CUeVeulues o set o Valus.
ZatuItem at item turs to Single unt ob. Values
Giroup Itms: Zrtu itms hut t divided iuto Su
ites re Culle, as Gjorup its.
tlmeutuy ttms etu itms Hhut Cannet be divided
C Calle as lMLtuy|tms
Entity An eutity 15Hhut which Coutu'n cetuil
atvibutes oY ppperties which ma be asipnes valus,
tielo lt is_aSingle elemeutu Uit einetmeti
epestina a cutoibute_o ce euity.
Recwr Keeme is a celleetid o_ gielel Vrulueso a
qive eukty.
Filefile is a Colleetidno hewtels o He euh'hes
IMC ive eutity Set..

Algeritnm
ovim isCL5tep-by-step p7rteelure Leuielu
dehiues Sete nstrueticns t be exeetee
Cdan Dhdur get he_clesineel_Output

Categories oalgoriHhms :
Seahch -Update
Sort - Delete

nst
Prof. Trupesh Patel - LDRP ITR

Clasiicatin ot Datu Stmetue

atcuStruetune

kinew utu Non-linew_ate


Stauetue| Stuctw

Shutic etu yhtmic putu Tyee Gph


Stuetue L stmetu

Qu Stue inked ist


Axruy

Linew au StruutwL stnutul l_which_utu

elmeuds_an 3E4uuhiall4_or inewrl wheL


0
attuehe to its Pwious cluel uert
eeLch_elemut is
dolcLeluf_elemeuts 15 Called linw Zutu stnuehre.
PxeAmptes Arruy uue. ahuek linked list.

Non- Linea Vau Stnuetune Datu stuetwhes_Lwhvre odat


elemuuts _ne not plued Sequeuhiall ar lineanl ane

Cullee nen-linew dutu Stnuetures.


EXamples 1 mphs
Prof. Trupesh Patel - LDRP ITR
atu Types
he okutu tpe is Hhe ftuto_a Vwiable t
Wlich a Value Can be sipntd. It dihines Haat
Parhicul Vriable wil sin e yalusa5
ve dutu bype0nly.

pimiivE_Dah stmtwris
Pimitve Dutu stmuetures_Cne Hhe hsit
Sfrutues HautdisectyapL2ate upon e madine
istctisMs
ELmples Tutys Elpuhi peiut numMbers , Chtr.aetr
Constuuts Strin4 Constuts Poiuturs,

Non-primihve Date struehures


Non primitve olau 3tctes he Mrre
Complicauted than rimihvedutu sthuctus but kiglly
seu.
Exanplesakns, linked t , stue,quues, tre, 1mph.
Zau struutureOpuaiims :
lzavesing neans t Visit he elemeut Stores
Stered
iM it E visits dlut in_a Systamutic mnne
This Cu be elone whciny pe o _pat Statu

Seanching tmens h kinel apoticudr eeme


in He ve olatu Stmatune l t is cousideeol as
Succesu LWhe r4uire elemut s au
isposible n dact stnuctres ltke _
in -list tee93up heks
Prof. Trupesh Patel - LDRP ITR

Tnsvti Meelns to Clolel CM elemt


I hheL 9ive letu Stuctu.

aM_elunut n
DetidN_ melns_w gemove
he iven clcutu structwe

Analysisof Algoritm how


Veveloping a
omula or preelietiM o
H algovithm wsles bes eo 04 pmbu
st
_

5iz
e?inpnt lutput i
pmblem Size coulel be o.
C _alyorithu

The ynumb ak opsatims mwlvel in He algoritm.


Hhe numbet o
Evampleoh a Sonhin_al oritM
inpus 1S H ttzu humbe ók_elenMut tp_be
rhanae n a Specihic Dhdes. h e nu mbes o
Sortea elmet
Outpts is he totzl hUmbeá o

I Sewseing a e l u n f y an asauy
we ant
havin nelmuts,Hhe prehe SiLe s Same
Cs Ane humber_ef_elemuts n a n e tp
bu Semehe. H e the mblwn size cu
inpnSixe CUre the Same an_1's equd_to_n

two Chreus5 _o Size h_and m_oNe _merqeel


size isHe Sum ak two
te prnbtem
Sizes C=ntm).

r_uctesiad bein Cemptee, blen


Si s
Prof. Trupesh Patel - LDRP ITR

imeComplexity_t ls e Cmouut of Compute tim


i t neees exeute e p r p ana get tco me.

Speuce Cerplexity Itis defineo _as t ameunt e


memnyy
memny uihed unning algorithm
h_
ConcliM, Detemihatio e kine aned SpaLe
Complexit e} algorithm_leas to analysi og
Clgorithi

Ondes ot Magnituele ek_an AqoriHm


t is the Sum e numbe o Bccwemces_ of
Stutemeut Contuunee in it.
ExAmple 1
Ko(20, i4Ym |t1)

um Hhe L Sttemets inside


oap *_/_

Asumphm:
Thue _e C Stctmeuts nside
leup.
Foeh Sttemeuts teke ane
nit o ime
The csuphivms_Ce uele beeause inpimatid
he tget muline is hat_pMLdM when
te alsorim
i Sbuilt S i t i s et possible. to Sc hew muc
meech studtunet in he alaorith tkes to
eyeeute, The eyacthime
depnels n he uc'ne.
M_which e _cllorit î s un
As pe Hhe Prof. Trupesh Patel - LDRP ITR
asumphonMs
Tot time e exe.cutidm hr 4 Jwap = c¥1=c
Since Hhe loop is exerded ntimes.
Totcl time o exeeutisn = h ¥c
1h n*c is dejined_as he Onder o6 Magnituele
0 Algori. Sincecis a Constent oreder o maguitude[
is aoxivmute o be eeqU to n Tuis appai mah
3 beeausc t highe Velues n , the etheet ot
c is ho Squihicant 1hus constaut Can be
1moreo

Wonst_case Whey dalgorith eeuutes Miimum


humbet o nstruehis in_0ndvh p givHn
duin butput he Scemario s calles wost
Case Scenaud

AnyeCs uhe algoritm eXeeutes


Um bej1 o
instrehs inerdle 4ive He
desied Dulpu the Sceuaio_is Callel CwUge
Case SceMwio.

Bet case uhe algoviHm exeutes minimum


numbe e ustruchidns orde to qive He
desineed utput He Scenaiois_cale bst Case

lamewMaticul Notutidhkwi Detviminah e_Hhe


unMig ime oCM_AlgoiHm he mst vequine
methematical notahidn1s t cletermine Werst case
Avncye cose cnel Sest Case runmi tine as
it's dibhicult to Ceunf he numbe of opuhicns
wostavegebest cascAunnin time
nchcal PaoHems.
Prof. Trupesh Patel - LDRP ITR
Asymptotic Notahis (0,,e):
orelen i _Cnalyse which_dutu struetuwre or
uoritm isHhe best Sutes hu hejob , ltis Meeese
1 ndesune how_a_dahu shrekure behuves OVn time
CLmal SpeLe. u imnptanttuol n HusCnalysi is
Asympkokic Wotutiims.

Big-O_netuthim 0Notutin
Big o fers set e aukunchinswhese
Vcuteis_wighu han_Hhut o He_culgorimm's
gowth_ake
Tis Ca be use npresent hirst Case
OWnaL Case or butCase Condihns_ak
algorihm
fn) =qF boune of tt
algoritym

Tn) is bnd within kon)


jon clifh prwble sizes

Mo 1
Pr Size-
Thrsheld (rwH e
Size Cye)

OO is callee as iq Oh. _ts MeAniw is s as o


behas as is olejined as tu _yate at wich tha
time o exesutidnM pmble
9ize
Tcn) time eyeenh' oCM_algeritmm ditheot
frobem sizes .
Prof. Trupesh Patel - LDRP ITR

cn) mcuthemticd Tpresentativy C


alsoritum as a uuchioN O prbleM Size

nen on negahive uAchis Tcn) auel en) the


unchi Tcn) Ofen))i hre Ce Positive

Constuuts Canel M suc thut Ten)c*fcn)


cull

Tuis netehiib)is ndo By-oh hutuhiM


boune to
gaphesl n) SLves asan P
Tcn). t describes
CWLve analysiny ,
the wst Hhut Can happu qive
dah sie.
while veluhingJen)w ftn), velah is se
Tis velahim sinis bouo The ime e

Computatioy ( T ) Cay beequ or lu than_af).


Jt cuunot 0 beyoue Hhut yadue ef et
hveshele problem Size 15 tnL minimum pobleuy Size
buyene which we C A yprediet Ht oehviou o t
Vspect te pefpimanie t h e ulgorith

mequhotutioM _Notutie
l t epresents the ewe bouna kr time_ek executidn ob
CAM algorithm
Omega yefes_t Set e_alkuehisns es12et
Yute lous Hhay hat o_the aulaorithm's
t yure
The bat_Casruwní timeo_ay caaoritmm is
detninee wh he alyoitha hus the bet
20%iH Loeib eyeeu M._
Prof. Trupesh Patel - LDRP ITR

The best Cuse Auning m C aleritm LA


eprutul lay Muttmemunca equoutid 0 4ollb
tuNon-neguHie funehims Tn)_ euefn),
e kuncid Tu) _2(ft) if he a n
=

Pesihve Constuyts Canel Mo Suc thut Tn)zcf)


a l n , nZM
Ldhere Tn) is He kime e f eyeutid of
alaoTitmkei oikterent Veuese phlem Sixe
This sheuld be ee cs Tat n is Omeaa
H fon) is He Tu
eens a Value o u (nzna), the
ime Compututis e algorith Tn) T's
alwys above_te
Sues a s lonwel bounel Tu)
hest thut Cy eeppen -
C cltu Size

Thet Natutio ' e ' Notatienn:


he avetae Case yunning time_er cnalaoriHu
is dekezminel whe he olgovitm_has CVerLe
Covdih e x eeutidM1
Searclr eXample, t h e Mumber e be Searche
is in Hne mid posihiM M the Sewreu Cwo ule
Call hs_as the wrge condii .

Mahemuica equatid. t h e avraj Case


hen- Megaive funchins Tn) cud qn),-
the unetidn T) 9gc)) i th the exist positive
Conshuuts CaC Cne ,Such tut
Prof. Trupesh Patel - LDRP ITR

C1gn) Tn)<Cagcn) ad n 4n7 Mo

whee, Tn) -time executidn o aMalyonm


gr ditereut prmblm siz .
meuthemcutical pseututi a CA

a l ovithm a uMctia pmblem


Size
This sheul be veue as T e n is
heu

The Thetu Netti is mu. precise thann


_oh Cnd Omega netutioMs
he unchin en)= elgm)i g) is bota
pper Chd Joweh bound TC).

ime Cemplerity EramleS


1 Oc1) Constat Cempuhin time
Ocn) Linew
3. Quacrutic
Cubic
OC2") Erpo nnhi
Below tuble ive q wick Vicn o_Va'ons unebm

g nleg
1 1
4 4
2 16 16
4 64 S12 2S6
1664 2S64016 6SS36
S 32 16 104 13276r|42141472961
FunctiM Values.
Prof. Trupesh Patel - LDRP ITR

plot_o5_ funchib Vues

SO

3o

10
-l05

O 1 S 10

e Asumptis while kinaling Time Cemplexih


enel all
n_nel all
The lencliugconstunt
The e hijhest_powe_
powS on 'n ant iqnor n fu)-

Exmple Ten) O 100t t2qt191) .1)


pan_C is
Leneliu Constaut o hiyhst
10D_wlhich_can b quorre
Se, )
ALHe ouu ponleA 2qyt 1 9 )cay be
1ynerre S 0 e g u a t i 2 caM he ladmtte as3,
Tu) = Ocn)

Eyumples Time cempleity.


Calcuate tim Complexiy_aeileoiagpga
21

riut 2
Prof. Trupesh Patel - LDRP ITR

So As lep itexutestiu is EM
fn)=
O (fe): 0CM)

2 i:1t y_do

fay k EJ+1 tp n eo

s Hre ipp exeentes Hmes


Joop exeuutes -1 mes t n s it
Lwap exeeurey y-2 hmes_

h e ttd cout of _loaps= - ) 4-)

Count ot 2t1 dpeels _n the evsul


eeuh ime.
re4. Count[z =Zt2) =_ The twte ount ot Leeps
oreler o t h loop
ot
-M2 -3+2
3 x2

gmeu the tbd cerplexib coee


0.cy.

You might also like