Algorithm Design - Khorsand -   ...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview:    ίభ̶ਉϸ̯ϥϩච໔ ΨϤণඟ໕Χ߮Ζণ΋      ZÆ¿M¶Ì¸veÁZźfË´·YY¿YZ]ÊËZÀ‹M…{¥|Å  …{[Zf¯ Algorithmics Theory and practice G.Brassard P.Bratley  …{ž]ZÀ» 1. Intruduction to algorithms Second edition T.H.German C.E.leiserson R.L.Rivest C.Stein 2. Algorithms R.Sedgewiek 3. The art of computer programming D.Knuth      ¶§  Greedy Divide and conquer Dynamic programming Exploring graphs  ZźfË´·YY¿Y  AlgorithmºfË´·Y  {Y{Y€ËÉZÅʳ„ËÁºfË´·Y€Å {€Ë~a¹Zn¿YʏyÄ]Z¯,{‹µZ^¿{ʏZy\Ìe€eÄ]€³Yį¹Z³Ä]¹Z³|ÀËM€§®Ë  {Y{ÄnÌf¿ZËÊmÁ€y®Ë¶«Y|u d‡YÊ¿|‹Á¹ZÆ]Y½Á|]½M¶uY€»Y®Ë€Å d‡Y¹Â¸ »½MļeZy•€‹   Á{Äm{Ä·{Z »®Ë¶uºfË´·YZËɀeÂÌb»Z¯dËZ‡®ËYÃ{Z¨f‡YºfË´·Y,ʳ|À¿YÄ»ZÀÌÅY³~yYºfË´·Y|À¿Z»  ProgramÄ»Z¿€]    d‡YÃ|‹Äf‹Â¿ʈË¿Ä»Z¿€]½Z]®Ë|ŸY«[ÂqZq{įd‡YºfË´·Y½Z¼Å    Ä»Z¿€]®Ë¾f‹Â¿¶uY€» ZÆË|À»ZÌ¿ɁZ‡ºÅY€§ÁĸXˆ»dyZÀ‹,ZŁZÌ¿­{Requirment    d‡Y€Ës€‹Ä]Ã{Z‡ÉZÅ´·YYÊ°Ë {Y{{ÂmÁʨ¸fz»ÉZÅ´·YÄ»Z¿€]®Ë¾f‹Â¿ÉY€]  ÊuY€—Design ¶Ì¸veAnalysis ʈË¿|¯Ä]Á€‹|ÌËZeY†adËZÆ¿{ÁZÆË|À»ZÌ¿ÊËZÆ¿ʇ€],ʈË¿Ä»Z¿€]ÁŠËÓZaRefinment and coding ÊÀÌ]Z]Verification Program testing Program debugging Êf‡{cZ^iYprogram Proving   d‡Y€Ë¶¼Ÿć¶»Z‹{Ây€yMĸu€»į    d‡Yd‡{ºÌÀ¯d]ZiÁºÌÀ¯ʬ¸eʸ¯Ä̔«®ËcÄ]YÄ»Z¿€]Ä°ÀËYÊÀ ËÊf‡{cZ^iYÄf°¿   ºÌÅ{Ê»Y€«ʇ€]{»YZÆ¿MÁÄfyY{€aAnalysisÁDesign¶uY€»{€fŒÌ]…{¾ËY{   ºÌÀ¯Ê»¶Ì¸ve¶°‹Á{Ä]YÃ|‹Äf‹Â¿ºfË´·YÓ¼ »‚Ì·Z¿MZ§{ d‡Yd‡{ºË‹¾X¼˜»  ¹Y|/¯Ä·Zˆ/»cÂ/®/ËÉY€/]¾/°¼»ÉZźfË´·Y½ZÌ»ºÌÀ¯ŽzŒ»Z“€§ ºÌÀ¯ĈËZ¬»Ä]ZŒ»ÉZźfË´·YZ]YºfË´·Y  d‹Y{|ÅYÂyɀf¼¯ʧ€»½Z»ºfË´·Y¹Y|¯ZË,{Y{ɀf¼¯ʧ€»Ĝ§ZuºfË´·Y   Function russe ( A,B ) X[1] A Y[1] B i  1 While X[1] > 1 do X[ i+1] X[i] div 2 Y[ i+1] Y[i] + Y[i] i i+1 end p0 while i > 0 do if X[i] is odd then p p + Y[i] i i -1 end End   |À¯[€“ºÅ{YtÌv{|ŸÁ{ʧ€»½Z»¾Ë€f¼¯Z]į|ÌÀ¯ÊuY€—ʼfË´·YµZj»  €Ë{Z¬»Z]©Â§ºfË´·YÉY€mY A= 45 , B= 19 1 2 3 45 22 11 1 2 3 19 38 76 1 2 4 4 5 5 2 4 6 1 5 X 6 152 304 608 8 16 Y 32 i=1 2 3 4 5 6 5 4 3 2 10 p = 0 608 760 830 855    |À¯¾ÌÌ eYº¼ÌÀÌ»Áº¼Ë‚¯Z»,AɀÀŸnÄËYM{į|ÌÀ¯ÊuY€—ʼfË´·YµZj»  1) Procedure Smaxmin( A,n,max,min ) 2) Max,min A(1) 3) For i 2 to n do 4) If A(i) > max Then max A(i) 5) 6) If A(i) < min 7) Then min A(i) End 8) 9) End   1 2 3 10 20 5 4 5 17 35 A  ¶]Z¬»ÄËYMZ]ºfË´·YÉY€mY Trace table n max min 5 10 10 2 - 20 - 3 - - 5 4 - - - 5 - 35 - 6 i  ʧ€»½Z»¶Ì¸ve cZ/ §{{Y|/ e ºÌ/À¯Ê/»ÉY~/³ÃZ¼/‹YcYÂf‡{ ºÌÀ¯Ê»Ã{Z¨f‡Y€ËÃ{Z‡Ã|ËYYºfË´·Y®Ëʧ€»½Z»¾Ì eÉY€]  ʧ€/»½Z/»Z/eºÌ/À¯Ê/»ž/¼mºÅZ]Y¶ZuÉZÅ{|Ÿ ºÌÀ¯Ê»[€“Âf‡{€Åʧ€»½Z»{ÁºÌÀ¯Ê»Y|ÌaYÂf‡{€ÅÉY€mY   Ä»Z¿€]Ä¿ºÌÀ¯ Ê»d^vºfË´·YÃZ]{|̋Z]Äf‹Y{ÄmÂe |ËMd‡|]ºfË´·Y  ÃZ¼‹  cZ §{{Y| e   ʧ€»½Z»  2*3 ¶¼ ·YÂf‡{ Y€°e Y€mY€Å     n  n-1  €j¯Y|un-1  n-1  €j¯Y|u n-1  n-1    ŽyZ‹Â¼n» ½Z»Â¼n» ʧ€»½Z» ʧ€»   Á¶/»ZŸºfˆ/̇,€eÂÌb»Z/¯ÉZ/¯‰Á,Y‚§Ydz‡Ä]Ê´fˆ]Y€Ë {ÁMd‡|]½YÂeʼ¿Êf‡{Ä]Y½Âf‡€ZÀŸ|‡Ê»€œ¿Ä]   {Y{ Ä/f^·Y ºË€/̳Ê»€œ¿{ʧ€»½Z»ŽyZ‹½YÂÀŸÄ]Y½Âf‡€ZÀŸÂ¼n»ÁºÌÀ¯Ê»kZyhv]YY½Âf‡¶°Œ»¾ËY¶uÉY€]   d‡YcÁZ¨f»ºÅZ]¦¸fz»cYÂf‡{ʧ€»½Z»Y€ËdˆÌ¿ªÌ«{ŽyZ‹¾ËY     |À¯|Ì·ÂeYÊqZ¿Â^̧Ä·Z^¿{{|Ÿ¾Ì»Ynį|ÌÀ¯ÊuY€—ʼfË´·YµZj»   |ÌÀ¯º¯Y½MʧZ“YcYÂf‡{į|ÌÀ¯Ê ‡ |̈ËÂÀ]ÃZ]Á{Y©Â§ºfË´·Y¾Ë€¼e if n 0 0 Fn 1 if n 1 ( F ) ( F ) if n 2 n 1 Golden Ratio : F (n) n 2 1 5 n ( ) n Á 1 5 2  ZźfË´·Y Function If If If fib1(n) n = 0 then return(0) n = 1 then return(1) n >= 2 then Return ( fib1(n-1) + fib1 (n-2)) End Function fib2(n) i1 j0 for k 1 to n do ji+j ij-i end return (j) end function fib3(n) i1 j0 k0 h1 While n > 0 do If n is odd Then [ t j.h j i.h + j.k + t i i.k + t] t h2 h 2.h.k + t k k2 + t n n div 2 end Return (j) End  |/ËZ]‚/Ì¿ɀ/´Ë{¦/ˀ eÊqZ/¿Â^̧Ä/·Z^¿{į|̇Ê»ÄnÌf¿¾ËYÄ] |ÌÀ¯ĈËZ¬»ʬ˜À»€œ¿YYfib1Áfib2Áfib3ºfË´·Y¾Ë€¼e   |‹Z]cÁZ¨f»½Mʻ¼Ÿĸ¼md‡Y¾°¼»Á|‹Z]Äf‹Y{  Function Euclid (m,n) While m> 0 do t n mod m nm mt end Return (n) End  |ÌËZ¼¿ķ»€§Y€ËºfË´·Yʧ€»½Z»µZj» Trace table  ¶u n m t 32 24 8 24 8 0 8 0   d‡Y{|ŸÁ{­€fŒ»Ä̸Ÿ¹Âˆ¬»¾Ë€f³‚]½{ÁMd‡{Ä]ÉY€]ºfË´·Y¾ËYÄf°¿   |ËYÃ|‹ÄmÂf»Y©Â§ºfË´·Y|Ë‹¾X¼˜»¾Ë€¼e  ¹Â/ƨ»ºÌÀ¯Ê»Ê ‡ ºËÁÊ»Ĭ¸u¹Âƨ»¡Y€‡ {‹Ê»Y€mYZ]|Àqįº̼ƨ]ºÌ¿YÂeʼ¿†a dˆÌ¿for¶j»whileĬ¸u  ʧ€»½Z»Ä^‡Zv»  €Ë{Z/¬»|/¿YÂeÊ» I¾ËY€]ZÀ] {‹Y€mYZ]k€j¯Y|uĬ¸u|ÌÀ¯‘€§ |À‹Z]Ĭ¸u¹Yi‰{€³½ZËZa{nÁm€Ë{Z¬» m i , n i |ÌÀ¯‘€§   ºÌÀ¯Ê»ŽzŒ»YĬ¸u‰{€³cZ §{{Y| e½MÉÁYÁºÌËZ¼¿ķ»€§YĬ¸u ºfË´·YÄ]{ÁÁÉY|f]Y{\Ìe€e¾ËYÄ] ºËÁMd‡|]¦¬‡®ËkÉY€]įºÌÀ¯Ê»µZ^¿{ÊfÆm{Yhv] |‹Z]Äf‹Y{YkÁ ÁÁ Y€/«€]•Z/^eYnÁm¦/¸fz»€Ë{Z/¬»¾Ì]ºÌÀ¯Ê»Ê ‡ ºËÁÊ»ºfË´·Y¡Y€‡Ä]µZu {‹Ê»Ã{Y{½ZŒ¿n 0Ám 0Z]nÁm€Ë{Z¬»   ºÌÀ¯ n i m i 1 m i n i 1 mod i 1, 2,3,...., k  n1 m0 m1 n0 n 2 m1 mod m0 m2 n1 mod m1 m i 1 ¾ËYYµZj»¾ËY{ ºÌÀ¯Ã{Z¨f‡Y½Z¼Ì“ZËcZ»Â¸ »YºËÂ^n»ÊÅZ³œÀ»¾ËYÄ] ºËÁMd‡|]YÉY|¬»kÉY€]|ËZ]į|ÌÀ°¿‰Â»Y€§   ºÌÀ¯Ê»Ã{Z¨f‡YÄ̔« (n mod m) < n/2    ni 1 mi 1 2 2  ÄnÌf¿{ mi ni 1 mod mi 1 mi 2 2   ºË{€¯Á€‹ m k 1 Y¶Ì·{¾Ì¼ÅÄ] d‡Y®ËÉÁZˆ»Á€f³‚]Z¼fu†ad‡Yd^j»ÁtÌvÃ|¿Z¼Ì«Z]®Ë m k 1 Z»Yd‡Y m k 0 mi   {‹Ê»€¨ÉÁZˆ»m k,¹YKZ]½ZËZa{,{‹Ê»Y€mYZ]kĬ¸uºËYÃ{€¯‘€§ m k 3 m k 5 m k 7 m 2 3 d0 2 2 2 2 {‹Ê»ÄnÌf¿Ę]YY\Ìe€e¾ËYÄ] 1 m k 1   ºË€Ì³Ê»€œ¿{k = 2d|‹Z]kÁ€³YÁk = 2d +1|‹Z]{€§€³Y d‡YĬ¸u‰{€³cZ §{{Y| eKÄf°¿ m m0 1 m0 2 d 2 d m0 d log 0 d 2 2    †a,|‹Z] log m 2 |¿YÂeÊ»€j¯Y|ud†a k 2d k 2d 2. log m0 k O (log m) k 2d 1 k 2d 1 (2. log m0 ) 1  cZ/ §{{Y|/ eÄ/¯ºË€/]Ê/»Êf¼/‡Ä]Y–]YÁZËĘ]Y¾ËY,ºÌÀ¯Ê»Y|ÌaYĬ¸u€]º¯Zuʬ˜À»Ę]Y,ʗ€‹ÉY€°eÉZÅĬ¸uÉY€]   ºÌÀ¯Ê»¶¼Ÿc¾Ì¼ÅÄ]‚Ì¿{Y»€ËZ‡{ {Zf§Y©Z¨eYÃ{Z‡Zf^ˆ¿Z¯¾ËYµZj»{ {‹¹Â¸ »Ĭ¸u‰{€³  Data structureÃ{Y{½Z¼fyZ‡    ºÌÀ¯ÄmÂeʸY{»Á{Ä]|ËZ]Ä»Z¿€]€Å¾f‹Â¿ÉY€] ºfË´·Y  Data structure    |ÌÀ¯ÄmÂe€ËµZj»Ä] {‹Ê»ɀ´Ë{¦Ë€ e\^‡Ê°Ë{€Ì̤eÊÀ Ë |¿Y{¶]Z¬f»€ÌiZeºÅÉÁ€]{»Á{¾ËYį 10 , 5 , 25 , 15 , 7 ÄfŒ/a{©Â§ÉZÅ{|Ÿ€³YÁ{‹Ê»¦Ë€ e¶°‹®ËÄ]½{€¯c‡ºfË´·Y|À‹Z]ÄËYM{©Â§ÉZÅ{|Ÿ€³YºfË´·YÊuY€—ÉY€]   |À¯\e€»É{ cÄ]Y€Ë{Y|ŸYį|ÌÀ¯ÊuY€—ʼfË´·YµZj»   |‹Z]Ê»ɀ´Ë{¶°‹Ä]½{€¯c‡ºfË´·Y|‹Z]ɀ´Ë{‚Ìq€ÅZË        Data structureY¿Y ÄËYM  Link listÉ|¿ÂÌadˆÌ·  |À¯Ê»µZ¤‹YºÅYĜ§ZuÊ·YÂf»ÉZÅÄ¿ZyÁd‡YÂ¿®ËY‰€ZÀŸ¹Z¼eįd‡YÉZfyZ‡ Structure R { int a; Struct R*p; Struct R*q; } u,v,w; u.p = &v; u.q = null; v.p = &w; w.p = null; w.q = &v; v.q = &u; Graph¥Y€³  G = (V,E) V: Vertex …Y d‡Y…YÁ{Ä]Ê°f»ž¸“€ÅįµZËÁ…Y¶»Z‹ZÅÉZeÁ{YÉYğ¼n» E: Edge ž¸“ µZË directedY{dÆmÁundirecteddÆm½Á|]|‹Z]Ê»Â¿Á{¥Y€³   ºËYÃ{€°¿ŽzŒ»YZÅdÆm€—Zy¾Ì¼ÅÄ] d‡YY{dÆmħ€—Á{įd‡Y¾ËY|À¿Z»dÆm½Á|]ž¸“€Å  µZj»    |À¿Zˆ°ËºÅZ] (v 1 ,v 0 ) Z] (v 0 ,v 1 ) ¾ËY€]ZÀ],|ÀfˆÌ¿\e€»kÁ,…ÂWkÁdÆm½Á|]¥Y€³®Ë{  V(G1) = { A , B , C , D } E(G1) = { (A , B) ( B , D ) ( A , C ) ( C , D ) ( A , D ) }  {‹Ê»ºÌ‡€ev 1 Ä]v 0 YÊ¿Z°Ìaį {‹Ê»Ã{Y{½ZŒ¿ v 0 ,v 1 \e€»kÁZ]Ä^·€ÅY{dÆm¥Y€³®Ë{ |ÀÅ{Ê»½ZŒ¿YcÁZ¨f»Ä^·Á{ v 1 ,v 0 Á v 0 ,v 1 ¾ËY€]ZÀ]  V(G2) = { A , B , C } E(G2) = { < C , B > < A , B > < B , A > } V(G) = { A , B , C , D , E , F } E(G) = { ( A , B ) ( B , C ) ( E , F ) } Ä/]Â/z»ÉZÅŠËZ¼¿¥Y€³Z»Y |À¯Ê»Ã{Z¨f‡YÉ|¿ÂÌadˆÌ·Ä]•Â]€»ÉZÅŠËZ¼¿YÁd‡YÉ|¿ÂÌadˆÌ·YʏZyd·Zu¥Y€³   ÉYÂn¼ÅdˆÌ·|À¿Z»{Y{Y{Ây  connected|À]ºÅ¥Y€³  ¦Ë€ e|Àq Path€Ìˆ»   |‹Z]Äf‹Y{{ÂmÁ€Ìˆ»®Ë¥Y€³…YÁ{€Å¾Ì]ÃZ³€Å,|À˳|À]ºÅY¥Y€³®Ë Treedy{   |‹Z]Äf‹Y{{ÂmÁž¸“®ËÄ·Z^¿{¾ËYYÊ·YÂf»…YÁ{€Å¾Ì]Ä°Ë—Ä]d‡Y¥Y€³…ÂWYÄ·Z^¿{®Ë€Ìˆ»®Ë  |À¯Ê»Y|ÌaÊfy{ZfyZ‡,|‹Z]Äf‹Y{ž¸“n-1ÊÀ Ë|‹Z]Äf‹Y|¿Á{Á|‹Z]|À^¼Å,|‹Z]Äf‹Y{…YnįʧY€³   |À˳Rooted TreeY¶Zudy{ÁÄf§€³€œ¿{Č˹Z¿Ä],YZy€ÀŸ®Ë,ZÅdy{{Ó¼ »  –‡Âeį|‹Z]ɀÀŸdy{Č˺ÌË´]Ôj» ºË€Ì´]€œ¿{ºÅɀ´Ë{¦ËZ›Á,dy{ČËÉY€]ºÌ¿YÂeÊ»   ºË‹dy{{YÁºÌ¿YÂeÊ»½M    {Y{{ÂmÁ€Ìˆ»®Ë–¬§Á–¬§,€ÀŸ€ÅÄ]ČˁYÄf°¿ ÃZ/‹YŠ¿Y|/¿€§Ä/]parent€/ÅÊ/À Ë,ºË€/̳Ê/»€œ¿{|¿€§Ä]Ê·Á•Z^eY,Y€ZÀŸ•Z^eYdy{{Ó¼ »  YÊ/Zy¶°/‹Ä/]ZÅdy{Ä ·Z˜»ÉY€]Ó¼ » |À¯Ê»ÃZ‹YÉ| ]¶ˆ¿Ä]€ÀŸ€ÅºË´]ºÌ¿YÂeÊ»ZË |À¯Ê» Binary TreeÊËÁ{Á{dy{   ºÌÀ¯Ê»ÃZ‹YÊËÁ{Á{dy{¹Z¿Ä]ZÆ¿M Ä/]Ê/ËÁ{Á{d/y{{À/³€Å {Y{d‡Y|¿€§Á`q|¿€§¹Z¿Ä],‚ËZ¼f»|¿€§Á{€ÀŸ€ÅÊËÁ{Á{dy{{   d‡Y€Ë¶°‹    |‹Z]Ê¿Zˆ°ËÉYÂfv»Á½Zˆ°ËÉZfyZ‡¶°‹ÉYY{ÊÀ Ë |‹Z]ɀ´Ë{Êb¯Ê°ËÃZ³€Å,|À˳ÉÁZˆ»ºÅZ]YData structureÁ{  dy{ª¼Ÿ   |À˳dy{Z¨eYZ˪¼Ÿ,Ydy{ÉZŀÀŸÉZÅt˜‡º¼Ë‚¯Z» Full Binary Tree€aÊËÁ{Á{dy{    |‹Z]Äf‹Y{|¿€§Á{½M€ÀŸ€ÅÃZ³€Å|À˳€aYkª¼ŸÄ]ÊËÁ{Á{dy{®Ë  d‡YY€«€]€ËÉZÅÃY‚³kª¼ŸÄ]€aÊËÁ{Á{dy{®Ë{ d‡Y 2k 1 €]Y€]¹Ynt˜‡€ZÀŸ{Y| e  d‡Y 2 k 1 €]Y€]dy{€ZÀŸ{Y| e    ºÌÀ¯Ê»Ã{Z¨f‡Yi ÉÁ€]Y€¬f‡YYÃY‚³cZ^iYÉY€]   d‡YY€«€]ÃY‚³i = 1ÉY€]  Y€¬f‡YÉY|f]Y  Y€/«€]‚Ì¿Y€¬f‡Yº°uºÌÀ¯Ê»d]ZiµZu {Y{€ÀŸ 2 p 1 ,¹Ypt˜‡{ÊÀ Ë,|‹Z]Y€«€]ÃY‚³i = pÉY€]|ÌÀ¯‘€§  Y€¬f‡Y‘€§ €/ÀŸ 2 p 1 ,¹Ypt˜/‡{Ê/f«Á†/a {Y{|/¿€§Á{½M€ÀŸ€ÅÊÀ Ë ºÌÀ¯ÄmÂedy{¦Ë€ eÄ]d‡YʧZ¯œÀ»¾ËYÄ] d‡Y   ÊÀ ˺ËY{€ÀŸ¶^«t˜‡€]Y€]Á{¹Yp + 1,É| ]t˜‡{,ºÌ‹Z]Äf‹Y{ 2.2 p 1 2 p   d‡YY€«€]ÃY‚³‚Ì¿¹YP + 1t˜‡{†a  ºÌÀ¯Ê»Ã{Z¨f‡YÃY‚³YÃY‚³cZ^iYÉY€]  Z]d‡Y€]Y€]€ZÀŸ{Y| eÃY‚³ª^—,kª¼ŸÄ]ÊËÁ{Á{dy{®ËÉY€] 2 0 21 2 k 1 2 k 1 Complete Binary Tree¶»Z¯ÊËÁ{Á{dy{ { |/‹Z]€/aÊ/ËÁ{Á{dy{Y1 , … , n€ZÀŸÄ]€›ZÀf»‰€ZÀŸÃZ³€Å|À˳¶»Z¯YɀÀŸ ndy{®Ë Ä/]`/qYZÅÃZ¼‹t˜‡€Å{Á{Y{YÃZ¼‹ČË,ºÌÀ¯Ê»ÉY~³ÃZ¼‹Y€ZÀŸ,€aÊËÁ{Á{dy{®Ë  |‹Z]Äf‹Y{Y•€‹Á{|À˳Kª¼ŸÄ]¶»Z¯dy{YÊfy{   |¿YʌËY‚§Yd‡Y |‹Z]k – 1ZËkt˜‡{½MÉZű€]    |‹Z]Ã|‹Z£M`qd¼‡ÄÌ·YÊÆfÀ»Ykt˜‡ÉZÅÀ³¹Z¼e   1. Lchild (i) = 2i 2. Rchild (i) = 2i +1 3. Parent (i)n = [ i/2 ]  ºÌ/À¯Ê/»¶Ë|/^e¶/»Z¯Ê/ËÁ{Á{d/y{®ËÄ]YÄËYM€Å,ºÌÅ{Ê»½ZŒ¿ÄËYMZ]Y¶»Z¯ÊËÁ{Á{dy{€Åįd‡Y…Z‡Y¾Ì¼Å€]   d‡YY€«€]€Ë–]YÁ¶»Z¯ÊËÁ{Á{dy{€ZÀŸ½ZÌ»ÃÁÔ ] d‡Y¶»Z¯,€ady{€Å,{‹Ê»ÄnÌf¿©Â§¦Ë€ eY   ºÌÀ¯Ê»‘ŸÄËYMZ]Y¶»Z¯dy{ZËÁºÌÀ¯Ê»‘Ÿ¶»Z¯dy{Z]YÄËYM,|‹Z]ÉÁ€“€³YZźfË´·Y{€´Ë{cZ^ ]   1 A 2 B 3 C 4 D 5 E         Ó¼ » d‡Y 2k 1 ½M{€ÀŸ¶«Y|uÁ{Y{€ÀŸ 2 k 1 €j¯Y|udy{¾ËY,ºÌ‹Z]Äf‹Y{kª¼ŸÄ]¶»Z¯ÊËÁ{Á{dy{®Ë€³Y    ºÌÅ{Ê»½ZŒ¿nZ]Ydy{€ZÀŸ{Y| e n 2 k 1 n 1 2 k k log n 1 2 ,†°ŸÄ] d‡Ylog nYÊ ]Ze|ËMÊ»d‡|]log nYdy{¾ËYª¼Ÿ,|‹Z]ºÅ¶»Z¯įºÌ‹Z]Äf‹Y{ɀÀŸndy{®Ë€³Y ºfËÂ/´·YÉY€/]ºË€/Ì´]ºÌ¼/e|/ËZ]Ä/¯d/‡ZnÀËY |/ËMÊ»d‡|]log nª¼ŸZ]Êfy{½MÉÁY,|‹Z]Äf‹Y{€ÀŸnÉYÄËYM€³Y Z/]d/‡Y€]Y€]dy{ª¼Ÿ€ÀŸnZ]¶»Z¯dy{®Ë{Z»Yd‡Y log( n 1) €]Y€]dy{ª¼Ÿ€ÀŸnZ]€aÊËÁ{Á{dy{®Ë{   ÄËYM¶°‹Ä]Ydy{†°Ÿ€]ZËÁºÌÀ¯ÃZ´¿dy{¶°‹Ä]YÄËYM,½Z¼ËZÅ   log n 1 2 Heap   Ä/]ÓÂ/¼ »Ê^Ìe€eĘ]Y¾ËY,{Y{{ÂmÁÊ^Ìe€eĘ]Y®Ë‰€ZÀŸ½ZÌ»įd‡Y¶»Z¯ÊËÁ{Á{dy{®ËHeap   d‡Y€f³‚]€f°q¯Š¿Y|¿€§YČË,ŠËZÅdy{€ËY®Ë€ÅÁʸYdy{{ d‡Y€ËÉZŶ°‹  ÉZÅ{|/Ÿ |/ÀÀ¯Ê/»Ã{Z¨f/‡YHeapYĜ§ZudˀË|»ÉY€]¶»ZŸÉZźfˆÌ‡Ó¼ » d‡Y¶»ZŸÉZźfˆÌ‡{Heap{€]Z¯¾Ë€f¼Æ»   d‡YĜ§Zu¦¸fz»ÉZÅ­Ô]ÁY|¿YHeap¶yY{   d‡YÉ{€]Z¯Data structure®ËHeap   HeapÄ]•Â]€»ÉZźfË´·Y ‘Â/ŸY€/ZÀŸÉZmHeap{,|À¯Ê»¶Ë|^eHeapÄ]YÄËYMį,ºË‹Ê»ZÀ‹MÉYÃ{Z‡ÉZźfË´·YZ]Šz]¾ËY{   |À¯Ê»c‡YHeap®ËdËZÆ¿{ZËÁ|À¯Ê»  Make-HeapºfË´·Y  Procedure make-heap ( T [1 .. n] ) For i ( n div 2 ) down to 1 do Sift-down ( T , I ) End End sift-downºfË´·Y  Procedure sift-down ( T[1..n] , i ) K i Repeat jk if 2 j n and T[2j] > T[k] then k 2j if 2 j n and T[2j + 1] > T[k] then k 2j + 1 exchange ( T[j] and T[k]) until j = k end   |À¯Ê»¶Ë|^eHeapÄ]Yi ČËZ]Êfy{€Ë,Tdy{{sift-downºfË´·YÄf°¿    ºÌÀ¯Ê»ŠËZ»M€ËÄËYMZ]YMake-heapºfË´·Y 1 10 2 25 3 30 4 50 5 60 6 40 n i k j n i 6 3 3 3 6 3 Sift_down (T,3) 6 6 2 Sift_down (T,2) 2 2 1 Sift_down (T,1) 5 5 1 1 2 2 4 4 2 1       Heap-sortºfË´·Y  Procedure Heap-sort ( T[ 1 .. n] ) Make-heap( T ) For i n step-1 to 2 do Exchange ( T[1] and T[ i ] ) Sift-down ( T[ 1 .. i-1] , 1) End End   ©Â§ÉZźfË´·Y¶Ì¸ve Make heap ʧ€»½Z» = n/2 sift down ʧ€»½Z»   ºÌÀ¯Ê»Y|ÌaYZźfË´·Yʧ€»½Z»ʸ¯cÄ]Y|f]Y ºÌÅ{Ê»¹Zn¿YYZ¯¾ËY‰ÁÁ{Ä]  Sift down ʧ€»½Z» = ½MʸyY{Ĭ¸u‰{€³cZ §{{Y| e Ĭ¸u‰{€³cZ §{{Y| e = dy{ª¼Ÿ cZ/^ŸÄ/] d/‡Yª/¼Ÿ½Z/¼ÅZ/]€aÊËÁ{Á{dy{®ËZ]€]Y€]€ZÀŸ{Y| e€j¯Y|u,kª¼ŸÁ€ÀŸnZ]¶»Z¯ÊËÁ{Á{dy{®Ë{   d‡Y log (n+1)€j¯Y|u,dy{¾ËYª¼Ÿ€´Ë{ Make heap ʧ€»½Z» = n / 2 log n 1 2 O ( n log n) Ä/]Make-heapʧ€/»½Z/»½Â/q ºËÁ€/]sift-down¡Y€/‡Ä]|ËZ] ºÌÀ¯¾ÌÌ eYMake-heapʧ€»½Z»ºÌÅYÂyÊ»Y{|n»   ºÌÀ¯ʇ€]ɀfŒÌ]d«{Z]YÂ“»¾Ì¼ÅºÌÀ¯Ê»Ê ‡µZu   {‹Ê»¾ÌÌ en/2sift-downʧ€»½Z»c   d‡YcÁZ¨f»Ĭ¸u‰{€³cZ §{{Y| eÉ{ÁÁ€ÅÉY€]į{Z‡Ê»Repeat-untilĬ¸uYʧ€»½Z»sift-downºfË´·Y{   ºÌÀ¯Y|Ìa€Ë~aÄ^‡Zv»¦¬‡®ËnÉY€]ºÌÀ¯Ê»Ê ‡ |‹Z]Repeat-untilĬ¸u‰{€³cZ §{{Y| e€j¯Y|un,|ÌÀ¯‘€§ Ä/mÂeRepeat-untilÄ/¬¸uÄ/] |/ËMÊ/»d/‡|]Make-heapʧ€»½Z»,ºÌÀ¯Y|ÌaµÂ^«¶]Z«¦¬‡®Ë nÉY€]ºÌ¿YÂf]€³Y†a Ã|/‹Ä^/‡Zv»Ä/¬¸u¶^«ÉY€mY{įÉYk…Z‡Y€]|Ë|mj,Ĭ¸uÉY€mY€Å{ {Y{Ê´fˆ]kÁj€Ë{Z¬»Ä]Ĭ¸u¾ËYļeZy•€‹ |ÌÀ¯  Ä/¬¸u‰{€/³¾Ì/»Yt{j kÂf‡{ÉY€mYY†ajY|¬» j t |ÌÀ¯‘€§ ºÌÀ¯Ê»ÄmÂejY|¬»Ä]¾ËY€]ZÀ] |ËMÊ»d‡{Ä],d‡Y t = 1,2, … , m j1 i j 2 2 j1   |‹Z] 2 j 1 1 j3 2 j 2 2 j2 1 ZË Ä¬¸u¹Á{‰{€³ÉY|f]Y{ ZË Ä¬¸u¹Â‡‰{€³ÉY|f]Y{ cZ/ §{ÉY€/]Y€/ÌyYÄ/˜]Y d/‡Y i Y|/¬»½Z/¼Å j 1 ºÌ¿Y{Ê»Z»ʧ€—Y |y€qÊ»Z]n€j¯Y|uĬ¸u,ºËYÃ{€¯‘€§|ÌËZ¼¿ÄmÂe j t 2. j t 1 t = 2,3, … , m  ºËY{Ĭ¸uÉY€mY¦¸fz» n j m 2 j m 1 22. j m 2 2 m 1. j 1 n 2 m 1.i 2m 1 n / i m 1 log n / i  m¦¬‡Repeat-untilĬ¸u‰{€³cZ §{{Y| e€j¯Y|u m 1 logn / i Ä/] º/ËÁMd/‡|]Ê¿Z/»¦¬/‡Ê/À Ë º/ËÁMd/‡|]YÉ{|/ŸMake-heapºfËÂ/´·YÉY€],Ę]Y¾ËY…Z‡Y€]ºÌÀ¯Ê»Ê ‡µZu  Ze(n/2)-1É| ]Z],d‡Yn/2€]Y€]iZ]®Ë {‹Ê»Y€mYi¦¸fz»€Ë{Z¬»ÉYYÄ]½MĬ¸u |ÌÀ¯ÄmÂeMake-heapºfË´·Y ʧ€/»½Z/»\Ìe€e¾ËYÄ],|‹Z]Äf‹Y{YĬ¸u‰{€³cZ §{{Y| e¾Ë€fŒÌ]sift-downĬ¸u,ºËÁÊ»sift-down¡Y€‡Z]€Å{  {‹Ê»¦Ë€ e€ËĘ]YZ]Make-heap n / 2 1 logn / i i 1 ºÌÀ¯Ê»µZ^¿{©Â§Ä^‡Zv»dÆm{Yhv] n / 2 n / 2 1 logn / i n / 2 logn / i i 1 i 1 ¦·Y Z/e 2 k Y€ZÀŸ¹Yk+1t˜‡{,Ã|‹Äf¨³‰Áª]Z˜» {‹Ê»€ady{¾ËYd·Zu¾Ë€e|]{,|ˀ̴]€œ¿{Y¶»Z¯dy{®Ë   ¶»Z¯dy{¦Ë€ eYºÅ,ºÌÀ¯Ê»Ã{Z¨f‡YºfËZ´·¦Ë€ eYºÅœÀ»¾ËYÄ] ¶Ë|/^e€/ad/y{Ä/]Z/»d/y{Ä/¯d/·Zu¾Ë€e|/]{,ºÌˆË¿Ê»¹Yk+1t˜‡{Y¦·YĘ]Y |¿YÃ|‹ÉY~³ÃZ¼‹ 2 k 1 1 2 k 1 1 n n n log k log k 1 k 1 2 1 2   {‹Ê» A log n / i log 2 i2k Y|/ÌaŠËY‚/§YÊ/°ËÊ/°Ë 2 k YZÆ¿M€ˆ¯k€z»Z»Yd‡YnZÆ¿McįºË€Ì³Ê»ºfËZ´·ÉZÅ{|ŸY,{‹Ê»Ã|ÅZŒ»į˜¿Z¼Å Ä/̬]YÄ/¸¼m¾Ì/·ÁY©Â/§ÉZÅlog½ZÌ»\Ìe€e¾ËYÄ] |¿Â‹Ê»®q¯įºË€Ì³Ê»ºfËZ´·ÉZÅ{|ŸYÊÀ Ë  2 k 1 1 Ze|¿YÃ{€¯ n A 2 k . log k 2  d§€³ÄnÌf¿½YÂeÊ»¾ËY€]ZÀ],d‡Y€f³‚] ½Mt˜/‡€/Å{,|/ÌÀ¯‘€/§ |‹Z]Äf‹Y{Ydª¼Ÿ,ºËZˆÌ»įÊfy{,ºÌÀ¯Ê»‘€§Ä°ÀËYÊÀ Ë ºÌÅ|Ì»ºÌ¼ eYÂ“»¾ËYµZu [ n / 2 d n k  d§€³ºÌÅYÂyÄnÌf¿,ºË€Ì´]€œ¿{dy{¾ËY¶¯{Y¦·YĘ]Y€³Y\Ìe€e¾ËYÄ],|‹Z]Y€«€][Ę]Y logn / i i 1  k 2 . log 2 k 0  ºËY{dª¼ŸÉY€]€aÊËÁ{Á{dy{¦Ë€ eª^— ºÌÀ¯Y|ÌaY{ÊÀ »¦¬‡,Ę]Y¾ËYÉY€]ºÅZ]ºÌÀ¯Ê»Ê ‡µZu d logn / 2 d logn / 2 d 1 log n   ºÌËZ¼¿Ã{Z‡ºÌ¿YÂeÊ»YkĘ]Y,ºfËZ´·ÉZÅʳ„ËÁYÃ{Z¨f‡YZ]   d 1 logn / 8 |ˀ̴]ÄnÌf¿ d 1 log n Ę]YY¾Ë€¼e    |ÌËZ¼¿ħZ“YY-2©Â§Ę]Y¾Ì§€—Ä]ÊËZ¼ÀÅY d n 3.n k  |ˀ̴]ÄnÌf¿kĘ]YÁ¶^«¾Ë€¼eÄnÌf¿Y¾Ë€¼e k 2 . log 2 k 0   d‡Y n / 2 3.n €j¯Y|uMake-heapºfË´·Yʧ€»½Z»ºÌf§€³ÄnÌf¿€ÌyYÉZžˀ¼eY\Ìe€e¾ËYÄ]†a   |ÌÅ{t̓ÂeYkÁ[Ę]YÊf‡{¾Ë€¼e                  alter-heapºfË´·Y  €´Ë{ºfË´·Y|Àq   {Z‡Ê»ÃZ]Á{YheapÁ|Å{Ê»Y€«v€]Y€]YiÃZ¼‹Z]ɀÀŸY|¬»Tdy{{ºfË´·Y¾ËY Procedure alter-heap ( T[ 1..n ] , i , v) X T[ i ] T[ i ] v If v < x then sift-down ( T, i ) Else percolate ( T , i ) End  percolateºfË´·Y Procedure percolate ( T[ 1..n ] , i ) Ki Repeat Jk If j > 1 and T[ j div 2 ] < T[ k ] then k j div 2 Exchange T[ j ] and T[ k ] Until j = k End find-maxºfË´·Y Function find-max ( T[ 1..n ] ) Return T[1] insert-nodeºfË´·Y Procedure insert-node ( T[1..n] , v ) T[ n + 1 ] v Percolate ( T[ 1 .. n +1 ] , n + 1 ) End               ¶§ Asymptotic NotationsÊ^¿Zn»ÉZÅ{Z¼¿  {Y|/ eºË|/»MÊ/À Ë ºÌ‡€]ʬ̫{º«Á{|ŸÄ]ºÌfˆ¿YÂf¿ºfË´·Y®Ëʧ€»½Z»½{€¯Y|ÌaÉY€],Ã|‹Ã|ÅZŒ»į˜¿Z¼Å  ½Z/»,ºÌfˆ/¿Y{Ê/»Ä/¯ÊeÂ/{ ºË{€/¯Ã{Z¨f/‡Yʧ€/»½Z/»½YÂÀŸÄ]½MYÔ¼ŸÁºË{€¼‹YcYÂf‡{Y®Ë€ÅÉY€mYcZ §{   |À‹Z]Äf‹Y{½Zˆ°ËɀÅZ›€³YÊfu,d‡YcÁZ¨f»Zf Ì^—,€´Ë{Âf‡{ʧ€»½Z»Z]Âf‡{®Ëʧ€» |¿Â/‹Ê/»\^‡Ê^¿Zn»ÉZÅ{Z¼¿ d‡YÊ^¿Zn»ÉZÅ{Z¼¿YÃ{Z¨f‡Y,ºË€^]ÓZ]ZÅ{|ŸÂ¿¾ËYZ]Y½Z»Z¯d«{ºÌ¿YÂf]įÉZÅÃYYÊ°Ë ʧ€»½Z»ÉY€]€´Ë{cZ^ŸÄ] d‡YÁ{€ÅZËÁ¦¯Z˦¬‡ÄWYYZÅ{Z¼¿¾ËYZ¯ ºË‹Ê»ZÀ‹MșÁÁO{Z¼¿ćZ]Šz]¾ËY{   ºÌÀ¯¦Ë€ eYÁ{€ÅZ˦¬‡Z˦¯,cYZ^ŸÂ¿¾ËYÉY€]   ºÌÀ¯Ê»¦Ë€ eYÁ{€ÅZËÁY|¬»¶«Y|uZËY|¬»€j¯Y|u O{Z¼¿  \ˆ/u€/]ʘËY€/‹dveZÆ¿M¦¬‡įd‡YÊ ]YÂeğ¼n»O(f(n))YœÀ» |‹Z] N R * YÃYÂz·{Ê ]Zef|ÌÀ¯‘€§  €´Ë{cZ^ŸÄ] {‹Ê»¦Ë€ ef(n)  O f (n ) t : N c * n 0 n n 0 t (n ) c f (n )   * 0 Äf°¿    {Y{Y€« O n 2 ÃÁ€³{ t (n) 5n 9 ž]Ze|ÌÅ{½ZŒ¿µZj»  t ( n ) 5n 9 O n 2   d‡YY€«€]ŠËY€]©Â§–ËY€‹į{Y{{ÂmÁÉY n 0 ÁCºÌÅ{½ZŒ¿ÁºËÁž]Ze¦Ë€ e¡Y€‡|ËZ]œÀ»¾ËYÄ]  ¶u ºËY{¦Ë€ eª^— : 5n 9 c n 2 c n 2 5n 9 0 ÉYYÄ]ÓZ]Ę]YÉY€]µZj»½YÂÀŸÄ] {Y{¹Zn¿Y½YÂeÊ»Z˜yÁÊ ‡‰ÁZ]YZ¯¾ËY |‹Z]Y€«€]Ę]YZe|ÌÀ¯¾ÌÌ eY n 0 ÁC|ËZ]µZu   {€Ì³Ê»Y€« O(n 2 ) ÃÁ€³{ž]Ze¾ËY\Ìe€e¾ËYÄ]†a d‡YY€«€]Ę]Y c 5 Á n 0 5 Y¦¬/‡|‹Z]¾°¼»įÊËZmZe€´Ë{cZ^ŸÄ] |¿Â‹¦Ë€ eÊ «YÁ{Y{½Z°»YįÊËZmZeįd‡Y¾ËYZŦ¬‡{»{ºÆ»Äf°¿®Ë  .Ä¿ZËdˆÅ t (n) O(n) ZËMįºÌÀ¯ʇ€]ºÌÅYÂyÊ»µZu   ºËÁZÌ]¾ÌËZa (c * )(n 0 )(n n 0 ) 5n 9 c n   ºÌÀ¯Ê»Ã{Z¨f‡Y¦Ë€ eYºÅZ]œÀ»¾ËYÉY€] 5n 9 c n 5n c n 9 (5 c ) n 9 n 9 5 c   |»M¾ÌËZa¦¬‡Ád§€³Y€« O ( n ) ÃÁ€³{t(n)ž]Ze†a       {Y{(transitive)É| ed̏Zy " O " Ę]Y|ÌÅ{½ZŒ¿µZj» f (n ) O ( g (n )) g (n ) O (h (n )) ? f (n ) O (h (n ))   ¶u c n n n 2 g ( n ) c 2 h ( n )  ºÌÀ¯Ê»d]Zi 2 †a n 3 max(n1 , n 2 ) Á c 3 c1 c 2 f (n ) c1 g (n ) c1 c 2 h (n )  c3 c 3 ,c 3 c1 c 2 n 3 n n 3  |ÌÅ{½ZŒ¿  f , g : * •€‹Ä]ÃYÂz·{ž]ZeÁ{gÁf|ÌÀ¯‘€§µZj» O f (n ) O g (n ) iff f ( n ) O g ( n ) g ( n ) O f ( n ) Ê/À Ë|À/‹Z]ÉÁZˆ/»º/ÅZ]ğ¼n»Á{Êf«ÁY~·|¿Y{ÉYğ¼n»¦Ë€ eOÉZÅ{Z¼¿½Âq,|‹Z] O f (n ) O g (n ) |ÌÀ¯‘€§  ¶u 1)O f (n ) O g (n )   †° ¸]Ád‡Yɀ´Ë{ğ¼n»€ËÊ°Ë 2)O g (n ) O f (n )   {‹Ê»¦Ë€ eºÅg(n)Z]Š¨¬‡,{‹Ê»¦Ë€ ef(n)Z]Š¨¬‡įÊ ]Ze€Åįd‡Y½MÃ|ÀÅ{½ZŒ¿µÁYĘ]Y   {‹Ê»¦Ë€ eºÅf(n)Z]Š¨¬‡,{‹Ê»¦Ë€ eg(n)Z]Š¨¬‡įÊ ]Ze€Åįd‡Y½MÃ|ÀÅ{½ZŒ¿µÁYĘ]Y   d‡Yf(n){Âyž]YÂe¾ËYYÊ°Ë,{‹Ê»¦Ë€ eºÅg(n)Z]Š¨¬‡,{‹Ê»¦Ë€ ef(n)Z]Š¨¬‡įÊ ]Ze€ÅµÁYĘ]Yª^— f ( n ) O f ( n ) f ( n ) O g ( n )   d‡Yg(n){Âyž]YÂe¾ËYYÊ°Ë,{‹Ê»¦Ë€ eºÅf(n)Z]Š¨¬‡,{‹Ê»¦Ë€ eg(n)Z]Š¨¬‡įÊ ]Ze€Å¹Á{Ę]Yª^—   g ( n ) O g ( n ) g ( n ) O f ( n )    d‡YÊ Ì^—{Y|ŸYž]ZeÁ{€Å{€], g (n ) O f (n ) Á f (n ) O g (n ) İ˘]|Ì¿‚]µZj»gÁfž]ZeÁ{¾Ë€¼e f , g :  |ÌÅ{½ZŒ¿  f , g : |ÌÀ¯‘€§µZj» O f (n ) g (n ) O max f (n ), g (n )  ¶u 1) O f (n ) g ( n ) O max f (n ), g (n )   d‡Yɀ´Ë{ğ¼n»€Ë¹Y|¯€ÅºÌÅ{½ZŒ¿|ËZ]|ÀËÁZˆ»ºÅZ]ğ¼n»Á{ºÌÅ{½ZŒ¿Ä°ÀËYÉY€] : cZ^iY O f (n ) g (n ) t |: * c1 * n1 n n1 t (n ) c1 h (n ) g (n )  if h (n ) max f (n ), g (n ) n n1 t ( n ) c1 f ( n ) g ( n ) t ( n ) c1 h ( n ) g ( n ) t (n ) 2c1 h ( n ) c2 2) O max f (n ), g (n ) O f (n ) g (n ) O(max) = O( Äm{¾Ë€fŒÌ] )  ºË€Ì³Ê»ºÆ»ÄnÌf¿®Ëʳ„ËÁ¾ËYY      O 5n 3 10n 2 15n 25 O n 3 ZËMµZj»   |ÌÀ¯ÄmÂe€ËµZj»Ä] O 5n 3 10n 2 15n 25 O max 5n 3 10n 2 15n , 25  ¶u O 5n 10n 15n O max 5n 10n O 5n 10n O max 5n ,10n O 5n O n 3 2 3 3 2 3 3 2 ,15n 2 3   O g (n ) O f (n ) ÃZ´¿M,|‹Z]d^j»{|Ÿ®Ë lim n f (n ) ,|‹Z] f , g : |ÌÀ¯‘€§µZj» g (n )  µZj» f (n ) l g (n )  |u¦Ë€ e n 0 0 0 f (n ) l g (n ) n n 0 l g (n ) f (n l ) , f (n ) l g (n ) f (n ) l g (n ) g ( n )O f ( n ) l g (n ) f (n ) l g (n ) O f (n ) O g ( n ) f ( n )O g ( n ) {Z¼¿  c , n 0 º/Ŧ/ˀ e¾/ËY{ d/‡YÃ|/‹¦/ˀ ef(n)…Z/‡Y€]ZÆ¿M¦¯į|Å{Ê»½ZŒ¿YÊ ]YÂe¹Z¼eÂ¼n» f ( n )   f (n ) t : c * n 0 n n 0 t (n ) c f (n )  |¿Â‹Ê»¦Ë€ eį|ÀfˆÅÊÅYÂz·{€Ë{Z¬» f , g : *  {‹Ê»ÄnÌf¿©Â§¦Ë€ eYĸZ§Ô] f ( n ) O g (n ) iff g (n ) f (n ) c1 n1 n n1 f g (n ) 1 f (n ) c1 c2  ( n ) c1 g ( n ) ș{Z¼¿   {‹Ê»¦Ë€ ef(n)\ˆu€]ZÆ¿M¦¬‡ºÅÁZÆ¿M¦¯ºÅįÊ ]YÂeğ¼n» f (n ) t : * c1 , c 2 n 0 n n 0 c 2 f (n ) t (n ) c1 f (n )    d‡YY€«€] f ( n ) (n ) Ę]Y f (n ) 5n 5 ž]ZeÉY€]µZj»ÉY€]   d‡YY€«€] g (n ) (n 2 ) Ę]Y g (n ) 10n 2 5n 90 ž]ZeÉY€]¾ÌÀr¼Å  f (n ) l Á f , g : |ÌÀ¯‘€§µZj» g (n )    f ( n ) g (n ) |ÌÀ¯d]Zi lim n  ¶u f (n ) l g (n )  ºËY{|u¦Ë€ eYÃ{Z¨f‡YZ]ÁÊfuY€] 0 n 0 0 f (n ) l g (n ) n n 0 l f (n ) l g (n ) l g (n ) f (n ) l g (n ) f ( n ) g (n )   d§€³€œ¿{Y€ËcZ^Ÿ½YÂeÊ»șÉY€]ʸ¯—Ä] f (n ) O f (n ) f (n )   |¿Â‹Ê»¦Ë€ ef(n)Z]ZÆ¿M¦¬‡Áf(n)Z]ZÆ¿M¦¯į|ÀfˆÅÊ ]YÂe,|¿Â‹Ê»¦Ë€ ef(n)Z]ZÆ¿M¦¯Á¦¬‡įÊ ]YÂe¹Z¼e Constructive InductionÉZfyZ‡ÉY€¬‡Y  ž]ZeșZËÁO¶°Œ]ºÌË´]ÊÀ Ë,ºÌÅ|]½ZŒ¿Ê^¿Zn»{Z¼¿Z]Yž]Ze¾ËY|ÀÅYÂz]Z»Y|ÌÀ¯‘€§ |ˀ̴]€œ¿{Yf(n)ž]Ze    ºÌÀ¯Ê»Ã{Z¨f‡YÃ{Z‡ÃY®ËYœÀ»¾ËYÄ] d‡Y‘Á€¨» d‡Zm¾Ì¼ÅÁºÌÀ¯d]ZinY|¬»€ÅÉY€]|ËZ]Y½Z¼ËZŸ{Y¾ËY€]ZÀ] ÁÄËYM€ZÀŸ{Y| e,Ĭ¸u‰{€³cZ §{{Y| e|À¿Z»,|ÀfˆÅÊ Ì^— Â/¿YZ/Æ¿Mʸ/YÉZ/Å€/Ì̤f»Ä/¯ºËY{Z¯Á€‡Ê ]YÂeZ]Ó¼ »½Âq ºÌÀ¯d]ZiYZŸ{Y½MºÌÀ¯Ê»Ê ‡ÁºÌÀ¯Ê»s€˜»YÊËZŸ{Y   |ËMÊ»–‡ÁÄ]Y€¬f‡YÉZaį ÉÁYYY€¬f/‡Y‘€/§ÁºÌ/À¯Ã{Z¨f‡YY€¬f‡Yº°uZËY€¬f‡YÄnÌf¿½YÂÀŸÄ]½Z¼ËZŸ{YYÊÀ Ë {¼¿½ZÌ]µÁYÄ]€yMY|ËZ]YY€¬f‡Y¾ËYZ»Y ÉY|/f]YYºË€/̳Ê/»Ä/nÌf¿ºÅZ]ÁºÌÀ¯Ê»½ZÌ]YY€¬f‡YÉY|f]Y†b‡ ºÌ‡Ê»Y€¬f‡Yº°uÄ]Y€¬f‡Y‘€§YºË€Ì´]ÄnÌf¿ ºËZˆ]½M { º/ËYÄfyZ/‡µÁYÄ]€yMYY€¬f‡Y®Ë|‡Ê»€œ¿Ä]ºÌÅ{Y€«ºÅZÀ¯Y©Â§¶uY€»€³YµZu ºÌ‡€]ºÌ¿YÂeÊ»Y€¬f‡Y‘€§Ä]Y€¬f‡Y  {‹¦Ë€ eʳ{Z‡Ä]șZËZËO{Z¼¿ŠËY€]į|‹Z]Ê ]ZedˆÌ¿¹Â¸ »Y|f]Y½Z¼ÅYf(n)ž]Ze,|̋Z]Äf‹Y{ÄmÂe |‹Z]Y€«€]½Z¼ËZŸ{Y •€/‹½Md/veÄ/¯ºÌÀ¯Ê»Y|ÌaYʗ€‹ZË,{Y{ºÌÅYÂy€Ì̤eY½Z»{ÂyÄÌ·ÁYÉZŸ{Y{‹¶°Œ»Zq{½Z¼ËZÆeZ^iY€³YZ¯Yĸu€»€Å   {‹Ê»¦Ë€ ef(n)ž]ZeZfyZ‡…Z‡Y€]įÊËY€¬f‡YÊÀ Ë |ÀÅ{Ê»½ZŒ¿YÉZfyZ‡ÉY€¬f‡Y‰Á©Â§cÔ¼m   |‹Z]Ê»Z˜yÁÊ ‡€]ÊÀ^»©Â§‰Ád Ì^—€´Ë{cZ^ŸÄ]       |ÌÅ{½ZŒ¿Ê^¿Zn»{Z¼¿Z]Y€¿M,|ˀ̴]€œ¿{€Ë¶°Œ]Yfž]ZeµZj» f : n 0 0 f (n ) n f (n 1) O. W ¹|/«{ÁºÌ¿‚/]…|/uYÉ{Z¼¿ž]Zeʇ€]Z]ºÌÀ¯Ê»Ê ‡ șZËZ˺ÌÀ¯Ã{Z¨f‡YO{Z¼¿YºÌ¿Y{ʼ¿,ºÌÀ¯Ê»ÃZ´¿ĸXˆ»cÄ]  ¶u Č/̼Ådˆ/Ì¿¹Â¸ »Z»Y|ËMÊ»d‡{Ä]ʳ{Z‡Ä]½Z»{ÂyÄÌ·ÁY…|ucZ«ÁYÊÅZ³ ºÌËZ¼¿d]Zi©Â§Äf‹Â¿[ÂqZq{Y½Z¼ËZŸ{Y| ] f ( n ) O (?)   |‹Z]˜ÀËY f ( n ) (?) f ( n ) (?) f ( n ) n f (n 1) n (n 1) f (n 1) n (n 1) (n 2) f (n 3) f (n ) O n 2  ºÌÀ¯Ê»ZŸ{Y ºÌÀ¯Ê»½ZÌ]€f¬Ì«{Y½Z¼ËZŸ{YºÌ‡ZÀ‹Ê»Yž]Ze½Âq d‡Y O n 2 ¶°‹Ä]f(n)ºÌÀ¯Ê»ZŸ{Y f ( n ) an 2 bn c ©Â/§ÉZ/Ÿ{YÄ/] d/‡YY€/«€]½Z/¼ËZŸ{Yn€/ÅÉYYÄ/]ºÌ/À¯d/]Zi|/ËZ] {Â/‹Ê/»½Z/Ì]Y€¬/‡Y€/yMZ/ËY€¬‡Yº°u½YÂÀŸÄ]Z»ÉZŸ{Y¾ËY HI(n)Y€/¿M,{Y{Ê´fˆ/]nÄ/]½Â/qÁºÌ/Å{Ê/»½ZŒ/¿HIZ/]Y€/¿MÄ/¯|À˳Partially Specified Induction Hypothesis   |‹Z]Y€«€]nYɀË{Z¬»ÉY€]|ËZ‹įºËYÃ{€¯s€˜»YÉZŸ{Y,d‡YÃ|Œ¿d]ZiÊËY€¬f‡YÂÀÅį|¿Z‡Ê»YÂ“»¾ËYcZ^Ÿ¾ËY   ºÌ˳Ê»   ºËZ‡Ê»HI(n)ÉÁYY€¿M ºËÁÊ»HI(n-1)¡Y€‡ d‡YY€«€]nYY|¬»€ÅÉY€]½Z¼ËZŸ{YºÌÅ{½ZŒ¿|ËZ] HI (n ) : f (n ) an 2 bn c HI (n 1) : f (n 1) a (n 1) 2 b ( n 1) c ÉY€/]|/ÌËZ¼¿Ä/mÂe ºÌ/‡€]ºÌ¿YÂ/eÊ»ĸXˆ»–ËY€‹dveY€¬f‡Yº°uÊÀ ËHI(n)Ä]Y€¬‡Y‘€§ÊÀ Ë,HI(n-1)YºÌÅ{Ê»½ZŒ¿µZu   ºËÁMd‡|]YÉZÅdË{Á|v»ŠËY€]ZËÁºÌÀ¯¾ÌÌ eYa,b,c|ËZ]ZË|‹Z]Y€«€]HI(n)Ä°¿M   ºÌ‡Ê»HI(n)Ä]ĸXˆ»–ËY€‹dveºÌÀ¯d]ZiºÌÅYÂyÊ» |‹Z]Y€«€]HI(n-1)ºÌÀ¯Ê»‘€§ f (n ) n f ( n 1) n a (n 1) 2 b ( n 1) c an 2 n (1 2a b ) (a b c ) an 2 bn c ,|/‹Z] an 2 bn c ÉÁZˆ/»€/ÌyYÄ/˜]YÊ/À Ë ºÌ/Å{Y€/«Y an 2 bn c ºÌ¿YÂ/f]f(n)ÉZ/m|/ËZ]|‹Z]Y€«€]HI(n)Ä°¿MÉY€] ÉÁZˆ/ecÔ/¼mZ/ËÁºË€/Ì´]YºÅ,ºÅZ]Y©Â§ÉÁZˆe¾Ì§€—ºÌ¿YÂeÊ»ZÆ¿M½{€¯Y|ÌaÉY€] d‡Ya,b,c½Z¼eÓÂÆn»ºÌÀ°¿‰Â»Y€§ 1 2a b b a 1 / 2 a b c c a b a b 1 / 2   ºÌÅ{Y€«€¨Z]|vf»Y\ËY€“¹Z¼eÁºÌÀ¯ɀ̳Âf¯Z§ºËÁZÌ]¥€—®ËÄ]Y©Â§   ºÌ‡Ê»HI(n)Ä]HI(n-1)Y,|À‹Z]1/2€]Y€]a,b€³YºË{Y{½ZŒ¿\Ìe€e¾ËYÄ]†a f (n ) 12 1 n n c 2 2 ¾/ËY|/ËZ]½Âq d‡YF(0)=cºË{ÁMd‡|]µZuÄ]ZeÄr¿Mª^—€´Ë{¥€—Y d‡YF(0)=0ĸXˆ»cª^— ºËÁÊ»•€‹¡Y€‡   |‹Z]|ËZ]€Ë¶°Œ]įd‡YÊ ]Zef(n)[Zˆu¾ËYZ]Á|‹c=0\Ìe€e¾ËYÄ]†a|À‹Z]ÉÁZˆ»Y|¬»Á{ f (n ) 12 1 n n 2 2 c2 n 2 12 1 n n c1 n 2 2 2      |ÌÅ{½ZŒ¿Ê^¿Zn»{Z¼¿YÃ{Z¨f‡YZ]Ytž]ZeµZj» t : n 1 a t (n ) 2 b n n t (n 1) OW . a,b t (n ) b n 2 n t (n 1)  ¶u b n 2 n b (n 1)2 ( n 1) t (n 2) b n 2 b n ( n 1) 2 n ( n 1) t (n 2) b n 2 b n ( n 1) 2 n ( n 1) b ( n 2) 2 (n 2) t ( n 3) b n 2 b n ( n 1) 2 b n (n 1) (n 2) 2 n (n 1) ( n 2) t (n 3)   ºÌÀ¯d]ZinY|¬»€ÅÉY€]|ËZ]YÂ“»¾ËY {Y{n!¦¯t(n)ž]Ze{‹Ê»ÄnÌf¿ d‡Y€f³‚]Z¼fun!Yt(n)ž]Ze HI (n ) : t (n ) (n !) HI (n ) : u t (n ) u n !   ºÌÀ¯Ê»½ZÌ]€eÃ{Z‡c]Y©Â§ÉZŸ{Y  ºË€Ì³Ê»€œ¿{€Ëc]YHI(n-1),©Â§HI(n)ÉÁY  HI (n 1) : u t (n 1) u ( n 1)!   d‡YY€«€]ºÅHI(n),|‹Z]Y€«€]HI(n-1)€³YÊÀ Ë ºÌ‡Ê»HI(n)Ä]HI(n-1)YĸXˆ»–ËY€‹dveºÌÀ¯Ê»d]Zi t (n ) bn 2 nt (n 1) bn 2 n u (n 1)! bn 2 un ! un !  ºË{€/°¿Y|/Ìaʗ€/‹º/ÅuÉY€/] ºË|̇HI(n)Ä]HI(n-1)Y†a,d‡Y€f³‚] (u n !) Y©Â§cZ^Ÿ{‹Ê»ÃZ‹Yį˜¿Z¼Å   ºÌ‡Ê»HI(n)Ä]HI(n-1)YuY|¬»€ÅÉY€]ÊÀ Ë {‹Ê»ÄnÌf¿Ę]YÁ{¾ËYY d‡Y t (1) u 1! ©Â§ÉZŸ{Yª^— d‡Yt(1)=aĸXˆ»cª^— ºËÁÊ»Y€¬f‡YÉY|f]Y¡Y€‡µZu   a u   d‡Yd]ZiZ»ÉZŸ{Y|‹Z]Äq€Åu,ºË€Ì´]€œ¿{aÉÁZˆ»ZË€f°q¯Yud‡YʧZ¯¾ËY€]ZÀ] d‡YÃ{Y{Z»Ä]ĸXˆ»cYa   ºÌËZ¼¿s€˜»ɀfÆ]¶°Œ]Y…|uºÌÀ¯Ê»Ê ‡ ºÌÀ¯Ê»s€˜»Yʇ|ut(n)¶°‹Ä]ÄmÂeZ] ºËÁÊ»ž]Ze¾ËY¦¬‡¡Y€‡µZu HI (n ) : t (n ) O (n !) HI (n ) : v t (n ) v n !   ºÌÀ¯Ê»½ZÌ]€Ë€eÃ{Z‡¶°Œ]Y©Â§ÉZŸ{Y   ºÌÀ¯Ê»¦Ë€ e€Ë¶°Œ]YHI(n-1),©Â§HIÉÁY HI (n 1) : v t (n 1) v ( n 1)!   ºÌ‡Ê»HI(n)Ä]HI(n-1)YĸXˆ»–ËY€‹dveºÌÅ{Ê»½ZŒ¿ t (n ) bn 2 nt (n 1) bn 2 n v (n 1)! v n ! HI(n)Ä/]HI(n-1)YÄ/°¿Md/¸Ÿ ºÌ/À¯tÌv/eY½Z/¼ËZŸ{Y|/ËZ]µZ/u ºË€/Ì´]Y©Â§ÄnÌf¿ºÌ¿YÂeʼ¿†ad‡Yd^j» bn 2 ½Âq  ºÌ/À¯Ê»ħZ“YʨÀ»ĸ¼m®Ë½Z¼ËZŸ{YÄ]œÀ»¾ËYÄ]ºË€^]¾Ì]YYĸ¼m¾ËYºÌÀ¯Ê»Ê ‡ d‡Y bn 2 ĸ¼m{ÂmÁ,ºÌ‡€]ºÌfˆ¿YÂf¿ HI (n ) : t (n ) v n ! w n ,w 0   |‹|ÅYÂy€Ëc]Z»ÉZŸ{Y|Ë|m¶°‹  ºËÁÊ»HI(n-1)¡Y€‡Y{|n» HI (n 1) : t (n 1) v (n 1)! w ( n 1)     {‹Ê»Y€«€]ºÅHI(n),|‹Z]Y€«€]HI(n-1)€³YºÌÅ{½ZŒ¿|ËZ] t (n ) bn 2 n t (n 1) bn 2 n v (n 1)! w (n 1) {ÁÃ{€¯Ä^e€»Ä]¶Ë|^eY€¿MHI(n-1){½{Y{Y€«Z]Ê·Á{Â]Ä^e€»YįºË{€¯ħZ“YYʨÀ»wnĸ¼m, bn 2 ½{€¯¥~uÉY€]   ºË{€¯º¯ bn 2 Y bn 2 v n ! wn (n 1) v n ! n bn w (n 1) v n ! n n (b w ) w t (n ) v n ! wn  ºÌ‹Z]Äf‹Y{d‡YʧZ¯,|ËZÌ]{€Ë¶°Œ]€ÌyYĘ]YÄ°¿MÉY€] (b w )n w w bn wn w w w bn n 3 n 3 w 3b n 2   d‡YµÂ^«{»n,wY|¬»€ÅÉY€]w 3b €³Y†a,ºËYÃ{ÁMd‡|]YwY|¬»|‡Ê»€œ¿Ä] Ê/À Ë d/‡Y n 3 ,w½{€/¯Y|/ÌaÉY€]į|ÌÀ¯ÄmÂeÄf°¿¾ËYÄ]ÃÁÔ ] ºËÁMd‡|]YvºÌÀ¯Ê»Ê ‡ ºÌÀ¯Ê»[Zzf¿Y w 3b   dˆÌ¿Y€«€]©Â§w,n=2Án=1ÉY€]  ©Â§‘€§ª^—,ºËÁÊ»t¡Y€‡ n 1 t (1) a A A , B a v 3b t (1) v 1! 3b B v a 3b t (2) 4b 2t (1) 4b 2a 4b 2a 2v 6b v a 5b t (2) v 2! 6b ¾ËYÄ] d‡YY€«€]ºÅn=2Án=1ÉY€]HI(n),ºË€Ì´]€œ¿{ a 5b ÉÁZˆ»Á€f³‚]Yv€³Y,bÁa€Ë{Z¬»½{Â]d^j»Ä]ÄmÂeZ] t (n ) (a 5b ) n ! 3b n  ºË{€¯d]Zi\Ìe€e   |‹Y|Ìa‚Ì¿ž]Ze¾ËY¦¬‡\Ìe€e¾ËYÄ] d‡|]YºfË´·Y¾ËYʧ€»½Z» |ÌËZ¼¿¾ÌÌ eYº¼Ì¿Ê»Áº¼Ë‚¯Z»€ZÀŸ,ɀÀŸnÄËYM®Ë{į|ÌÀ¯ÊuY€—ʼfË´·YµZj»   1) Procedure Smaxmin( A,n,max,min ) 2) Max,min A(1) 3) For i 2 to n do 4) If A(i) > max 5) Then max A(i) 6) If A(i) < min 7) Then min A(i) 8) End 9) End   |ÌËZ¼¿ʇ€]Y{ÂyºfË´·Yʧ€»½Z»,Ä]ZŒ»ÉZźfË´·YZ]ĈËZ¬»{ |ËÁM     |‹ʧ€ »®Ë¶§{ºfË´·Y¾ËY   ÃZ¼‹  cZ §{{Y| e  ¶¼ ·YÂf‡{ Y€°e            n n-1 €j¯Y|un-1 n-1 €j¯Y|u n-1 n-1  ŽyZ//‹Â//¼n» ʧ€»½Z»  įc¾ËYÄ]{‹µZ¼ŸYÊeY€Ì̤e|ËZ]7Ze–y{į|‡Ê»€œ¿Ä]  4) 5) 6) 7) If A(i) > max Then max A(i) else If A(i) < min Then min A(i)   d‡|]YºfË´·YÁ{¾ËYʧ€»Ĝ§ZuY|¬»Áʧ€»½Z»|ËZ]µZu ºË{ÁMd‡|]ĸXˆ»c®ËÉY€]¶uÃYÁ{Z¯ÉZnÀËYZe ÁcYÂf/‡{œÀ» {‹Ê»¶°Œ»Zq{©Â§Ã{Z‡ºfË´·Y{»{{|Ÿ¾ËY½{€¯Y|Ìa†a d‡Yʧ€»½Z»ŽyZ‹ (n )   ºËÁM   ºÌÀ¯Ê»Ã{Z‡YÄ»Z¿€]ºÌËMÊ»†a,ºË{€¯Ä ·Z˜»YÊ^¿Zn»ÉZÅ{Z¼¿€´Ë{ʧ€—Y d‡Y ¹Z/¼eÉY€/mYcZ/ §{{Y|/ eºfËÂ/´·Y¶¯ÉÁ€]Ä°¿MÉZmÄ] ºÌÀ¯Ê»[Zzf¿YŽyZ‹cYÂf‡{½YÂÀŸÄ]YÊeYÂf‡{ºfË´·Y€Å{   ºÌÅ{Ê»¹Zn¿YŽyZ‹cYÂf‡{ÉY€]YZ¯¾ËY,ºÌÀ¯[ZˆuYºfË´·YcYÂf‡{   d‡Y¾f§€³€œ¿{¶]Z«ºfË´·YYʌz]ÉY€mYÃ|ÀËZ¼¿½YÂÀŸÄ]½MÉY€mYįd‡YÉÂf‡{ŽyZ‹Âf‡{   ºÌÀ¯Ê»[Zzf¿YBarometerŽyZ‹Âf‡{½YÂÀŸÄ]Y€ZÀŸ¾Ì]ĈËZ¬»,©Â§cZv̓ÂeZ]   |ÀfˆÅÊ]ÂyŽyZ‹cYÂf‡{ʗ€‹cYÂf‡{Ó¼ » T1 (n ) 2( n 1)  µÁYºfË´·Yʧ€»½Z» 1(n 1) T 2 (n ) 2(n 1)  ¹Á{ºfË´·Yʧ€»½Z»Á   |‹Z]Ê»d·Zu¾Ë€e|]{ 2(n 1) Ád·Zu¾Ë€fÆ]ÉY€] 1(n 1) į   |ÀfˆÅO(n)ÃÁ€³{Á{€Åį{‹Ê»Ã|ÅZŒ»†a €/̳ÁY|¿Y…Z̬»€³Y†a |¿Y{Y€«O(n)ÃÁ€³{Á{€ÅZ»Y,|¿Y{É{ZˁcÁZ¨eʧ€»½Z»€œ¿YÊ»Á{ÁÊ·ÁYºfË´·Yį¾ËYZ]   |ÀfˆÅ½Zˆ°Ëʧ€»½Z»€œ¿YÁ{¾ËY,|‹Z]O½ZÌ]  Procedure Rmaxmin (i,j ,fmax ,fmin ) Case: :i=j: fmax,fminA(i) :i=j-1: if A(i)<A(j) Then[ fmax A(j), fmin A(i) ] Else[ fmax A(i), fmin A(j) ] :else: mid [ (i+j )/2 ] Rmaxmin (i , mid , gmax, gmin ) Rmaxmin ( mid +1 , j , hmax , hmin) Fmax max (gmax , hmax) Fmin min( gmin,hmin ) End End    {€¯}ZzeYBarometerY€Ì£ɀ´Ë{‰Á|ËZ]ºfË´·Y¾ËY{»{|‡Ê»€œ¿Ä]†a  ÄËYM |À¯Ê»¾ÌÌ eYminÁmax€ZÀŸjZei†Ë|¿YY,AÄËYM{ºfË´·Y¾ËY ºÌÀ¯Ê»Á€»YÊfŒ³Z]ºfË´·Y¾ËYZ¯Y|f]Y   d‡YºfË´·Y¾ËYglobalį,d‡YnZeYA   nYjÁºÌÅ{Ê»YiÊ¿YÂyZ]¾Ì·ÁY{ 1 10 2 15 3 9 4 25 5 7 6 16 A   \/Ìe€eÁZ/Åpage¾Ì]|»MÁd§ |̈ËÂÀ]cZÌW‚m€¯}Z]¶»Z¯—Ä]YZÅPage |ÌËZ¼¿µZ^¿{d‡{Z]Y©Â§ºfË´·YÉY€mY¾Ë€¼e    |Ë‹ÄmÂf»Ê]ÂyÄ]YZÅÊ¿YÂyZ] ÊËZ/Åd·Zu¾ÌÀq{ {‹Ê»Ê¿Ó—Z̈]Z¯É{Y»{Z»Y d‡Y\‡ZÀ»Z̈]cZÌW‚m½ZÌ]€œ¿YZÅpage¾fyZ‡Ó¼ » ÊfŒ³Z]Ê¿YÂyZ]dy{ ÉY€/] {Â/‹Ê/»¾Ë‚´ËZmdy{€ÀŸ®ËZ] page€Ådy{¾ËY{ |ËMÊ»Z¯Ä]dy{®Ë[ÂqZq{ZÅpage€eÃ{Z‡¶°‹   {Â]|ÅYÂy€Ë¶°‹Ä]ÓZ]µZj»ÉY€]dy{Â¿¾ËYµZj»     |ËYÃ|‹ÄmÂf»YZ¯¶uY€»|Ë‹¾X¼˜» |ˁZˆ]Y{|n»Y©Â§dy{¾Ë€¼e ÊfŒ³Z]ÉZźfË´·Yʧ€»½Z»¾ÌÌ e ÉZ/ŵÂ/»€§YÃ{Z¨f/‡YZ]ºÌÀ¯Ê»Ê ‡†b‡,ºË‹ÄmÂf»YºfË´·Y¹Âƨ»ºÌÀ¯Ê»Ê ‡Y|f]YÊfŒ³Z]ÉZźfË´·YÉY€]  ŠËY‚/§YZ/ËŠÅZ/¯ʧ€/»½Z/»{Â/‹{Z/ˁZ˺¯n {Y{Ê´fˆ]ÄËYM€ZÀŸ{Y| enÄ]ºfË´·Yʧ€»½Z»ºfË´·Y¹Âƨ»ª^—   |ËZ¼¿Ê»Y¹Ó®¼¯Z»Ä]ºfË´·Y¹Âƨ»Ó¼ » ºÌÀ¯½ZÌ]YºfË´·Y¹Âƨ»ʓZË T(n)ÉY€]ºÌÀ¯Ê»Ê ‡ {Y{€ÀŸnÉ{ÁÁÄËYMį|‹Z]Êf·ZuÉY€]ºfË´·Yʧ€»½Z»T(n)ºÌÀ¯Ê»‘€§¾ËY€]ZÀ] |]ZËÊ»   |À¯Ê»®¼¯Z»Ä]ZźfË´·YcaseZfyZ‡É{Y»¾ÌÀq{ ºÌˆËÂÀ]\‡ZÀ»¦ËZ eºfË´·Y¶°‹Ä]ÄmÂeZ] 0 n 1 T ( n ) 1 n 2 T n / 2 T n / 2 2  ºËY|¿ɀ´Ë{ÃY|‡Ê»€œ¿Ä] ºÌÀ¯Ê»‰Z¼‹YŽyZ‹cYÂf‡{ÉY€mY{Y| ed·Zu€Å{|ÌÀ¯‘€§ OW .   d‡YÃ|‹Y€mYZ]|ÀqBarometerÂf‡{|ÀÅ{Ê»½ZŒ¿ÊÀ Ë |À˳Recurrence Functionž]YÂeĿ´ÀËYÄ] ¶]Z«ʸ^«T 2 ÁT1 ž]YÂeZ]ž]Ze¾ËYįd‡Y½M|¿Z»Ê»įɂÌqZ»Y ºË{ÁMd‡{Ä]‚Ì¿YÊfŒ³Z]ºfË´·Yʧ€»½Z»\Ìe€e¾ËYÄ] ¶/uÉY€/] ºÌÀ¯¶u|ËZ]YÊfŒ³Z]Ä·{Z »®ËÊÀ Ë {¼¿s€˜»Y¶u|ÀËM€§|ËZ]ÊfŒ³Z]ž]YÂe¾ËYÉY€]¶Ì·{¾^¼ÅÄ] dˆÌ¿ĈËZ¬»   ʓZËÔ»Z¯ÉZʼnÁZe{¼¿Á€‹½YÂeÊ»Ã{Z‡‰Á®ËY Ä/¯ºËY~³Ê»YÉY€«Ä·{Z »¶°‹½{€¯Ã{Z‡ÉY€] ºÌÀ¯Ê»¶uYÄ·{Z »†b‡ÁºÌÀ¯Ê»Ã{Z‡YÄ·{Z »¶°‹Z¯ÉY|f]Y{Ó¼ » n 1 0 T ( n ) 1 n 2 2 T (n / 2) 2 O. W   |À¯Ê»Ã{Z‡YZ»Z¯¦¬‡Á¦¯ž]YÂe¥~uµZj»¾ËY{ {‹Ã{Z‡Ä·{Z »¶°‹Y€«½MZ]   ºÌÀ¯Ê»Ã{Z¨f‡YReplacementÉY~´ËZm‰ÁY¶uÉY€]   {‹Ã{Z‡Ä·{Z »¶°‹‘€§½MZ]įºÌÀ¯Ê»s€˜»ʓ€§ T ( n ) 2 T (n / 2) 2 T ( n ) 22 T ( n / 4) (2 22 ) 22 2 T ( n / 8) 2 (2 22 ) 23 T ( n / 8) (2 22 23 ) n 2k 1 T k 1 (2 22 23 2k 1 ) 2 2k 1 T (2) (2 22 23 2k 1 ) n (2 22 23 2 k 1 ) 2 k 2 2 k 1 1 n n 2 2i 2 2 2 i 0 2 1 3n n n n 2 1 n 2 2 2 2 2 2 YT(n)|/ËZ]Y|f]Y¾ËY€]ZÀ] |ÀfˆÅintegerºÅÄËYM€ZÀŸÄ°ÀËY½MÁ |Ë|m‘€§®ËZ]ºÌÀ¯Y€°eY©Â§cZ̸¼ŸºÌÅYÂyÊ»Y{|n»   ºÌÀ¯[Zzf¿Y€f¼¯ʧ€»½Z»Z]ʼfË´·Y,\‡ZÀ»d«{Z]©Â§ÉZźfË´·Y½ZÌ»ºÌ¿YÂeÊ»\Ìe€e¾ËYÄ]   ºË€Ì´]€œ¿{Y€¿M|ËZ]T(n)¦Ë€ e{į,d‡ZÅjÁiĈËZ¬»|À¿Z»€ZÀŸĈËZ¬»,Êf·Zu¾ÌÀq{   ºÌÀ¯Y€°eY©Â§Ä]ZŒ»¶u†b‡ÁºÌˆËÂÀ]Y{|n»  1 n 1 T ( n ) 3 n 2 T n / 2 T n / 2 4 OW .   |ËZ¼¿Ê»¦Ë€ e€Ë•€‹Ä],؇Y®Ë…Z‡Y€]YZÌ¿{€¼ŸÊ»ZÀfËÁʼË|«½Zf‡Y{®ËµZj» Ä/] ¾ÌËZ/a{±‚/]À/Æ»ÁÓZ/]{®/q¯Àƻįc¾ËYÄ]{Y{{ÂmÁÀƻµÁYĸ̻ÉÁ,{Y{{ÂmÁ½ZŒ¿…Z¼·Yĸ̻Á{   {€Ì´¿Y€«€f°q¯ÉÁ€f³‚]Ĭ¸uÃZ³pÌÅįÉ—Ä],ºÌÀ°Ì»¶¬fÀ»¹Á{Ä]µÁYĸ̻YYZÅÀƻ¹Â‡Ê°¼¯ĸ̻®¼¯   |‹Z]Ê»µZ‡½Â̸̻ZÌ¿{€¼Ÿ½Zf‡Y{¾ËY…Z‡Y€] Procedure Hanoi(m,I,j) If m > 0 Then [Hanoi (m-1,I,6-i-j) Write (i→j) Hanoi(m-1,6-i-j,j) End   |Å{¹Zn¿YYZ¯¾ËYį|̈ËÂÀ]ÉYÄ»Z¿€] ʳ{Z‡ÉY€] ºËYÃ{€¯Y|Hanoi(64,1,2)Z]YºfË´·Y¾ËYÊ¿YÂyZ]¾Ì·ÁY{ |À¯Ê»¶¬fÀ»jÄ]i½Âf‡YYÀƻmºfË´·Y¾ËY   ºÌÀ¯Ê»µZ^¿{€Ës€Œ]YºfË´·YZ¯‰{€³,|ˀ̴]€œ¿{Ym,Z¯ H H H m 3 m 2 H (3,1, 2) i 1 i 1 j 2 j 3 H (2,1,3) H (1,1, 2) H m 1 m 0 i 1 i 1 j 2 H (0,1,3) 1 2 j 3 H (0,3, 2)   |ËYÄf§€³{ZËYZÅpage½ZÌ»|»MÁd§|Ë‹¾X¼˜» |ÌÀ¯¶»Z¯cZÌW‚m€¯}Z]Y©Â§µZj»ÉZ¯¶uY€»¾Ë€¼e    ºÌÀ¯Ê»Ã{Z¨f‡YÊ°¼¯½Âf‡ÃZ¼‹½{€¯Y|ÌaÉY€]6-i-jµÂ»€§YÄf°¿   YZ/ÅÀ/Æ»ÉZ/mÄ/]Zm ºÌ/Å{Ê»½ZŒ¿ÄqZ]YZÅk€]µZj»¾ËY{Z“€§ d‡YɁZ‡µ|»ʈË¿Ä»Z¿€]{ZÅZ¯¾Ë€f¼Æ»YÊ°ËÄf°¿   d‡YĿ´qºfË´·YÉZ¯ª˜À»ʸ¯˜]ÁºÌÀ¯Ê»¾ÌÌ eĿ´qYZŽÂf‡,ºÌÅ{Ê»¹Zn¿YĿ´q Ã|‹ÄmÄ]ZmÀƻ®Ë,|f§ZÌ]©Z¨eYwriteÃZ³€Å d‡YÃ|‹ɁZ‡ÄÌ^‹writeÂf‡{–‡ÂeZÅÀƻÊËZmÄ]ZmºfË´·Y¾ËY{Äf°¿    |Å{Ê»½ZŒ¿Ê]ÂyÄ]YÊfŒ³Z]ÉZźfË´·YÊËZ¿YÂyºfË´·Y¾ËY {Y{{ÂmÁwrite®Ëpage€Å{|ÌËZ¼¿ÄmÂe d‡Y ʧ€»½Z»¾ÌÌ e Y€/mYºfËÂ/´·YYʌ/z]Ä/¯|Å{Ê»½ZŒ¿½MÉY€mYįd‡YÉÂf‡{BarometerÂf‡{ ºËÁÊ»ºfË´·Y¶Ì¸veÁBarometer [Z/zf¿Y¡Y€/‡¾ËY€]Z/À] ºÌ/‡Ê/¼¿Ä/nÌf¿Ä/]cYÂf/‡{ÉY~/³ÃZ¼/‹ÃYY ºÌ/À¯ŽzŒ/»Y½Z/»¾Ì/Ì e‰Á|/ËZ]Y|/f]Y / / / / / / / / / /   ,page®/ËÉY€/mYÃ|/ÀËZ¼¿{¼¿‘€§½YÂeÊ»¾ËY€]ZÀ],{‹Ê»Y€mYwriteÂf‡{Z^°Ëpage€Å{,©Â§ºfË´·Y{ d‡YÃ|‹   ºË€Ì³Ê»€œ¿{writeÂf‡{½Z¼ÅYBaromete†a d‡YwriteÂf‡{ {Â/‹º¯ZË{Zˁm€³Y {Y{Ê´fˆ]ZÅÀƻ{Y| eÊÀ ËmÄ]{‹Ê»ÄfyZ‡įÉZÅpage{Y| e |ÌÀ¯ÄmÂeºfË´·YÊfŒ³Z]¶°‹Ä]   ºËY{Àƻmįd‡YÊf·ZuÉY€]ºfË´·Yʧ€»½Z»T(m){‹‘€§|¿YÂeÊ»†a {‹Ê»º¯ZË{ZˁºÅZÅpage{Y| e ºÌ¿YÂ/eÊ/»ŠËY€/] {Â/‹Ê/»ÊfŒ/³Z]º/ÅT(m)†ad‡YÊfŒ³Z]ºfË´·Y½Âq ºËÁ€Ì»ºfË´·Y¶°‹¡Y€‡T(m)¦Ë€ eÉY€] 2 T (m 1) 1 T (m ) 1 m 1   ºË€Ì´]ÄnÌf¿ºfË´·YÉÁYY€Ë¦Ë€ e m 1   {‹Ê»½ZÌ],d‡YRecurrence Function®Ëį©Â§ž]Ze…Z‡Y€]ºfË´·Yʧ€»½Z»    d‡YÃ{Zf§Y©Z¨eYZ]|ÀqBarometerÂf‡{|ÀÅ{Ê»½ZŒ¿ž]YÂeÂ¿¾ËY  ŠeZ^‡Zv»,|‹Z]Äf‹Y|¿ÄÌ·ÁYY|¬»ÊfŒ³Z]ž]Ze€³YºÌ¿Y{Ê»Z»Y,ºÌÀ¯ʼ¿Ã|ÅZŒ»YÄÌ·ÁY•€‹,ž]YÂe¦Ë€ e{cZ«ÁYÊÅZ³Äf°¿ Ä/Ì·ÁY€Ë{Z¬»ÉY€]YºfË´·Yįd‡Y½MÃ{Z‡ÃY®Ë ºÌÀ¯œÀ»ž]Ze¦Ë€ e{Ê^Ìe€eÄ]ÊfˆËZ]YÄÌ·ÁYY|¬»¾ËY€]ZÀ] {‹ʼ¿¹Z¼e  .Ä¿ZË|ËMÊ»d‡|]Ê^‡ZÀ»{|ŸZËMºÌÀÌ^]ÁºÌÀ¯µZ^¿{d‡{Z] HanoiĸXˆ/»¦/ˀ eZ/]Z/ÅÉZ/mÄ/]Z/m{Y| eºÌÀÌ^],ºÌÅ{Ê»¦¸fz»€Ë{Z¬»mÄ] ºÌËZ¼¿ŠËZ»MY©Â§ž]ZeÊf‡{ºÌ¿YÂeÊ»µZu    d‡YZ³Z‡Hanoik€]ĸXˆ»¦Ë€ eZ]ž]Ze¾ËY|‡Ê»€œ¿Ä]†a   d‡YZ³Z‡ Recurrence Function®Ë¶u  ©Â/§ĸXˆ/»{ {Â/‹Ê/»½Z/Ì]Ê/“ZËÃ{Z/‡ž/]YÂeYʰ˶°‹Ä]Ó¼ »[YÂm¾ËY |À¯Ê»©|Recurrence Function{į d‡YÊ ]Ze½M[YÂm ºËÁMd‡|]Y½M[YÂm|ËZ]ÊfŒ³Z]Ę]Y®Ë¦Ë€ eY†a,ºË|Ë{¶^«ÉZŵZj»{į˜¿Z¼Å    |À¯©|½M{|ËZ]Recurrence Function®Ë[YÂm d‡Y T (m ) 2m 1 ¶°‹Ä][YÂm Ä/]{Â/]Ã{Z/‡‰Á®/ËįYÊÀ˂´ËZm‰Á¶^«Ĉ¸m {Y{{ÂmÁRecurrence FunctioncÓ{Z »¶uÉY€]ʨ¸fz»ÉZʼnÁ Z/ʼnÁ½MĸÌ/‡Â]įºËÁ€]ɀ´Ë{¾Ë‚´ËZmÉZʼnÁ¡Y€‡|ËZ]¶Ì·{¾Ì¼ÅÄ],{Y{É{Á|v»{€]Z¯ÄÀ»Y{‰Á¾ËYZ»Y ºÌf§€³Z¯ ÁY|/¿YÄ/]Z/ÅRecurrence FunctionÂ/Àe¾ËY€]Z/À] º/ËÁMd‡|]Recurrence Function®ËºÌ¿YÂeÊ»ºfË´·Y€ÅÉYYÄ]   ºÌËZ¼¿¶uYėÂ]€»cÓ{Z »ºÌ¿YÂeÊ»ZźfË´·YYÉZ̈]ÉY€] Recurrence YÂ/¿¾/ËYÄ/f^·Y ºÌÀ¯Ê»¶uÁʧ€ »YRecurrence FunctionYʏZyÃÁ€³Ä»Y{Y{ d‡YZźfË´·Y{Y| e   |‹Z]Ê»|‹YʇZÀ‹Z¯ÁʇZÀ‹Z¯ÃÁ{ÉZźfË´·YYÉZ̈]ɳx‡ZaZÅFunction Recurrence Functions  Homogeneous Recurrence¾´¼ÅcÓ{Z »   d‡Y€Ëʻ¼Ÿ¶°‹Ä]¾°¼ÅRecurrence Function®Ë a0 t n a1 t n 1 ak t n k 0   |ÀfˆÅĸXˆ»cÓÂÆn»ZÅ t i Ád]Zi\ËY€“ZÅ ai ½M{į  Äf/‹Y|¿ t i Ä/¯ºËY|/¿ºÅÉYĸ¼m {Y|¿{ÂmÁ t i t i ,(t i )3 , (t i )2 |À¿Z»ʘy€Ì£¶»YŸ,©Â§Ä·{Z »{{‹Ê»Ã|ÅZŒ»į˜¿Z¼Å   ºÌÅ{Ê»Y€« t m ,T(m)ÉZmÄ] ºË{€³Ê»Z]É¿ZÅk€]ĸXˆ»Ä],ºÌfˆÅZÀ‹M|¬qcÓ| »¾ËYZ]ºÌÀÌ^]Ä°ÀËYÉY€]   ºÌ˳¾´¼ÅcÓ{Z »¾ËYÄ]€—Zy¾Ì¼ÅÄ] |‹Z]{|ŸÁ|‹Z] t m 2 t m 1 1   |‹Z]ʼ¿¾´¼ÅÄ·{Z »®Ëį{‹Ê»¶Ë|^e€Ë¶°‹Ä]ºfË´·Y½MÄ·{Z » Ê´fˆ/] t m 1 Y|/¬»Ä/] t m Y|/¬»Ê/À Ë d‡Y–^e€»ºÆ]½McÓÂÆn»įd‡Y½M,{¼¿ħZ“YcÓ| »Â¿¾ËYÄ]|ËZ]įɀ´Ë{Äf°¿   €yMÊ·YÁ t m 2 Ä] t m 1 Y|¬»Á{Y{ ¶¬fˆ/»ºÅYcÓÂÆn»ÊÀ Ë d‹Y{ÄmÂeZÆ¿M¾Ì]•Z^eYÄ]|ËZ]Z»Y,|‹Z]Ê» t n , t n 1 , , t n k Ä·{Z »cÓÂÆn»įd‡Yd‡{ÊÀ Ë ,|/‹Z] t n x n |/ÌÀ¯‘€/§ º/ËÁMÊ»d‡|]YZÅ[YÂmYÊ°ËZnÀËY{ {Y{ʨ¸fz»ÉZÅ[YÂmÄ·{Z »|À¿Z»¾´¼ÅÄ·{Z »®Ë   |ÀfˆÌ¿   |ËMÊ»d‡{Ä]cÓÂÆn»¹Z¼e,ºÌÀ¯Y|ÌaYx€³YÊÀ Ë   |À¯©||ËZ]Ä·{Z »{,d‡YÄ·{Z »[YÂm t n ½Âq ºÌÀ¯Ê»ÉÁ€ÌaÃ{Z‡Ã|ËY®ËYx½{€¯Y|ÌaÉY€] a0 x n a1 x n 1 ak x n k 0 x n k a0 x k a1 x k 1 ak 0  ºÌ‹Z]Äf‹Y{|ËZ]¾ËY€]ZÀ] {Y|¿Ê»Âƨ»ZźfË´·Y¶Ì¸ve{į|¿Â‹Ê»€¨ZÅ t i ¹Z¼e,|‹Z]€¨x€³Y a0 x k a1 x k 1 ak 0 d/‡|]xÊ/À ˵Â/Æn»€Ë{Z/¬»,Ä/·{Z »¾/ËY¶uY |À˳Ä·{Z »ÉY€]Charactristic EquationZËĐzŒ»Ä·{Z »,Ä·{Z »¾ËYÄ] ,|‹Z] r1 , r2 , , rk ZÅČ˾ËY|ÌÀ¯‘€§ {Y{Ê»ÂÅ»ZËʬ̬uČËK,KÄm{ÉYĸ¼m|Àq®Ë€^mʇZ‡YÄ̔«ª^— |ËMÊ»   |‹Z]Äf‹Y{Y r1n ZË r2n ZË ZË rkn €Ë{Z¬»|¿YÂeÊ» t n \Ìe€e¾ËYÄ] ‰Y|¬»ºÅ r2n ÉYYÄ],{Œ̻€¨‰Y|¬» r1n €Ë{Z¬»ÉYYÄ]ÊÀ Ë,d‡Y¾´¼ÅÄ·{Z »½Âm ºÌÀ¯Ê»ÄmÂe½{Â]¾´¼ÅÄ]µZu \/̯€e ºÌ/À¯Ê»Ã{Z¨f‡Y¶Ìˆ¿Y€¨Ë{cÓ{Z »¶uZ]Ä]ZŒ»ÉYÃ|ËYY¾ËY€]ZÀ],{‹Ê»€¨‰Y|¬»ºÅ rkn ÉYYÄ]Á Á{‹Ê»€¨  {Â]|ÅYÂy€Ë¶°Œ] t n €´Ë{cZ^ŸÄ] d‡Y¾´¼ÅÄ·{Z »ÉY€]Ê]YÂm,¾´¼ÅÄ·{Z »®ËÉZÅ[YÂmʘy t n c1 r1n c 2 r2n c k rkn    c1 ,c 2 , , c k \ËY€“ºÅÁºËÁMd‡|]Y r1 , r2 , , rk €Ë{Z¬»|ËZ], t n ¾ÌÌ eÉY€]  t n 3t n 1 4t n 2 0 t 0 0, t1 1 n 2   |ÌÀ¯¶uY€ËÄ·{Z »µZj» Á{Â/]|/ÅYÂyKÄ/m{Y½MĐ/zŒ»Ä/·{Z » d/‡YK = 2½M{Ä/¯,d‡YÄ·{Z »Â¿YÄ·{Z »¾ËY,{‹Ê»Ã|ÅZŒ»į˜¿Z¼Å r1 1 x 2 3x 4 0 r2 4 n 0 t 0 c1 1 c 2 1 0 c1 1 5  n 1 t1 c1 4c 2 1 c 2 1 5 1 (x 4)(x 1) 0 t n 4n ( 1) n 5   d‡Y€Ë¶°Œ]     t n t n 1 t n 2 n 2  µZj» t 0 0 t 1 1 t n t n 1 t n 2 t n t n 1 t n 2 0  ¶u 1 5 r1 2 x 2 x 1 0 1 5 r2 2 n n t n c1 r1n c 2 r2n tn c1 0 t 0 c1 c 2 0 1 t 1 c1 r1 c 2 r2 1 c 2 1 5 1 5 1 r1n r2n ÊqZ¿Â^̧€´Ë{ʻ¼Ÿĸ¼m®Ë 5 Ä/·{Z »¶°/‹,¾ËY€]Z/À] d/‡Y€Ë~/a½Z°»Y,ĐzŒ»Ä·{Z »¶u…Z‡Y€] r1 , r2 , , rk ½{€¯Y|Ìa,{‹Ê»Ã|ÅZŒ»į˜¿Z¼ÅÄf°¿   \ˀ/“Đ/zŒ»Ä/·{Z »{\/Ìe€e¾/ËYÄ/] ºÌ»Z/À]rYČ/˾ËY€³Y |‹Z]Äf‹Y{mÄ^e€»Y€°»ČË®ËĐzŒ»Ä·{Z »|ÌÀ¯‘€§   |ÌÀ¯ÄmÂeÄ·{Z »¶°‹ZyÉZÅd·ZuYÊ°ËÄ] {Y{d̼ÅYY|¬»¾ËY½{€¯Y|Ìa{ĐzŒ»   |ËMd‡|]€ËÉZÅ[YÂm, t n ÉY€]r…Z‡Y€]į{‹Ê»\^‡Â“»¾ËY |ËMÊ»{ÂmÂ] x r m ÉZ/ÅČ/Ë €/°»€Ì£ZÆ¿MYÊy€],|¿€°»ZÆ¿MYÊy€] {Y{ČËkÊÀ Ëd‡YkÄ^e€»YĐzŒ»Ä·{Z »|̋Z]Äf‹Y{ÄmÂeµZu€ÅÄ]   {ÁMÊ»{ÂmÂ]Y©Â§|Ë|m€Ë{Z¬» t n ÉY€]€°»€Ì£ t n r n , t n n r n , , t n n m 1 r n  t n 5t n 1 8t n 2 4t n 3 0 t 0 0 t1 1 t 2 2 n 3  |ÌÀ¯¶uYÁÄ]ÁÄ·{Z »µZj»  ¶u x 3 5x 2 8x 4 0 r1 1 (x 1)(x 2) 2 0 r2 2  |‹Z]Ê»€Ë¶°Œ]ĐzŒ»Ä·{Z » t n r1n , r2n , n r2n t n c1 r1n c 2 r2n c 3 n r2n n 0 t 0 c1 c 2 0 n 1 t 1 c1 r1 c 2 r2 c 3 r2 1 2 2 2 n 2 t 2 c1 r1 c 2 r2 c 3 2r2 2 c1 2 c 2 2 c 1 / 2 3   Inomogeneous Recurrence¾´¼Å€Ì£cÓ{Z »     ºËY{€aÊ»¾´¼Å€Ì£cÓ{Z »YʏZyÂ¿¶uÄ]Zm¾ËY{,{Y{YZŶ°‹¹Zˆ«YÁY¿Y¾´¼Å€Ì£Ä·{Z »®Ë a0 t n a1 t n 1 ak t n k b n p ( n )    t n , t n 1 , , t n k cÓÂÆn»¾´¼ÅÄ·{Z »Ä]ZŒ» d‡YÄ·{Z »|À¿Z»Ä·{Z »¾ËY`qd¼‡,{‹Ê»Ã|ÅZŒ»į˜¿Z¼Å   dÄm{YÉYĸ¼m|Àq®Ëp(n)Ád‡Yd]ZiY|¬»®ËB |ÀfˆÅd]Zi€Ë{Z¬» a0 , a1 , , ak  |À‹Z]Ê»    d‡Y¾´¼Å€Ì£Ä·{Z »®Ë b n p (n ) {Â/mÁd/¸ŸÄ/]Ä/·{Z » d/‹Y{Y€¨/Y|/¬»,d‹Y|¿µÂÆn»įÉYĸ¼mZÆÀe,|Àf‹Y{YµÂÆn»Ä·{Z »{cÔ¼m¹Z¼eÄf°¿  ¾/´¼ÅÄ/·{Z »[YÂ/m ºÌÀ¯¶Ë|^eÄ·{Z »Ä]YÄ·{Z »įd‡Y½MZ¯‰Á d‡YÃ{Z‡Z̈]Ã|ËY®Ë,cÓ{Z »Â¿¾ËY¶uÃ|ËY Š¸Ë|/^eÊ/À ˺Ì/À¯‘Â/ŸYŠ¸°/‹|/ËZ]įºËY{Ä·{Z »®Ë ºÌÅ{¹Zn¿YYZ¯¾ËY˜qÄ°ÀËY|¿Z»Ê»Z»Y {Â]|ÅYÂyĸXˆ»[YÂm ¶°Œ/]Z/eºÌ/Å{¹Z/n¿YY¹ÓÉZ/ÅÊÀ˂´ËZ/mZËÁªË€¨e,ž¼m‰{ÂyZ]YÄ·{Z »¾ËYÄ°ÀËYY€Ì£|¿Z»ʼ¿ÊÅY ¾´¼ÅÄ·{Z »Ä]ºÌÀ¯   {‹¶Ë|^e¾´¼Å   ºÌÅ{Ê»ÄWYYʸ¯µÂ»€§®Ë†b‡,ºÌÀ¯Ê»¾Ë€¼eY‰Á¾ËYµZj»Á{Z]Y|f]Y  t n 2t n 1 3n   |ÌÀ¯¶uYÁ€]ÁÄ·{Z »µZj» b 3, p (n ) 1, d 0  ¶u   ºËY~´]n+1ºÌ¿YÂeÊ»nÉZm¾ËY€]ZÀ],d‡YY€«€]n€ÅÉYYÄ]Ę]Y¾ËYÄ°ÀËY|À¿Z»,ºËÁÊ» ÊeZ/°¿¡Y€‡†a d‡Y€¨¦·Zz»,d‡Yd¼‡|ÌËZ¼¿ÄmÂe,ºÌÀ¯Ê»€¨Y©Â§Ä·{Z »d‡Yd¼‡Ã{Z‡ʓZËcZ̸¼Ÿɀˆ°ËZ] 1) t n 1 2t n 3n 1   ºÌÀ¯Ê»[€“{YʸYÄ·{Z »µZu 2) 3t n 6t n 1 3n 1   ºÌÀ¯Ê»º¯ºÅYYÁcÓ{Z » t n 1 2t n 3n 1 (3t n 6t n 1 3n 1 ) t n 1 5t n 6t n 1 0 €/œ¿Ä/]ZnÀËY{¾ËY€]ZÀ]  t n 1 Ä¿{Â] t n Ä·{Z »¾ËYµÁYĸ¼m {€¯ÄmÂe|ËZ]Äf°¿¾ËYÄ]ºÌÀ¯ĈËZ¬»Ä·{Z »Z]YÄ·{Z »¾ËYºÌÅYÂz]€³Y    d‡Yk = 2į|‡Ê» Charactristic Equation : x 2 5x 6 0 r1 2 (x 2)(x 3) 0 r2 3   c1 ºÌfˆ/¿YÂeÊ/»,{Â/]Ã{Y{Z/»Ä/]ĸXˆ»cÄÌ·ÁYY|¬»Á{€¯YÊÀ Ë,ºÌÀ¯Ê»¶uYÄ·{Z »¾´¼ÅÄ·{Z »Ä]ZŒ» r2 Á r1 ½|‹Y|ÌaZ] ®/Ë ºÌ/À¯Ã|ÅZŒ/»ºÌ¿YÂ/eÊ»YŠz]Á{ĐzŒ»Ä·{Z »½{€¯Y|Ìa{ÃY¼Å d‡Ys€—¶]Z«ºÅɀ´Ë{cZ°¿ ºËÁMd‡|]Y c 2 Á   {‹Ê»Ã|ÅZŒ»Ê]ÂyÄ]{Y»¾ËY©Â§µZj»{ d‡YcY€Ì̤eÄ]€›ZÀf»€´Ë{Šz]Ád‡YĸXˆ»ÄÌ·ÁYÄ·{Z »`qd¼‡Ä]€›ZÀf»Šz]  t n 2t n 1 ( n 5)3n   |ÌÀ¯¶uY€¿MÁ|ÌËZ¼¿¶Ë|^e¾´¼ÅÄ·{Z »®ËÄ]Y©Â§Ä·{Z »µZj»   ºËY~³Ê»n+1,nÉZmÄ]  ¶u t n 1 2t n (n 6)3n 1   ºÌÀ¯Ê»[€“{YʸYÄ·{Z » 3t n 6t n 1 ( n 5)3n 1   ºÌÀ¯€¨Yd‡Yd¼‡n+2½YÂeZ]ºÌÀ¯Ê»Ê ‡†a ºÌÀ¯€¨Yd‡Yd¼‡ºÌ¿YÂeʼ¿n+1½YÂeZ]|‡Ê»€œ¿Ä]†a   ºÀ̯Ê»[€“{YʸYÄ·{Z » 1) 9t n 18t n 1 ( n 5)3n 2   ºËY~³Ê»n+2,nÉZmʸYÄ·{Z »½Z¼Å{ 2) t n 2 2t n 1 ( n 7)3n 2   ºÌÀ¯Ê»[€“-6{ÁºÌÅ{Ê»Y€«n+1,nÉZmʸYÄ·{Z »{Z]¾ËY 2) 6t n 1 12t n 2( n 6)3n 2   {‹Ê»€ËÄ·{Z »¶Zuį ºÌÀ¯Ê»ž¼mºÅZ]YÁÁcÓ{Z » t n 2 8t n 1 21t n 18t n 1 0 x 3 8x 2 21x 18 0   d‡Yc¾ËYÄ]½MĐzŒ»Ä·{Z »į|‹ÄfyZ‡¾´¼ÅÄ·{Z »®ËZ¯¾ËYZ] (x 2)(x 3) 2 0 cY€/Ì̤eYʋZ¿½M€´Ë{Šz]Á¾´¼ÅÄ·{Z »Ä]€›ZÀf»½MŠz]®Ë {Y{Šz]Á{ĐzŒ»Ä·{Z »¾ËY,{‹Ê»Ã|ÅZŒ»į˜¿Z¼Å   d‡Y  {Â]|ÅYÂy€Ë¶°‹Ä]ĐzŒ»Ä·{Z »Ä·{Z »ÉY€]ʸ¯—Ä] (a0 x k a1 x k 1 ak )(x b )d 1 0  t n 2t n 1 1 n 1 t 0 0  µZj»  ¶u  b 1 p (n ) 1 d 0 r2 2 (x 2)(x 1) 0 r1 1 t n c1 1n c 2 2n n 0 t 0 c1 c 2 0 c1 1,c 2 1 n 1 t 1 c1 2c 2 1 Ã{Z¨f/‡Y¶/]Z«Č/̼Ådˆ/Ì¿¹Â¸ »įd‡Y©Â§|À¿Z»ÃY®Ë |‹Z]€f¼¯ c i \ËY€“{Y| eYÄÌ·ÁY€Ë{Z¬»{Y| e,|ÌÀ¯‘€§¹Á{‰Á   ºËÁMd‡|]Y c 2 Á c1 \ËY€“ºÌÀ¯Ê ‡ÁºÌÅ{Y€«Ä·{Z »{Y t n [YÂmįd‡Y½M€´Ë{ÃY |‹Z] t c1 2n c 2 t n 2t n 1 1 n t n 2t n 1 1 t1 2t 0 1 1 c1 2n c 2 2 c1 c 2 2 n 1 1 n n c1 2 c 2 2c1 2 c 2 1 c1 1   |‹Z]|¿YÂeÊ»ÉY|¬»€Å c 2 †a  t n 2t n 1 n  µZj» p (n ) 1 2 n n n d 1 ( x 2)(x 1) 0 t n c1 2 c 2 1 c 3 n 1 b 1 Y€/«Ä/·{Z »{Y t n Ä°¿MY€Ì£ºËY|¿ÉYÃZq,ºËÁMd‡|]Y c1 ,c 2 ,c 3 ºÌÅYÂz]€³Y†a d‡YÃ|Œ¿Ã{Y{ t 0 ĸXˆ»c¾ËY{  ¶u  c1 0, c 2 2,c 3 1 ,ºÌ/À¯¶/uYĸXˆ/»‰Á¾/ËYÄ/]€/³Y ºÌ/À¯Y|Ìa•€‹ZËÁºËÁMd‡|]Y|¬»ZË, c1 ,c 2 ,c 3 ÉY€]ÁºÌÅ{   |‹|ÅYÂy  n a0 t n a1 t n 1 ak t n k b1n p1 (n ) b 2 p 2 (n )  ºË€Ì³Ê»€œ¿{€Ë¶°Œ]Y¾´¼ÅÄ·{Z »®Ëʸ¯—Ä]   Á d 2 Äm{Y p 2 (n ) Á d 1 Äm{Y p1 (n ) ½M{į (a0 x k a1 x k 1 ak )(x b1 )d1 1 (x b 2 )d 2 1 0  {Â]|ÅYÂy€Ë¶°Œ]ĐzŒ»Ä·{Z »d·Zu¾ËY{  µZj» t n 2t n 1 n 2n t 0 0      b1 1 p1 ( n ) n d 1 1 b 2 2 p 2 (n ) 1 d 0 2  ¶u (x 2)( x 1) 2 ( x 2) 0 ( x 2) 2 ( x 1) 2 0 t n c1 1n c 2 n 1n c 3 2 n c 4 n 2 n t 1 2t 0 1 2 3 2 t 2 2t 1 2 2 12 3 t 3 2t 2 3 2 35 n n n n 0 t0 1 t1 2 t2 3 t3 c1 2 c 2 1 c 3 2 c 4 1  €Ì̤f»€Ì̤e ¾/ËYcÓ{Z/ »YÊ/y€]{Â/»{ d/‡YcÓ{Z »¶uʸYÉZʼnÁÓ¼ »©Â§‰ÁÁ{,ʇZÀ‹Z¯ÃÁ{cZ»Â¸ »|u{  ¶°/‹Ä/]YÄ/·{Z »¶°/‹,d/‡YʓZË€Ì̤f»€Ì̤e½Z¼ÅįÃ{Z‡¶°‹Ä]€Ì̤e®ËZ]cZ«ÁYÊÅZ³Z»Y ºË€^]Z°]ºÌ¿YÂeʼ¿YZʼnÁ ÉZ/ŵZ/j»Ä/]{Á|/v»Ã|/ËY¾ËYį {‹Ê»Ã{€]Z¯Ä],€Ì̤f»€Ì̤eÃ|ËYÉ{Y»¾ÌÀq{ ºËÁMÊ»{€¯~·Y©Â§¾´¼Å€Ì£Z˾´¼Å   |‹Z]ʼ¿Z¼fu| ]Äv¨|Àq{Ã|‹Äf¨³  T (n ) 4T (n / 2) n n 1  µZj» if n 2k t k T ( n ) T (2 k )  ¶u k k t k 4t k 1 2 t k 4t k 1 2 k 1 T (n / 2) T (2 ) t k 1 p1 (k ) 1 (x 4)(x 2) 0 t k c1 4k c 2 2 k d 0 b 2 €/Ì̤f»€/Ì̤e,µZ/j»¾/ËY{ ºÌÅYÂ/yÊ/»Y t n [YÂmÀyÓZ]½Âq |‹Z]ÃY€¼Å½ÁYÁ€Ì̤f»€Ì̤eZ]|ËZ]ɀÌ̤f»€Ì̤e€Å{¼¿d«{|ËZ]   ºÌˆËÂÀ]n\ˆu€]Y‚ÌqļŶ^«Ę]Y{d‡YʧZ¯ ºË€Ì´]Z°]ºÌ¿YÂeÊ»ʳ{Z‡Ä]Y½ÁYÁ T ( n ) c1 n 2 c 2 n T ( n ) O ( n 2 n 2 k ) T n 4T n/2 n 2  µZj» if n 2 k T ( n ) T (2 k ) t k  ¶u k t k 4t k 1 4 k 1 T ( n / 2) T (2 ) t k 1 P1 ( k ) 1 1 ( x 4)( x 4) 0 ( x 4) 2 0 t k c 1 4 k c 2 k 4 k d 0 b 4 1   ºÌÅ{¹Zn¿Yʳ{Z‡Ä]ºÌ¿YÂeÊ»Y½ÁYÁ€Ì̤f»€Ì̤eµZj»¾ËY{ºÅZ]  T ( n ) c 1 n 2 c 2 lo g n n 2 2 T ( n ) O ( n 2 lo g n n 2 k ) T (n ) n T 2 (n / 2) T (1) 6 n 1   |ÌÀ¯¶uYÁ€]ÁÄ·{Z »µZj»  ¶u Y€/Ì̤f»€/Ì̤e{ÓÂ/¼ »Z/»Y |/‹Z^¿¶/u¶/]Z«©Â/§cY€/Ì̤eÄ]ZŒ/»Ê/eY€Ì̤eZ]|‡Ê»€œ¿Ä]¾ËY€]ZÀ] d‡Yʘy€Ì£Ä·{Z »¾ËYY€ÅZ› n 2k T ( n ) T (2 k ) t k   ºÌÀ¯Ê»Á€‹cY€Ì̤e¾Ë€eÃ{Z‡ t 2 k t k2 1 T ( n / 2) T (2k 1 ) t k 1 k t 0 6 T (1) T (20 ) t 0   {‹Ê»¶Ë|^eZźfËZ´·Â¼n»Ä][€”¸ZuºfËZ´·ÃÁÔ ]d‡Y®Ë{‚¿ºÅ 2k Ä] d‡Y log 2 ž]YÂe ¾/ËYYÊ°Ë ºÌÀ¯µZ¼ŸYYÊ ]ZeÄ·{Z »¾Ì§€—Ä]į{‹¹Ód‡Y¾°¼»dˆÌ¿€Ë~a½Z°»YÃ{Z‡¶°‹Ä]Ä·{Z »cY€Ì̤e{Y»Êy€]{ lo g t k lo g 2 k lo g t k2 1  {‹Ê»ÄnÌf¿,ºË€Ì³Ê»ºfËZ´·©Â§Ę]Y¾Ì§€—YµZu k 2 lo g t k 1 lo g t 0 lo g 6 lo g 2 lo g 3 1 lo g 3 v k 2v k 1 k v k k 2v k 1 v k log t k v 0 log t 0 1 log 3 b1 1 2 v k c 1 2 k c 2 1k c 3 k 1k p 1 ( k ) k ( x 2)( x 1) 0 d 1 1 v 1 1 2v 0 1 2 2 log 3 3 2 log 3 v 2 2 2v 1 8 4 log 3 k 0 v 0 c 1 c 2 1 log 3 c 1 3 log 3 c 2 2 k 1 v 1 2c 1 c 2 c 3 3 2 log 3 k 2 v 4c c 2c 8 4 log 3 c 1 1 2 3 2 3 ºË€]Ê»Z°]|Ë|m€Ì̤f»€Ì̤e®ËµZu v k (3 log 3)2 k k 2   ºÌ‡€] t n Ä]½ÁYÁÉY~´ËZmZ]|ËZ]¾ËY€]ZÀ] ºÌÀ¯Y|ÌaY t n |ËZ]į|ÌÀ¯ÄmÂe vk v k log t k t k 2   t 2(3 log 3)2k k 2 n n k t n 2(3 log 3) n log 2 2 2(3 log 3) 2 log 2 22 k n 2 11 11 2(3 log 3) 2(3 log 3) n n4 2log 2 4 1 t n 2(3 log 3) 4n   |‹Z]kZÌfuYɀfŒÌ]d«{Ä]d‡Y¾°¼»įºÌÀ¯Y|ÌaYT(n)ÀyÓZ]|ËZ]½ÁYÁcZ̸¼Ÿ{\Ìe€e¾ËYÄ]  ʏZyd·ZuºË{€¯s€˜»įÉZŵZj»¹Z¼e|ˀ̴]ÄnÌf¿ |ÌÀ¯ʇ€]Y€¿M¦¸fz»cÓZu |ÌÀ¯ʇ€]Y[Zf¯ĸXˆ»¾Ë€¼e   d‡Y½MY  1 t n 4 t n 1 t 1 / 4 1   |ÌÀ¯¶uYÁ€]ÁÄ·{Z »µZj» (A ) a b n 1 1 T (n ) n b n 4 an 1 4b n 1 an 1 b n 1  ¶u an b n 1 b n 4b n 1 an 1  |¿€]Y€]ºÅZ]ZÅk€z»Á€ˆ¯Á{ÉZÅc{‹Ê»ÄnÌf¿©Â§ÉÁZˆeY (B ) b n 4b n 1 b n 2 b n 4b n 1 b n 2 0 r1 2 3 x 2 4x 1 0 r2 2 3 b n c1 (2 3) n c 2 (2 3) n (1)  (A)Ę]Yª^— ºËÁÊ»ÄÌ·ÁY€Ë{Z¬»¡Y€‡ ºÌÀ¯Y|ÌaY c1 ,c 2 įºÌÀ¯Ê»µZ^¿{ÊfÆm{Yhv] T (1) t1 a1 1 1 a1 4 b1 b1 4 (C ) ¹Ó€/³Y¾ËY€]Z/À] |/‡€][YÂmÄ]cZ^‡Zv»ZeºÌÀ¯[Zzf¿YÉY|¬» b0 ÉY€]|ËZ]¾ËY€]ZÀ]ºËYÃ{€°¿¦Ë€ eYʨÀ»†Ë|¿YZ]€Ë{Z¬»½Âq   ºË€Ì´]€œ¿{ʗ€‹|ËZ]ºÅ a0 ÉY€]|‹Z] n 0 b 0 c1 1 c 2 1 1 2 3 ,c 2 1 c1 c1 23 n 1 b1 c1 (2 3) c 2 (2 3) 4 |Å|¿Z»Ä]ʗ€‹€³Y.Ä¿ZË|Å{Ê»Z»Ä]ʗ€‹ºÌÀÌ^]ºËÁÊ»ĸXˆ»c¡Y€‡ ºËY{Z^¿ a0 Y|¬»Ä]į|‡Ê»€œ¿Ä]\Ìe€e¾ËYÄ] Ę]Yª^—:   ºÌÀ¯[Zzf¿YY a0 Y|¬»|ËZ] (C ) b1 4b0 a0 4a0 a0 0 d‡|]T(n)\Ìe€e¾ËYÄ]ÁºËÁMÊ»d‡|]Y an Y|¬»(B)Ę]YYÃ{Z¨f‡YZ]ÁºËÁMÊ»d‡|]Y b n ,Ę]YYÃ{Z¨f‡YZ]†a   |ËMÊ»    ¶§ Greedy AlgorithmÄ¿ZË€uÉZźfË´·Y  ½Z»{Â/‡ºÌËÂ/´]Z/“€§ {Â/‹minZ/Ëmax|/ËZ]d/̼¯Y|¬»Ó¼ »ZÆ¿M{įºËY{Z¯Á€‡ÉZźfË´·YZ]¶§¾ËY{  ÉY€/] ºÌ/À¯minºÌÅYÂ/yÊ/»Yʧ|/ÅZËÁºÌÀ¯maxºÌÅYÂyÊ»Yʧ|źÌË´]ºÌ¿YÂeÊ» |ËMÊ»¹Âƨ»¾Ì¼ÅYGreedy½YÂÀŸ   {‹¶«Y|u½Z»€“ZËÁ{‹€j¯Y|u   {Y{ʨ¸fz»ÉZŶ°‹ĸXˆ»€Å{ZÅdË{Á|v»½Mį{Y{{ÂmÁÉZÅdË{Á|v»,ZÅ¥|ŝ¿¾ËYÄ]½|̇  d/‡Y€/ˁ¶°Œ]‰Á¾ËYÉZ¯ºfË´·Y €f³‚]¶°Œ]ZË|¿Â‹Ê»¦Ë€ e€f°q¯¶°Œ]ZË |¿Y{ÉÁZˆ»Z¿d Ì^—ZÅdË{Á|v»¾ËY Function Greedy (C:set) :set S while not solution(S) and C do X an element of C maximizing select(X) C C \ {x} If feasible( S {X } ) then S S {X } If solution(S) then return S Else return " there are no solutions "   ºÌÅ{Ê»t̓ÂeµZj»®ËZ]Y€¿M Minimum Spanning Tree¾Ì¼¯ÉZ‹Âady{  ¥Y€/³…Â/W¹Z¼e¶»Z‹į|À˳Z‹ÂaYZÅdy{¾ËYÊ¿Z» |‹Z]Äf‹Y{ž¸“n-1{Y{…Yn€³Y |‹Z]Äf‹Y|¿Á{ÊÀ Ë|‹Z]Äf‹Y{ Êfy{Êf Ì^—|¿YÂeÊ» |‹Z]Äf‹Y{…YZËž¸“É{Y| e€Å|¿YÂeÊ»¥Y€³€Ë¾ËY |ˀ̴]€œ¿{Y¥Y€³®ËYʧY€³€Ë  ºfËÂ/´·YÁ{ ¥Y€/³®/ËÉY€/]dˆ/Ì¿Z/f°ËZ/»Y‚·Y¾Ì/¼¯ÉZ/‹Âad/y{,|‹Z]min½M½Áįd‡YÊfy{¾Ì¼¯ÉZ‹Âady{   |À‹Z]   {Y{{ÂmÁ¾Ì¼¯ÉZ‹Âady{½{€¯Y|ÌaÉY€]®Ì‡Ô¯ KruskalºfË´·Y  Function Kruskal ( G N , A : graph ; length : A * ) : set of edges {initialization} Sort A by increasing length n #N T { will contain the edges of the minimum spanning tree Initialize n sets, each containing one distinct element of N } {greedy loop} Repeat {u,v} shotest edge not yet considered ucomp find(u) vcomp find(v) If ucomp vcomp then Merge(ucomp,vcomp) T T {{u ,v }} Until #T = n-1 Return T  d/y{®/ËTįºËY{ÄmÂe {Œ¿ÃZ^f‹YTZ]¾ËY€]ZÀ],T¾fyZ‡ÉY€]d‡YÉY‚]Y¶´Àm d‡YºfË´·YÊmÁ€yT©Â§ºfË´·Y{   d‡Y|À^¼ÅÁ{Y{ž¸“n-1,|‹Z]Äf‹Y{…Yn€³Y,{Y|¿Á{†a,d‡Y   |‡€]ČËÄ]Ze{ÁÊ»ÓZ]dy{YÁ{€Ì³Ê»Y{ÂyÉ{ÁÁfindºfË´·YÄf°¿    µZj»   u v ucomp Vcomp  1 2 3 1 2 4 2 3 5 1 1 4 2 3 5 4 6 7 6 7 5 1 4 1 4 6 7 2 4 5 7 1 1 1 6 ¶uY€»        kruskalºfË´·Yʧ€»½Z»¶Ì¸ve ‰{€/³¾/ËYÉY€]O(n)®Ë†a |y€qÊ»Z]n-1,repeat-untilĬ¸u¾ÌÀr¼Å d‡Y O (a log a ) €]Y€]sort(A)ʧ€»½Z» log aZ/¯¾/ËY½Z/»,ºÌ/‹Z]Ä/‹Y{Z/ŽÁÉY€]minheapdy{€³YįºËY{Ê¿Z»‚Ì¿ÄÀ˂žˀf¼¯Z]Ê ¸“[Zzf¿YÉY€] ºËY{   d‡YO(log N)‚Ì¿Č˾f§ZËÉY€]ʧ€»½Z» d‡Y Ĭ¸u¶yY{ÉY€]ʧ€»½Z» : O (n log a ) ( n 1)(log a log a ) €´Ë|/°ËZ/]YÁ{¾ËYºfË´·Y¾ËY¶¯ÉY€]µZu Ĭ¸u¶yY{ÉY€]‚Ì¿O(n log a)®ËÁsort(A)ÉY€]ºËY{O(a log a)®Ë†a a |/‹Z]aY€f°qÂ/¯n€/³YÁn log aºfË´·Y¶¯ÉY€]|‹Z]aY€f³‚]n€³YZnÀËY{ ºÌÀ¯Ê»Y|ÌaYº¼Ë‚¯Z» ºÌÀ¯Ê»ž¼m   d‡YºfË´·Y¶¯ÉY€]log a primºfË´·Y  Function prim ( G N , A : graph : length : A * ):set of edges {initialization} T { will contain the edges of the minimum spanning tree } While B N do Find {u,v} of minimum length such that u N \ B and v B T T {{u ,v }} B B {u } Return T ¶Ë|^e€yM{įºÌf‹Y{¶´Àmĸu€»€Å{kruskalºfË´·Y{įÊ·Zu{ ºËY{dy{®Ëĸu€»€Å{ºfË´·Y¾ËY{Äf°¿   |‹Ê»dy{Ä] primºfË´·Yʧ€»½Z»   º/ËY{Ä/À˂žˀ/f¼¯Z/](u,v)ž¸/“[Z/zf¿YÉY€]log nZËlog a®ËZÆÀeÁ |y€qÊ»Z](N)¥Y€³…ÂW{Y| eÄ]whileĬ¸u   {€Ì³Ê»Y€«n log nZËn log aÃÁ€³{ºfË´·Y¾ËYʧ€»½Z»¾ËY€]ZÀ] Shortest Path€Ìˆ»¾Ë€eÃZe¯    |À¯Y|ÌaY¥Y€³…ÂW€ËZ‡ÁŽzŒ»…Y®Ë¾Ì]ĸZ§¾Ë€eÃZe¯į|ÌÀ¯ÊuY€—ʼfË´·Y    Á€eÂÌb»Z/¯Ê¿Z/^»…{¾Ì/]ĸ/Z§¾Ë€/eÃZe¯ºÌÅYÂyÊ» |ˀ̴]€œ¿{Y€eÂÌb»Z¯Äf‹ÉZÅ…{¥Y€³,©Â§¥Y€³ÉZmÄ]µZj»   ºÌÀ¯Y|ÌaY…Á{€ËZ‡      ZÅ¥Y€³ŠËZ¼¿  ºÌÅ{½ZŒ¿Y¥Y€³ºÌ¿YÂeÊ»®Ì‡Ô¯¶°‹Á{Ä]µÂ¼ »˜]  †Ë€eZ»YÃ{Z¨f‡Y  ÉYÂn¼ÅdˆÌ·YÃ{Z¨f‡Y   ½Á¾/ËY,{Â/‹Ê/»Ã{Y{½ZŒ/¿{ZˁʸÌy½ÁZ],|‹Z]Äf‹Y|¿{ÂmÁįÊ ¸“ ºÌˆË¿Ê»YÔ“Y½ÁÁ{Y|ŸYÉZn]†Ë€eZ»{ Y†Ë€eZ/»ɀ/˜«€/ZÀŸ |ÀÅ{Ê»½ZŒ¿ʸ¯d»ÔŸZ]Y½Á¾ËYÓ¼ » {‹ʼ¿[Zzf¿Yž«Â»pÌÅZÆ]Zzf¿Y{įd‡Y{Zˁ|¬¿M ®ËºÌ¿YÂeÊ»Y©Â§†Ë€eZ» {Y{ºÅɀ´Ë{{€]Z¯Â“»¾ËYZ»Y ºËY|¿ʨÀ»½Áįd‡Y½M½Z¼“€§ŠÌa ºÌÅ{Ê»½ZŒ¿€¨Z]   ºË€Ì´]€œ¿{…Zb‡Y†Ë€eZ» Procedure shortest-path ( v,cost,dist,n ) For i 1 to n do S(i) 0 , Dist(i) Cost(v,i) End S(v) 1 , Dist(v)=0 For num 2 to n-1 do Choose u such that Dist(u) = min { Dist (w) } S(w)=0 S(u) 1 For all w with S(w)=0 do Dist(w) min { Dist (w),Dist(u)+Cost (u,w) } End End End DistÁd/‡Y¥Y€/³Ä/]•Â/]€»†Ë€eZ»Cost |À¯Ê»¾ÌÌ eY¥Y€³…ÂW€ËZ‡ÁvÃYÂz·{…Y¾Ì]ĸZ§¾Ë€eÃZe¯ºfË´·Y¾ËY  ”/Ÿn,DistÄËYM |Å{Ê»½ZŒ¿Yi…YÁv…Y¾Ì]ĸZ§¾Ë€eÃZe¯Dist(i) |Å{Ê»½ZŒ¿YºfË´·YÊmÁ€yįd‡YÄËYM ®/Ëv {Y{{€]Z/¯ºfËÂ/´·Y|/ÀËM€§{Ä/¯{ÁÊ»Z¯Ä]ZÅdÌ]YÄËYM®Ë½YÂÀŸÄËSÄËYM d‡Y¥Y€³…ÂW{Y| enį{Y{   ºÌÀÌ^]€fÆ]YºfË´·YÉZ¯‰{€³ZeºÌÀ¯Ê»[Zzf¿YYv©Â§µZj»ÉY€] |‹Z]ʇY€Å|¿YÂeÊ»ÊÀ Ëd‡Y¥Y€³YÃYÂz·{…Y 1 2 3 4 5 6 7 8   Dist  S 1500 0 250  0 1250 0 250 1150 1650 1250 0 250 1150 1650 2450 1250 0 250 1150 1650 2450 1250 0 250 1150 1650   0    0    01 3350    01    01    01     01    ÃZ]Á{ZeºÌÀ¯Ê»®ËYŠfÌ]ºÌÀÌ^]įY…Y€Å ºÌÀ¯Ê»Ã{Z¨f‡YÉY~³d»ÔŸÉY€]ÄËYM¾ËYY,d‡ZÅdÌ]YÄËYM®Ë,SÄËYM …Z/‡YY€],ºÌ¿YÂeÊ»µZu d‡Y…Y½Z¼ÅįºËÁÊ»…Y¾Ë€f¿YY¡Y€‡,ºÌf§YÊ»ÃYYįd‡YÊÀ »¾ËYÄ]€]Y€]v[Zzf¿Y   ºÌÀÌ^¿Y½M   ºËÁM{ÁÄ]Y¾°¼»ÉZŀ̈»¹Z¼e,u[Zzf¿Y Dist(1): min { Dist(1),Dist(6)+Cost(6,1) }= Dist(2): min { Dist(2),Dist(6)+Cost(6,2) }= Dist(4): min { Dist(4),Dist(6)+Cost(6,4) }= 1250 Dist(7): min { Dist(7),Dist(6)+Cost(6,7) }= 1150 Dist(8): min { Dist(8),Dist(6)+Cost(6,8) }= 1650  €Ìˆ/»®/Ë{Â/‹Ê/»ÄfyZ‡Ô“Y¾ËYYįɀ̈» {‹[Zzf¿Yž¸“¾Ë€f¿YY,ĸu€»€Å{įd‡Y½MʸYÃ|ËY,ºfË´·Y¾ËY{ YÃ{Z¨f/‡Y |À/‹Z]Ã|/‹®Ë,SÄËYM{…ÂW¹Z¼eÊÀ Ë ºÌ‹Z]Ã{€¯™Zv·Y…ÂW¹Z¼e,€Ìˆ»{įºÌÀ¯¹Z¼eYZ¯ºÌ¿YÂeÊ»Êf«Á   {Â]|ÅYÂyÊ^ˆ¿º¼ÌÀÌ»   ºÌÀ¯Ê»Ã{Z¨f‡YDistÄËYM½{ÁM{Ä]{,É| ]€Ë{Z¬»YÃY¼Åį{Y{Yd̏Zy¾ËY,DistÄËYM   º/ËY{É|/ ]Ä/¬¸uÉY€/]‚/Ì¿½Z/»®ËÁu[Zzf¿YÉY€]½Z»®Ë¹Á{Ĭ¸u¶yY{ d‡YO(n)€]Y€]µÁYĬ¸uʧ€»½Z» ʧ€»½Z»¶Ì¸ve   d‡Y O (n 2 ) ÃÁ€³{ºfË´·Y¾ËYʧ€»½Z» d‡Y O (n 2 ) Ê»Á{Ĭ¸u   É|ˀ³‰ÁÉY€]®Ì‡Ô¯ÉZŵZj» ÁZn»ÉZŽZf‡Yİ˘]ºÌÀ¯ɂ̻M²¿YȬ¿ʸYZf^ˆ¿²¿{Y| e¾Ë€f¼¯Z]ºÌÅYÂyÊ» |ˀ̴]€œ¿{Y½Y€ËYȬ¿ |À‹Z]Äf‹Y{cÁZ¨f»ÉZŲ¿ YÄ/¬˜À»ÉZ/Å€Æ/‹¹Z/¼e,Z/ÅÃ{Zm½{€¯ʗZ]|ÅYÂyÊ»ÉYÃ|À‹Á€§,|ˀ̴]€œ¿{YÉYĬ˜À» {€³ÃÁ{Ã|À‹Á€§ĸXˆ» |À¯Â^ŸZ^°Ë–¬§Á–¬§¥Y€³ž¸“€ÅYÊÀ Ë |‹Z]Ã{¼ÌaYd§Zˆ»¶«Y|u¶¯{İ˘],|ÀÌ^]                QuicksortºfË´·Y Procedure Quicksort ( p,q ) If p < q Then [ j q+1 Partition( p,j ) Quicksort ( p,j-1 ) Quicksort ( j+1,q )] End Procedure partition ( m,p ) v A(m) im Loop Loop i i +1 Until A (i ) v Loop P p-1 Until A ( p ) v If i < p Then interchange ( A(i),A(p) ) Else exit Forever A(m) A(p) A(p) v End {,ºËY|/¿ZÌ]ÃYÄ/]YQuick sortºfËÂ/´·YºÌÅYÂ/z]€³Y |À¯Ê»\e€»É{ ˜Æ]YA(p:q)ÄËYM,Quick sortºfË´·Y Ä/¯º/ËYÄfyY|¿YÃYYQuick sort\Ìe€e¾ËYÄ] ºÌÅ{Ê»Y€«n,qÉZm ºÌÅ{Ê»®ËpÉZm ºÌÀ¯Ê»Y|Y½MʸYÄ»Z¿€]®Ë partitionºfË´·Y,ºfË´·Y¾ËYʸYŠz] d‡YºfË´·Y¾ËYµZ]¸³,AÄËYM,ºËYÃ{€¯‘€§ |À¯Ê»\e€»YɀÀŸnÄËYM d¼/‡Ä]ÄËYMÉY|f]YYi†Ë|¿Y ºÌÀ¯Ê»Ã{Z¨f‡Yi,p†Ë|¿YÁ{Y {€Ì³Ê»€œ¿{Ã|ÀÀ¯Y€§Y€ÀŸ½YÂÀŸÄ]YµÁY€ÀŸ,AÄËYM{   {¼¿½ZÌ]½YÂeÊ»€Ë¶°Œ]Y½MZ¯į d‡Y   ½MÉY|f]Yd¼‡Ä]ÄËYMÉZÆf¿YYp†Ë|¿YÁ|À¯Ê»d¯€uÄËYMÉZÆf¿Y Ä/ËYMÉZ/Æf¿YÄ]|ÀfˆÅ€f³‚]Ã|ÀÀ¯Y€§Y€ÀŸYįÊËZÆ¿M ºÌÀ¯Ê»ĈËZ¬»Ã|ÀÀ¯Y€§Y€ÀŸÊÀ ËvZ]YÄËYM€ZÀŸ†Ë|¿YÁ{¾ËYZ] ¶/v»Ä/]Ĉ/ËZ¬»®/ËZ/]YÃ|/ÀÀ¯Y€§Y€ÀŸdËZÆ¿{ ÄËYMÉY|f]YÄ]|ÀfˆÅ€f°q¯Ã|ÀÀ¯Y€§Y€ÀŸYįÊËZÆ¿MÁºÌÀ¯Ê»¶¬fÀ» €/ZÀŸ¹Z/¼eÁ€f°qÂ/¯Ã|ÀÀ¯Y€§Y€ÀŸYÄËYM{½MY¶^«€ZÀŸ¹Z¼eį{Y{Yd̏Zy¾ËY|Ë|m¶v» ºÌÀ¯Ê»¶¬fÀ»‰|Ë|m Y|/Y‰{Ây¹ÓcZ §{Ä]Quick sort€³YµZu {Y{Y€«\e€»ÄËYM{‰{Ây¶v»{Ád‹Y{€]Y€ÀŸ®ËpartitionÊÀ Ë  {€Ì³Ê»Y€«‰{Ây¶v»{Ã|ÀÀ¯Y€§Y€ÀŸÄ°¸]{‹ʼ¿c‡ÄËYM€´Ë{cZ^ŸÄ] |ÀfˆÅ€f³‚]Ã|ÀÀ¯Y€§Y€ÀŸY½MY| ]   |‹|ÅYÂy\e€»AÄËYM,|¿   1 2 3 4 5 6 7  8 9 70 60 80 45 90 50 10 55  µZj» A  65 75   €/f³‚]Ä/ËYM€/ZÀŸ¹Z/¼eY{|/Ÿ¾/ËY ºÌÅ{Ê»Y€«±‚]{|Ÿ®Ë,AÄËYMY¹Yn +1Ä¿Zy{Quick sortºfË´·YÉY|f]Y{   ºÌÀ¯Ê»Ã{Z¨f‡Y{Z¼¿YºÌ¿Y{ʼ¿Y‰Y|¬»½ÂqZ»Y d‡YZ»ZÌ¿ɳx‡ZaµZj»—Ä],©Â§µZj»{ d‡Y m p v i  1 2 3 4 5 6 7 8 9 10 45 55 60 50 65 90 80 75 70  1 10 65 1 9 2 8 3 7 4 6 5    ÉY€/]ºÌ/À¯Ê»Ê ‡†a {‹Ê»[Zzf¿Ypartition¶yY{{€f»ÁZ]¾ËY€]ZÀ] d‡YʸYŠz]partitionºfË´·Y¾ËY{ ʧ€»½Z»¶Ì¸ve   ºÌÀ¯[Zzf¿Y|ËZ]Y€f»ÁZ]Âf‡{ ºÌÀ¯Y|Ìaʧ€»½Z»partition    ºÌÀ¯Ê»[Zzf¿Y€f»ÁZ]½YÂÀŸÄ]Y€ZÀŸ¾Ì]ĈËZ¬» n +1  n  # n-2 # # (n 1) (n ) (n 2) (n 6) # O (n 2 )   {€Ì³Ê»Y€« O (n 2 ) ÃÁ€³{ºfË´·Y¾ËYʧ€»½Z»ÄnÌf¿{ d/‡|] O (n 2 ) {Â/]¶/»Z¯€/³Y d/‡YŽ«Z¿ʸÌy€œ¿Ä]©Â§Ê]Zˆu|ŸZe ºËÁÊ»ʧ€»½Z»¾ÌÌ eµZ^¿{€eÄ¿ZÀÌ]ž«YÁʼ¯µZu   |f§ZÌ]©Z¨eY|¿YÂeʼ¿įd‡Yʨ¬‡ O (n 2 ) ž«YÁ{ |»MÊ» ®/Ë{Y€/ˁÄ/˜]YºÌ¿YÂ/eÊ/»,T(n)ÉY€/] |/‹Z]ɀ/ÀŸnÄ/ËYM½{€¯\e€»ÉY€]Quick sortʧ€»½Z»T(n)|ÌÀ¯‘€§ 1 n n   ºÌˆËÂÀ]Ä¿ZÀÌ]ž«YÁdÌ “Á T (n ) n 1 T (k 1) T (n k ) k 1 Á¹Á{Ä/¿Zy{ZË,{€Ì³Ê»Y€«µÁYÄ¿Zy{ZËÃ|ÀÀ¯Y€§Y€ÀŸ |f§YÊ»©Z¨eY€ZÀŸ¾Ì]ĈËZ¬»n +1,partitionÊ¿YÂyZ]¾Ì·ÁY{ 1 \ˀ“Ád‡YÃ|‹Äf‹Â¿d·Zun¾ËYY®Ë€Å,¶]Z¬» ¹YnÄ¿Zy{ÀyÓZ]ZË n   |Å{Ê»Z»Ä]Y¾Ì´¿ZÌ»  ¹Á{¶/§{Ã|/‹Ä/f¨³ÉZ/ʼnÁYºÌ¿YÂ/eÊ/» ºÌÀ¯¶uY€¿M|ËZ]įd‡YQuick sortºfË´·YÄ]€›ZÀf»ÊfŒ³Z]ž]Ze,Ę]Y ÉÁYYÄ/Ì·ÁY–ËY€/‹Z/¯€/ŁY¶/^« ºÌ/À¯Ê/»[Z/zf¿YYÉ{»‰ÁZm¾ËY{ ºÌÀ¯¶uY€¿MÉ{»˜]Ä°¿MZËÁºÌÀ¯Ã{Z¨f‡Y T (1) 0 T (0) 0   ºËÁMÊ»d‡|]ºfË´·Y 1 2 T (0) 2 T (1) 2 T (n 1) n n T (n ) n (n 1) 2(T (0) T (1) T ( n 1))   ºËÁÊ»Ę]Y¡Y€‡Ä]µZu T (n ) n 1   {‹Ê»¶Ë|^e€Ë¶°Œ] ºÌÅ{Ê»Y€«n-1,nÉZm d‡YY€«€]nY|¬»€ÅÉYYÄ]©Â§Ę]Y (n 1) T (n 1) (n 1)n 2 T (0) T (1) T (n 2) n T (n ) (n 1) T (n 1) n 2 n 2 T ( n 1) n 2 n n T (n ) 2n (n 1) T ( n 1)  {‹Ê»ÄnÌf¿ ºÌÀ¯Ê»ºÌˆ¬en(n+1)€]YÄ·{Z »¾Ì§€— T (n ) T (n 1) 2 n 1 n n 1 T (n 2) 2 2 T (n 3) 2 2 2 T (1) 2 2 n 1 n n 1 n 2 n 1 n n 1 2 3 n 1 n 1 1 2 k k 3   ºËÁMd‡|]Ê^ˀ¬eŠËY€]ºÌ¿YÂeÊ»ÊÅ{Y|¬»Z] d‡YÊfŒ³Z]Ę]Y®Ë,Ę]Y¾ËY n 1 1 n 1 k k 3 3 1 dx ln(n 1) ln(3) ln(n 1) x T (n ) ln(n 1) T (n ) (n 1) ln(n 1) T (n ) O n log n 2 n 1  ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online