Algoritmos, diagramas y pseudocodigo

Page 1

+6BKEF>A #( +A@8:BEAD 7JD<8AD

Gfj Xc^fi`kdfj >gfklalmq]f mf daklY\g \] afkljm[[agf]k im] af\a[Yf ]d [Yeafg Y k]_maj hYjY \Yj kgdm[a{f Y mf hjgZd]eY* N] hm]\] \][aj im] mf Yd_gjaleg ]k dY kmeY \] mfY hYjl] d{_a[Y( eYk mfY hYjl] \] [gfljgd( ]f \gf\] dY hYjl] d{_a[Y ]kh][a^a[Y ]d [gfg[aea]flg ]f dY kgdm[a{f \]d hjgZd]eY q dY hYjl] \] [gfljgd ]k dY ]kljYl]_aY hYjY kgdm[agfYj ]d hjgZd]eY*

> XiXZk\iwjk`ZXj [\ cfj Xc^fi`kd fj ) Pf Yd_gjaleg fg \]Z] \] k]j YeZa_mg* ) ?]Z] \] l]f]j mfY k][m]f[aY afa[aYd q AafYd ) >Y\Y hYkg \]Z]jw l]f]j mfY k][m]f[aY km[]kanY q |fa[Y* ) @d Yd_gjaleg \]Z] \] k]j ka]ehj] ]^a[a]fl] q \Yj mfY kgdm[a{f Yd hjgZd]eY g \] dg [gfljYjag egkljYj mf e]fkYb] im] \a_Y Naf kgdm[a{f

Kif^iXdX Pf hjg_jYeY ]klY \]^afa\g hgj mf Yd_gjaleg ( hgjim] ^gjeY ]d [gfbmflg \] afkljm[[agf]k im] ^gjeYf ]d Yd_gjaleg $[g\a^a[Y\gk ]f mf d]f_mYb] \] hjg_jYeY[a{f% q im] k] hjg[]kY ]f mfY [gehmlY\gjY hYjY kgdm[agfYj mf hjgZd]eY ]kh][y^a[g* ,

46 32 * ) -52 4 -& 0 1 *,& '85*

(0


)>;AC<E?AD ] ,<6;C6?6D 9: .>F=A 6B><869AD :@ 2/2

C \liwjk`ZX G#f Yd_gjaleg im] \Y g hjg\m[] mfY kgdm[a{f Y mf hjgZd]eY hdYfl]Y\g Ymfim] ]klY kgdm[a{f fg k]Y dY {hlaeY ]k ddYeY\g C]mjykla[g *

?`X^iXd X [\ ]claf @d \aY_jYeY \] ^dmbg ]k mfY j]hj]k]flY[a{f _jw^a[Y im] [gf^gjeYf ]d Yd_gjaleg* @f ]d ka_ma]fl] ]b]ehdg k] em]kljY mf \aY_jYeY \] ^dmbg hYjY6 ?DQD?DM $+% \gk nYjaYZd]k = q >( \gf\] ]d j]kmdlY\g ]k YdeY[]fY\g ]f dY nYjaYZd] <* $Q]j Bjw^a[g -%

Bjw^a[g )'

,

46 32 * ) -52 4 -& 0 1 *,& '85*


+6BKEF>A #( +A@8:BEAD 7JD<8AD Gfj jwdYfcfj [\c [`X^iXdX dXj Zfdle\j jfe5

O\id`eXc5 N] mkY hYjY af\a[Yj ]d afa[ag g ^af \] mf \aY_jYeY \] ^dmbg

KifZ\jf5 >mYdima]j lahg \] gh]jY[a{f im] hm]\Y gja_afYj [YeZag \] nYdgj( gh]jY[agf]k Yjalexla[Yk( \] ljYfk^gjeY[agf]k( ]l[*

@ekiX[X*NXc`[X5 N] mkY hYjY af\a[Yj ]d af_j]kg g kYda\Y \] \Ylgk*

