What s on algoxithms ond its types.
*Alqorithms is a tep by Sep procedure 40 Psforn a
Specific task
alqosithm ie a Sequence of intruchion to ocoomplich
Pauticulay tosk is alled o Algovithm.
*Tt Consistg aeal kywode
er, START, etop , ReAO, print, 1f,Then,else, Goto ete.
Popertie
*t muet be cimple ond cleax to undestard
+ t mugt ensure about the kesult
It muct idertity the numbei of Steps.
Syrtox:
Step 1
he numnbeng
Step 2
PROceLs 0R formula. fid he
Stepz
Sum sep4 : PRist...Display he Rests
oY Sumsteps STop
*Alqorithms ake laeeified irto 3type.
. Sinpla Algorithms
londitiona! Algosithms
3 Itesatiee or loopig alyosithms.
Simple Alqoxithms:
Simplu othaatica! openationg
+An alqovithme Cortains Snçlu
+ it cbeg not Cotains ony Cortions, Loo ps
Ex Step1: START
Sep : ReAO P,TR
Step3: Si(e*T*R) hoo
Stepy: Priot
Steps: StoP
Conditional alqoxithme
4Alqosithms Contaice Conditions to execute only one parttiule
Statement
it ueg îF, THeN, END,Tfeop e
Sytax; er1: TACT
Stepa ReAD mouke
Step3: f maokey=38 Then
Pint" result is paes"
Print"regult is pail
eno if
Stepu'. STop
Iterotive alaorithms
Write an aloorithmns to pirt I to lo Cunbes
Step1 : START
Stepa: ReAD i=t
Stepzi PRit P
Step4: i- R+1
Step s: ie ieeo hen
goto Stps
End if
Step6: stop.
Nottions
*Notations is aleo claled an prvession or Equation or
mohematial omdo
* Otafiong to caloulate the noning time Compuxity
an
aleorithms.
Notationg ore claacitied into 3 types
Best Case: misinum ime Raquived for progorn evecutian
Pvenoge Cace: Avenoqe time quired foY Pvooron
pvovom exeeution
Worce Case: moeiMUm ime Raquired fov proGorrm eeeution
The commonly ved aeymptoic notation s to Caleolate the
Runtine Complity of an algorithm
*O otation
2 notation
+ 0 Nototion
Big Oh Nttin 0:
* This notation On) is the formal oy to express
the vpper bound of an alqovthms running time.
*Tt meoUKES the woxest Case time Computy oY the
Lonqest omount of time on alqoithms Con Poseiby bk
to Compluae 9en)
f(n)
or exomple, for o fonctiontn)
0(ftn) $gn): thesie eists C0 0nd Mo Such that
)ecqn) for all n>no
Omego Notation,n.
The otation Ocn) is the -formal woy to erpeeg both the
Loue boUnd ond the uppor bound of on alqovithm's aunir
time
t meosUKes the haet Cage time Cornplexitu OY the Amount
Of time on alqorithm Con posaikble to Compste
fln)
9n)
-fer exomplu, for oa funion tny
n(fco)>£9n): hexe exits Co ond No Such tho gn) cc.
ThetaNotaion, 0:
ile notatin Gn is the formal oy to &ress bilh the Laue
bourr ond the uppe kound of on algoihis unning time
It measures the bet Case time Compty Or the Pvsoe
Omout o an alqoithns Con fosslbly toe to Complik
Pointes
Pointers denived cthlype
t is a vaiable which Con ctoxes the oddkees of
onthe muiabl
o powenful tool to oceees the dib throgh
îndivect Refeenco.
it ie a Oynamie voiabo ie., it ado cate memory to the
Waiable at tha time of execution.
t he proCecL f alocating memory to he Vaniabe is
Called 0s dindg
AIl the noImol Vagiablas alecate memory at trnpils
time is Called as Statie inding or eoaly bindinq
but pointes vosiables alaate memory ot execution
time is Caled as dynamic bindi0g ov tate biring.
t poinle Appots tuo poenfu fetKey
+ manoxy moroqemertt:
it alsate marnsy to a vasiabla wboneven it veqive by
the usen ond de allocat memory wthenaven it ot \quvel
by the memory wthast uwaste.
’Serity moraqe ment
frovides eoutty to the data thranh indivect
vefelence ii.e,, it hides the data
Syta
dstotyçe partevasade ieg: int*
+ Pointens uport tun special openalks
’Amphensond (8)
Amphoond Rapreserte the Addveos o the
Vaiable.
’AStenisk(*)
Asteis Rapresents. the value op the Wasioblu
Exomple:
iclude <stdio.hs
t includee conio.h>
void moin c)
int n 5o
clrecrc);
Aitfaddregg of P vouiobla is %x\n,p.
frintfNalve of e Vaaiabe is °od\n"l:
gedeh();
Stack
A ctac is a inea) hta ctructuse thot followe the
"LIFO" princi ple (Loct in first out)
+ this meons the last elomers insested is the -irct ame
to be Semoved
semove fom h top.
The follousing the list of opeotion thot con be
Penformed a stoct.
Puch: The insentian opeaion is Called os push opeatin
oPhe deletion opention is Caled os pop opesotíon
Tvavense isitig ch ord veny doto tem of a stock is
Called trovense opedotion.
overflow: insenting an elmert in on alsuody 41led
Stack is Called astlow
un OenfjouJ! lhe pop opendtion wth in an
emptystoclk
led
Called as unoenslow.
Stock opetons: it on be impamented by usinq tuo uays
Stock using Aray Stock ueing linted lis.
Thuy anu eny Eociy whi represerting tock Usig
impamented withhelp Unkad isb we haje to ibrtity
of a a y . we hnave oy asnqs node.
two apntions Pushe &fopc)
(A) Alooxithm:puh opelion.
intialy top s-\,Mat si13 step1: Raod on elannt ito item
step1: [hek for venfla Cveate arous no tern
f (top41= Monsize) sd-empdlo iten,
temink nl)
oisplay'oveN-flaw
eye top=toptl topeteP
Raad a volue itoite
tenp.nattoP
Step2:e t torn
Steps it
(8) Alqorthm:Pap opention.
step l: obeek for ondufou s1 (chec -for undesfia
iTfaps--) (topznul)
GsployUrdoflow' oisploy'gtack undanfow
else
lse
itern sAocktopiop:opy itemtop.Oota
dispa'ald emit)
Stepn: e t top=toplint
Cc) Alqoithm:trovense opoasion.
tep4:if (topr-) steea. cehecle -f uode flou]
Cispla'stayisEmpty" if(top =eull
get itop
display"stoek
else
undotow'
whie o) temptop
play sto[i while(temp!ll)
display temfdota
Step EH temp-temp.link
Step? : eit,
ie a ineax dota otrocture which follouwcs FIfo mechonicon
The elsment ingeted tiret is xemoved fivct Tust like feou
SAonding in o ine (queue )
F1fo sonde -for foret Rn-First out
he -fol bwing oxe the L|st of opevation that Con be pertomed
on queue.
Erquee:he insertion queue opeotion is Called Enqueue
De queue: The deletion opesntion is Called Dequeue
Tronvense: Vsiting each and evey element in queue
Reox Front
A
Ovenfow: insesting on extta elumert in an alteods flle d
quee is Callect arOflouy Befoxe Deko îrngesting on elamerl
into qUere we need to toke Coe OF 0vetlou
Stuation.
ungfow:he oeletion opection with on empty queve is Calle
unDeflouw. Befose Deletion on elemert in queve,
to take Coxe Ofof Ueflow situat lon
Quee Con be
implamented in tuo ways
sing Aray
Q. Queue using linked lict
Cisculo linked lich:
linVed list.
A Circulam Linled ist S aeo Called as doubo erdkd
The only diffexet behween he sigly linked it ordo Circua
linked liet is thot the lact node heg not poirt to ory ro
in o
Sinqu inked ligt,so it ike pait Cortains a null value.
on the othen hond, the circulam linked list i a List ic, o
List in which he Last note Conneds to the ffxgt nodes, so
the ink pat of the last rode hold the ffst nodeg pddres
the circulas lin ked tist hos ng Sarting ord eding rode. we
Con tovenee in ony direction, i.e., erthe anuod ot fornnd.
The diaqrommatic repreertalion of the Cireulam inked List s
Shoun beloy
gtct mde
int data;
Struct derext;
A Circulo Linled lict s a Seoence of elamerls in uhich ch
no has a dink to the net od, and the lat noda is houing o
lin tothe firet node. the repreertrtion of the Cireulag
linked
List wi be Similog to the Singla Gnkd List
100
hood.