NXc`[X5 N] mladarY hYjY egkljYj \Ylgk( k]jw ]d kyeZgdg mkY\g ]f ]kl] l]plg* > fe\Zkfi5 Najn] hYjY ]fdYrYj \gk hYjl]k [mYd]kima]jY \] mf \aY_jYeY Y ljYnxk \] mf [gf][lgj ]f dY kYda\Y q gljg [gf][lgj ]f dY ]fljY\Y* NXc`[X5 Df\a[Y g h ]jY[ag f ]k d{_a[Yk g \] [ge hYjY[a{f ]flj] \Ylgk q ]f ^mf[a{f \]d j]kmdlY\g \]l]jeafY [mYd [Yeafg Ydl]jfYlang \]d hjg_jYeY k] \]Z] k]_maj*

@e ZXjf [\5 PkY\g hYjY af\a[Yj nYjaYk Y[[agf]k hgkaZd]k k]_|f k]Y mf \Ylg \] ]fljY\g Yd [gfljgd*

?\j[\5 @kljm[lmjY j]h]lalanY i af\a[Y mf [a[dg \] I j]h]la[agf]k \] mfY g eYk Y[[agf]k*

,

4 6 32 * ) -5 2 4 -& 0 1 *, & ' 8 5*

)(


)>;AC<E?AD H ,<6;C6?6D 9: .>F=A 6B><869AD :@ 2/2

QXi`XYc\j N] mladarYf hYjY [gfl]f]j \Ylgk \] \aklaflgk lahgk6 f|e]jgk( d]ljYk( [Y\]fYk \] [YjY[l]j]k( nYdgj]k d{_a[gk( ]l[* @d nYdgj [gfl]fa\g ]f mfY nYjaYZd] hm]\] [YeZaYj Y dg dYj_g \] dY ]b][m[a{f \] mf hjg_jYeY*

>fejkXek\j Ngf ]d]e]flgk im] [gfla]f]f \Ylgk( ]d nYdgj Yka_fY\g Y mfY [gfklYfl] ]k ^abg q fg k] hm]\] [YeZaYj \mjYfl] lg\Y dY ]b][m[a{f \] mf hjg_jYeY*

@ogi\j`fe\j GYk ]phj]kagf]k kgf [geZafY[agf]k \] [gfklYfl]k( nYjaYZd]k( kaeZgdgk \] gh]jY[a{f( hYjxfl]kak q fgeZj]k \] ^mf[agf]k ]kh][aYd]k*

Kfi \a\dgcf5 < & # = & . $ * >

>Y\Y ]phj]ka{f lgeY mf nYdgj im] k] \]l]jeafY lgeYf\g dgk nYdgj]k \] dYk nYjaYZd]k q [gfklYfl]k aehda[Y\Yk q dY ]b][m[a{f \] dYk gh]jY[agf]k aehda[Y\Yk* PfY ]phj]ka{f [gfklY \] gh]jY\gj]k q gh]jYf\gk* N]_|f k]Y ]d lahg \] \Ylgk im] eYfahmdYf( k] [dYka^a[Yf dYk ]phj]kagf]k ]f6

<i`kd vk`ZXj M\cXZ`yeXc\j Gy^`ZXj

Jg\iX[fi\j < i`kd vk`Zfj Ggk gh]jY\gj]k Yjalexla[gk h]jeal]f j]YdarYj [mYdima]j gh]jY[a{f Yjalexla[Y $kmeY( j]klY( emdlahda[Y[a{f q \anaka{f%* @f dY ka_ma]fl] lYZdY k] em]kljYf dgk gh]jY\gj]k* ))

,

4 632 * ) -52 4 -& 0

1

*(&'85*


+6BKEF>A #( +A@8:BEAD 7JD<8AD A W M YI L V Y

& &

+,( (*0

4 K K Qe U .4<=1 />71 +>6=5:652125A8 (5?5<5A8 -9=48251 +A3>69 (5?5<5A8 48=4;1

8 RM T W SV @ & $ # @ & " # @ & " ! # @ 2 % ! " @ 2 # ' " @ & $ +,( " @& $ (*0 "

D M Z \ S[I L V " $ % # 0 ( "

@d gh]jY\gj HJ? \]nm]dn] ]d j]ka\mg \] mfY \anaka{f ]fl]jY( ea]fljYk im] ]d gh]jY\gj ?DQ h]jeal] j]YdarYj mfY \anaka{f ]flj] \gk f|e]jgk ]fl]jgk( Ydda jw\a[Y dY \a^]j]f[aY [gf ]d gh]jY\gj Ç+É*

M \cXZ`ye Xc\j K]jeal]f ]nYdmYj dYk j]dY[agf]k ]flj] mf hYj \] gh]jYf\gk* Ggk gh]jY\gj]k j]dY[a{fYd]k kgf6 Jg\iX[fi : :9 8 89 9 9 g f

<ZZ`ye H Yq g j im] H Yq g j g a_mYd im] H ]f g j im] H ]f g j g a_mYd im] D_mYd ? aklaflg

G y^`Zfj Ggk gh]jY\gj]k d{_a[gk hjg\m[]f mf j]kmdlY\g Yffc\Xef' q kmk gh]jYf\gk kgf lYeZaxf nYdgj]k d{_a[gk g YkaeadYZd]k Y ]ddgk $dgk nYdgj]k fmexja[gk kgf YkaeadY\gk Y Z`\ikf g ]Xcjf k]_|f km nYdgj k]Y []jg g \aklaflg \] []jg%* Ggk gh]jY\gj]k d{_a[gk kgf lj]k7 \gk \] ]ddgk kgf ZafYjagk( ]d |dlaeg $f]_Y[a{f% ]k mfYjag* <I? #T$ Kjg\m[] mf j]kmdlY\g [gf nYdgj \] n]j\Y\ kil\ [mYf\g YeZgk gh]jYf\gk la]f]f nYdgj \] n]j\Y\ ljm]7 ]f [mYdima]j gljg [Ykg ]d j]kmdlY\g l]f\jw mf nYdgj \] n]j\Y\ ]Xcj\) N`ekXo`j5 nYjaYZd] , <I? nYjaYZd]. ,

4 6 32 * ) -5 2 4 -& 0 1 *, & ' 8 5 *

)*


)>;AC<E?AD H ,<6;C6?6D 9: .>F=A 6B><869AD :@ 2/2 JM #J$ Kjg\m[] mf j]kmdlY\g [gf nYdgj \] ^Ydkg ]Xcj\ [mYf\g YeZgk gh]jY\gj]k la]f]f nYdgj]k ^Ydkgk7 ]f [mYdima]j gljg [Ykg ]d j]kmdlY\g l]f\jw mf nYdgj \] n]j\Y\ kil\) N`ekXo`j5 nYjaYZd] - JM nYjaYZd].

IJO #IJ$ Dfna]jl] ]d nYdgj \] n]j\Y\ \] gh]jYf\g* NaflYpak6 IJO gh]jYf\g

@a\dgcf 5 Na gh]jYf\g la]f] mf nYdgj \] n]j\Y\ kil\' efk gh]jYf\g hjg\m[] mf j]kmdlY\g [gf nYdgj ^Ydkg ]Xcj\)

Ki`fi`[X[ [\ cfj Jg\iX[fi\j Ggk gh]jY\gj]k \]Z]f k]j ]nYdmY\gk k]_|f dY ka_ma]fl] hjagja\Y\

A . *) < /*) &( +( Hg\( Igl 0*) '( <f\ 1*) :( 8 ( : 9 ( 8 9 ( 8 :( 9( Jj

@I OM< ? < * N<GD?< [\ [Xkfj Ggk \akhgkalangk \] ]fljY\Y + kYda\Y h]jeal]f im] ]d mkmYjag afl]jY[l|] [gf ]d kakl]eY* Kgj e]\ag \] dgk \akhgkalangk \] ]fljY\Y ]d mkmYjag af_j]kY dgk \Ylgk Y hjg[]kYj ]f ]d kakl]eY q dgk \akhgkalangk \] kYda\Y em]kljYf ]d j]kmdlY\g* GYk afkljm[[agf]k \] @+N \Yf Y[[]kg Yd hjg_jYeY\gj Y dYk ^mf[agf]k Zwka[Yk \] ]klgk \akhgkalangk( h]jealaxf\gd] [YhlmjYj \Ylgk \] dgk \akhgkalangk \] ]fljY\Y q Yka_fYjdgk Y nYjaYZd]k hYjY gh]jYj [gf ]ddgk q egkljYj j]kmdlY\gk \]d hjg[]kg ]f dgk \akhgkalangk \] kYda\Y* )+

,

4 6 32 * ) -5 2 4 -& 0 1 * , & ' 8 5 *


+6BKEF>A #( +A@8:BEAD 7JD<8AD G@@M K]jeal] ]d af_j]kg \] \Ylgk Yd [gehmlY\gj( ]d \Ylg d]a\g \]Z] k]j YdeY[]fY\g ]f mfY nYjaYZd]( dY kaflYpak ]k dY ka_ma]fl]6 G@@M mXi`XYc\

@N>MD=DM K]jeal] j]hgjlYj j]kmdlY\gk \] mf hjg[]kg( lYeZaxf k] mkY hYjY ]fnaYj mf e]fkYb] Yd gh]jY\gj* GY kaflYpak ]k dY ka_ma]fl]6

@N>MD=DM QXi`XYc\ @N>MD=DM ÑO\okfÖ @N>MD=DM @ogi\j`ye Q]Yegk mfgk ]b]ehdgk( k]_|f k]Yf dYk kaflYpak Yfl]jagj]k j]kh][lanYe]fl]

@N>MD=DM M\jlckX[f @klY afkljm[[a{f \]nm]dn] ]d [gfl]fa\g \] dY nYjaYZd] M]kmdlY\g

@N>MD=DM ÑKi\gui\j\ gXiX \c `e^i\jf [\ [XkfjÖ @klY afkljm[[a{f em]kljY Yd mkmYjag ]d [gfl]fa\g \] dgk Yhgkljg^]k( f{l]k] im] hYjY hg\]j egkljYj mf l]plg ]kl] \]Z] aj ]f[]jjY\g ]f Yhgkljg^]k g [geaddYk k]_|f ]d d]f_mYb] im] mlada[]*

@N>MD=DM /%e @klY afkljm[[a{f hjae]jg [Yd[mdY dY ]phj]ka{f 0&f q dm]_g em]kljY ]k] j]kmdlY\g*

O`gfj [\ [Xkfj \jZXcXi\j Ngf Yim]ddgk lahgk \] \Ylgk [mqgk ea]eZjgk ]klwf [gehm]klgk hgj mf kgdg yl]e $\Ylg%* Ggk lahgk \] \Ylgk ]k[YdYj]k fYlangk kgf Yim]ddgk lahgk \] \Ylgk ]k[YdYj]k im] qY ]klwf aehd]e]flY\gk ]f ]d d]f_mYb] bmflg Y kmk j]kh][lanYk gh]jY[agf]k* @flj] ]klgk lahgk \] \Ylgk l]f]egk @ek\if' M\Xc' >XiuZk\i' =ffc\Xef6 ewk Y\]dYfl] n]j]egk gljgk lahgk \] \Ylgk* ,

4 6 32 * ) -5 2 4 -& 0 1 *, & '85*

),


)>;AC<E?AD H ,<6;C6?6D 9: .>F=A 6B><869AD :@ 2/2

<j`^eXZ`fe\j PfY Yka_fY[a{f [gfkakl] ]f \Yjd] mf \]l]jeafY\g nYdgj Y mfY nYjaYZd] g [gfklYfl]( hgj ]b]ehdg ]f dY ka_ma]fl] k]fl]f[aY gZk]jnYegk im] Y dY nYjaYZd] <( k] d] \Y ]d nYdgj \] 1* < 8 0 ?] eYf]jY kaeadYj hg\]egk l]f]j dY ka_ma]fl] Yka_fY[a{f < 8 / & #. % T <-$ n]egk im] mfY ]phj]ka{f Y ka\g Yka_fY\Y Y dY nYjaYZd] < <d_mfgk Ymlgj]k mkYf ]d kyeZgdg

]f n]r \] a_mYd $ 9 % hYjY mfY Yka_fY[a{f*

?\ZcXiXZ`ye [\ mXi`XYc\j H]\aYfl] dY \][dYjY[a{f \] nYjaYZd]k \]k[jaZaegk dYk [YjY[l]jykla[Yk \] dYk eakeYk* GY kaflYpak im] mkYj]egk ]k dY ka_ma]fl]6 I f d Y i \ [ \ m X i `X Y c\ 5 O`gf @flaxf\Yk] hgj lahg( Yd lahg \] \Ylg \] dY nYjaYZd]*

OvZe`ZXj [\ [\jXiifccf [\ Xc^fi`kdfj @pakl]f \gk hjaf[ahYd]k lx[fa[Yk \] \ak]zg \] Yd_gjalegk \] hjg_jYeY[a{f( ]d Ofg ?fne q ]d =fkkfd Pg)

Ofg ?fne OYeZaxf [gfg[a\Y [geg \] Xii`YX(XYXaf q [gfkakl] ]f ]klYZd][]j mfY k]ja] \] fan]d]k \] eYqgj Y e]fgj [gehd]ba\Y\ $YjjaZY)YZYbg% im] \]f kgdm[a{f Yd hjgZd]eY* >gfkakl] ]f ]^][lmYj mfY j]dY[a{f ]flj] dYk ]lYhYk \] dY ]kljm[lmjY[a{f \] ^gjeY im] mfY ]lYhY b]jwjima[Y q km afe]\aYlg af^]jagj k] j]dY[agf]f e]\aYfl] ]fljY\Yk q kYda\Yk \] af^gjeY[a{f* @kl] \ak]zg [gfkakl] ]f mfY k]ja] \] \]k[gehgka[agf]k km[]kanYk \]d hjgZd]eY afa[aYd( im] j][aZ] ]d j]^afYea]flg hjg_j]kang \]d j]h]jlgjag \] afkljm[[agf]k im] nYf Y ^gjeYj hYjl] \]d hjg_jYeY* GX lk`c`qXZ`ye [\ cX kvZe`ZX [\ [`j\xf Ofg(?fne k`\e\ . fYa\k`mfj Yuj`Zfj5 ) Naehda^a[Y[a{f \]d hjgZd]eY q \] dgk kmZhjg_jYeYk \] [Y\Y \]k[gehgka[a{f* )-

,

4 6 32 * ) -5 2 4 -& 0 1 *, & ' 85 *


)>;AC<E?AD H ,<6;C6?6D 9: .>F=A 6B><869AD :@ 2/2 kgdm[agf]k hj]k]flY\Yk fg ]jY [gehYlaZd] dY mfY [gf dY gljY( fg j]hj]k]flYZY mfY _dgZYda\Y\( [YjY[l]jykla[Y hjaf[ahYd \] dgk kakl]eYk* >geg fg `mZg mf hj]nag Yfwdakak( \ak]zg \] mfY kgdm[a{f Y fan]d _dgZYd ]f lg\gk kmk hjgnaf[aYk( []fljYdarY[a{f \] af^gjeY[a{f( im] kgf [YjY[l]jykla[Yk hjghaYk \] mf \ak]zg ?]k[]f\]fl] $Ogh ?gof% q [YjY[l]jykla[Yk ^mf\Ye]flYd]k \] dgk kakl]eYk7 ]d hYak fg hm]\] kYlak^Y[]j km f][]ka\Y\ Y fan]d _dgZYd* GY [j]Y[a{f \] Yd_gjalegk ]k ZYkY\g kgZj] dY lx[fa[Y \]k[]f\]fl]( dY [mYd Zjaf\Y ]d \ak]zg a\]Yd hYjY dY kgdm[a{f \] mf hjgZd]eY*

Kj\l[fZy[`^f ?aj]egk im] mfY fglY[a{f ]k mf hk]m\g[{\a_g ka e]\aYfl] ]ddY hg\]egk \]k[jaZaj ]d Yd_gjaleg( mladarYf\g hYdYZjYk q ^jYk]k \]d d]f_mYb] fYlmjYd kmb]lYk Y mfYk \]l]je afY\Yk j]_dYk* Of[f gj\l[fZy[`^f [\Y\ gfj`Y`c`kXi cX [\jZi`gZ`ye [\5

) Dfkljm[[agf]k \] ]fljY\Y + kYda\Y* ) Dfkljm[[agf]k \] hjg[]kg* ) N]fl]f[aYk \] [gfljgd \]d ^dmbg \] ]b][m[a{f* ) <[[agf]k [gehm]klYk( Y j]^yfYj hgkl]jagje]fl]*

KYjY ]fl]f\]j e]bgj ]klgk [gf[]hlgk n]Yegk Yd_mfgk ]b]ehdgk*

@a\d gcf , @dYZgj] mf Yd_gjaleg q km hk]m\g[{ka_g hYjY [Yd[mdYj ] aehjaeaj ]d wj]Y \] mf ljawf_mdg*

NfclZ`ye5 ?\ZcXiXi QXi`XYc\j ='C 5 i\Xc @ekiX[X5 $\Ylgk Y afljg\m[aj Yd [gehmlY\gj% =Xj\

8 =

<ckliX 8 C )/

,

4632 * ) -5 2 4 -& 0

1

*,&'85*


+6BKEF>A #( +A@8:BEAD 7JD<8AD Jg\iXZ`ye5

>Yd[mdYj wj]Y \]d ljawf_mdg $=Yk] p <dlmjY%+.

NXc`[X5

$M]kmdlY\g im] egkljYjw ]d [gehmlY\gj%

Kj\l[fZy[`^f5

-* Dfa[aYj hjg[]kg .* ?][dYjYj nYjaYZd]k C 6 j]Yd = 6 j]Yd < 6 j]Yd /* G@@M = 0* G@@M C 1* < 9 $ = & C % + . 2* @N>MD=DM < 3* O]jeafYj ]d hjg[]kg

@ogc`ZXZ`ye Kj\l[fZy[`^f5

-*) N] afa[aY ]d hjg[]kg( lg\g hjg_jYeY g Zdgim] \] hjg_jYeY( \]Z] l]f]j mf af\a[Ylang \] afa[ag* .*) ?][dYjYegk dYk nYjaYZd]k Y mkYj( dYk nYjaYZd]k C q = kgf \] lahg j]Yd( \] ]kg k] \]\m[] im] ]d j]kmdlY\g \] mfY gh]jY[a{f ]flj] ]klYk \gk nYjaYZd]k lYeZaxf k]Y \]d lahg j]Yd( hgj ]kg < lYeZaxf ]k \]d lahg j]Yd* /*) G]]egk ]d nYdgj \] dY nYjaYZd]k = ( hgj ]b]ehdg \a_Yegk ]d nYdgj afljg\m[a\g k]Y 2 0*) G]]egk ]d nYdgj \] dY nYjaYZd] C ( hYjY ]kl] ]b]ehdg af_j]k]egk -, * 1*) >Yd[mdYegk dY ]phj]ka{f $=&C%+. q \a[`g j]kmdlY\g dg YdeY[]fYegk ]f dY nYjaYZd] < ( ]flgf[]k k]jw6 < 9 $2&-,%+.( hgj dg lYflg l]f\j]egk < 9 /,* 2*) @k[jaZaegk ]d j]kmdlY\g \] dY gh]jY[a{f( ]f ]kl] [Ykg k]jw /, * 3*) >mYf\g mf hjg[]kg g hjg_jYeY k] afa[Y( \]Z]egk af\a[Yj km ^af( [Ykg [gfljYjag( \a[`g hjg[]kg hm]\] ]b][mlYjk] af^afalYe]fl]* ,

46 32 * ) -5 2 4 -& 0 1 *, & ' 8 5*

)0


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.