Kormen t algoritmy_postroenie_i_analiz

1,669 views

Published on

Published in: Spiritual, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,669
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Kormen t algoritmy_postroenie_i_analiz

  1. 1. 1 71.1. . . . . . . . . . . . . . . . . . . . . . . . . . 71.2. . . . . . . . . . . . . . . . . . . . . 111.3. . . . . . . . . . . . . . . . . . 151.3.1. . . . . . . . . . 161.3.2. 17I 24252 262.1. . . . . . . . . . . . . . 262.2. . . . . . . . . . 303 393.1. . . . . . . . . . . . . . . . . . . . 393.2. . . . . . . . . . . . . . . . . . . . . . . . . 434 494.1. . . . . . . . . . . . . . . . . . . . . 504.2. . . . . . . . . . . . . . . . . . 534.3. . . . . . . . . . . . . . . . . . . . . . . . 56? 4.4 4.1 . . . . . . . . . . . . . . . 594.4.1. . . . . . . . . . 594.4.2. . . . . . . . 635 715.1. . . . . . . . . . . . . . . . . . . . . . . . . . 715.2. . . . . . . . . . . . . . . . . . . . . . . . . . 765.3. . . . . . . . . . . . . . . . . . . . . . . . . . . 795.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
  2. 2. 25.5.1. . . . . . . . . . 875.5.2. . . 895.5.3. . . . . 916 966.1. . . . . . . . . . . . . . . . . . . . . 966.2. . . . . . . . . . . . . . . . . . . . . . . . . 1026.2.1. . . . 1036.3. . . . . . . . . . . . . 1086.4. . . . . 1136.5. . . . . . . . . . 1186.6. . . . . . . . . . . . . . . . . . . 1236.6.1. . . . . . . . . . . . . . 1236.6.2. . . . . . . . . . . . . . . . . . . . 1256.6.3. . . . . . . . . 126II 1321337 1367.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1367.2. . . . . . . . . . . 1387.3. . . . . . . . . . . . . . . . . . . . . . 1407.4. . . . . . . . . 1437.5. . . . . . . . . . . . . . . . . . 1438 1488.1. . . . . . . . . . . . . . 1488.2. . . . . . . . . . . . . . . . 1518.3. . . . 1558.4. . . . . . . . . . . . . . . . 1578.4.1. . . . . . . . . . . . . 1578.4.2. . . . . . . . . 1589 1669.1. . . . . . . . . . . . . . 1669.2. . . . . . . . . . . . . . . . . . . 1699.3. . . . . . . . . . . . . . . . . . . . 1719.4. . . . . . . . . . . . . . . . 17410 18010.1. . . . . . . . . . . . . . . . . . . 18110.2. . . . . . . . . . . 18210.3. . . . . . . 185
  3. 3. 3III 19219311 19711.1. . . . . . . . . . . . . . . . . . . . . . . 19711.2. . . . . . . . . . . . . . . . . . . . . . 20111.3. 20611.4. . . . . . . . . . . . 21012 - 21712.1. . . . . . . . . . . . . . . . . . . . . . 21712.2. - . . . . . . . . . . . . . . . . . . . . . . . . 21912.3. - . . . . . . . . . . . . . . . . . . . . . . . 22512.3.1. . . . . . . . . . . . . . . . . 22612.3.2. . . . . . . . . . . . . . . . . . . . . . 22712.3.3. . . . . . . . . . . . 22812.4. . . . . . . . . . . . . . . . . . . . 23113 24213.1. ? . . . . . . . . . . 24313.2. . . . . . . . . . . . . . . . . . 24513.3. . . . . . . . . . . . . 248? 13.4 . . . . . . . . . . 25214 - 26214.1. - . . . . . . . . . . . 26214.2. . . . . . . . . . . . . . . . . . . . . . . . . . . 26414.3. . . . . . . . . . . . . . . . . . . . 26714.4. . . . . . . . . . . . . . . . . . . . . . . . . . . 27115 28015.1. . . . . . . . . . 28015.2. 28515.3. . . . . . . . . . . . . . . . . . . . 288IV 29629716 29916.1. . . . . . . . . . . . 30016.2. . 30716.3. . . . . . . 31216.4. . . . . . 317
  4. 4. 417 32617.1. . . . . . . . . . . . . . . . . . . 32617.2. ? . . . . . . . . . . 33017.3. . . . . . . . . . . . . . . . . . . . . . . 333? 17.4 . . . . . . 34117.4.1. . . . . . . . . . . . . . . . . . . . . . 34117.4.2. 343? 17.5 . . . . . . . . . . . . . . . . . . . 34618 35218.1. . . . . . . . . . . . . . . . . . . . . 35318.2. . . . . . . . . . . . . . . . . . . . . 35618.3. . . . . . . . . . . . . . . . . . . . . 35918.4. . . . . . . . . . . . . . . . . . . 36218.4.1. . . . . . . . . . . . . . . . 36218.4.2. . . . . . . 365V 37237319 - 37619.1. - . . . . . . . . . . . . . . . . . . 37919.2. - . . . . . . . . . . . 38119.3. - . . . . . . . . . . . . . 38820 39420.1. . . . . . 39520.1.1. . . . . . . . . . . . . . . 39520.1.2. . . . . . . . . . . . . . . . . 39720.2. . . . . . . . . . . 39920.2.1. . . . . . . . . . . . . . . 40021 41321.1. . . . . . . . . . . . . . 41421.2. , . . . 41621.3. . . . . . . . . 42521.4. . . . . . . . . . . . . . 42922 43422.1. . . . . 43422.2. . . . . . . . . . . . . . 43722.2.1. . . . . . . . . . . . . . . . . . . . . 44123 45223.1. . . . . . . . . . . . . 453
  5. 5. 523.1.1. . . . . . . . . . . . . . . 45323.1.2. . . . . . . . . . . . . . . . . . . 45623.1.3. . . . . . . . . . . . . . . . . . . 46423.1.4. . . . . . . . . . . . 47123.1.5. . . . . . . . . . . . 47324 48124.1. . . . . . . . . . . . 48224.2. . . . . . . . . . . . . . 48625 49325.1. . . . . . . . . . . . . . 49725.2. - . . . . . . . . . . . . . . . 50725.3.. . . . . . . . . . . . . . . . . . . . . . . . . . . . 51025.4. . . . . 51226 52226.1. - . . . . . . . . . . . . . . . 52927 54627.1. . . . . . . . . . . . . . . . . . . . . . . 54727.2. { . . . . . . . . . . . . . . . . 55227.3. . . 56227.4. . . . . . . . . . 56527.5. - - - . . . . . . . . . . . . . . 57428 58628.1. . . . . . . . . . . . . . . . . . . . . 58728.2. . . . . . . . . . . . . . . . . . 59028.3. . . . . . . . . . . . . . . . 59228.4. . . . . . . . . . . . . . . . . . . . . . . 59428.5. . . . . . . . . . . . . . . . . . . . . 59629 60129.1. . . . . . . . . . 60229.1.1. . . . . . . . . . . . 60229.1.2. . . . . . 60329.1.3. . . . . . . . . . . . . . . . . . . . . . 60329.1.4. . . . . . . . . . . . . . . . . . . . 60429.1.5. . . . . . . . . . . . . . . . . . . . 60529.1.6. . . . . . . . . . . . . . . . . . . . . 60529.2. C . . . . . . . . . . . . . . . . . . . 60529.2.1. . . . . . . . . . . . . . . . 60629.2.2. . . . . 60729.2.3. -. . . . . . . . . . . . 608
  6. 6. 629.2.4. :. . . . . . . . . . . . . . . . . . . . . 60929.2.5. . . . . . . 61029.3. . . . . . . . . . . . . . . . . . . 61229.3.1. . . . . . . . . . . . . . 61229.3.2. . . . . . . . . . . . . . . 61429.3.3. . . . . . 61429.3.4. . . . . . . . . . . . . . . 61529.3.5. . . . . . . . . . . . . . . . . . . . . 61629.4. . . . . . . . . . . . . . . . . . . 61729.4.1. . . . . . . . . 61729.4.2. . . . . . . . . . . . . . . 61829.4.3. . . 61829.4.4. . . . . . . . . . . . . 61929.4.5. . . . . . . . . . . . . . . . . 61929.4.6. . . . . . . . . . . . . . . . 62029.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . 62229.6. . . . . . . . . . . . . . . . . . . . . . . . 62330 62530.0.1. -(PRAM) . . . . . . . . . . . . . . . . . . . . 62530.0.2. -. . . . . . . . . . . . . . . . . . . . . . . . . 62630.0.3. . . . . . . . . . . . . . . . . . . 62730.0.4. . . . . . . . . . . . . . . . . . . . . . 62730.1. . . . . . . . . . . . . . . . . . 62830.1.1. . . . . . . . . . . . . . . . . . . 62830.1.2. . . . . . . . . . . . . . . . . . . . 63030.1.3. . . . . . . . . . . . . . . . . . . . . . . . 63030.1.4. . . 63130.1.5. . . . . . . . . . . . . . . 63330.2. CRCW- EREW- . . . . . . . . . . . . . . . 63630.2.1. . . . . . . . . . . 63630.2.2. . . . . . . . . . . . 63730.2.3. CRCW-EREW- . . . . . . . . . . . . . . . . . . 63930.3. . . . . 64230.3.1. . . . . . . . . . . . . . . . . . . . . 64530.4. . . 64530.4.1. 64630.4.2. . . . . . . . . . . . 64730.4.3. . . . . . . . . . . . . . . . . . . . . . . . 64730.4.4. . . . . . . . . . . . . . . . . . . . . 64930.5. ( -) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
  7. 7. 730.5.1. -. . . . . . . . . . . . . . . . . . . . . . . 65030.5.2. 6- . . . . . . . . . . . . . 65130.5.3. -6- . . . . . . . . . . . . . . 65330.5.4. . . . . . . . . . . . . . . . . . . . . 65430.6. . . . . . . . . . . . . . . . . . . . . . . . . . . . 65430.7. . . . . . . . . . . . . . . . . . . . . . . . 65731 65931.1. . . . . . . . . . . . . . . . . . 65931.2. . . . . . . . 66831.3. . . . . . . . . . . . . . . . . . . . . 67531.4. -. . . . . . . . . . . 67933 p - p 71233.1. . . . . . . . . . . 71333.2. . . . . . . . . . . . . . . 71833.3. . . . . . . . . . . . . . . . . . 72233.4. . . . . . . 72633.5. . . . . . . . . . . . . . 72933.6. . . . . . . . . . . . . . . . . . . . . . 73233.7. RSA . . . . . . . 73533.8. . . . . . . . . . . . . . . . 74134 75734.0.1. . . . . . . . . . . 75834.1. . . . . . . . . . . . . . . . . . . 75934.2. | . . . . . . . . . . . . . . . 76134.2.1. . . . . . . . . . . . . . . . . . . . . 76434.3. . . . 76534.3.1. . . . . . . . . . . . . . . . 76534.3.2. . . . . . . . . . 76634.3.3. . . . . . . . . . 77034.4. | | . . . . . . . . 77134.4.1. - , 77134.4.2. . . . . . . . . . . . . . . . . . . . 77334.4.3. - . . 77434.4.4. KMP . . . . . . . . . . . . 77634.5. | . . . . . . . . . . . . . . . . 77734.5.1. - . . . . . . . . . . . . . 77834.5.2. . . . . . . . . 78034.5.3. . . . . . . . . . . . . . . . . . . . . 78434.6. . . . . . . . . . . . . . . . . . . . . . . . . . 785
  8. 8. 835 78735.1. . . . . . . . . . . . . . . . . . . . . 78835.2. ? . . . . . . . . . . . 79335.3. . . . . . . . . . . . . . 79835.4. . . . . . . . . . . . 80435.5. . . . . . . . . . . . . . . . . . . . . . . . . . . . 80736 NP- 81136.1. . . . . . . . . . . . . . . . . . . 81236.2. NP . . . . . 81936.3. NP- . . . . . . . . . . . . . . . . 82436.4. NP- . . . . . . . . . . . . . . . . . . . . . 83736.4.1. . . . . . . . . . . . . . . . . . . . 83736.4.2. . . . . . . . . . 83936.4.3. . . . . . . . . . 84236.4.4. . . . . . . . . . . . . . . 84637 85037.1. . . . . . . . . . . . . . 85237.2. . . . . . . . . . . . . . . . . . . 85437.2.1. ( -) . . . . . . . . . . . . . . . . . . . . . 85437.2.2. . . . . . . . . . . 85637.3. . . . . . . . . . . . . . . 863
  9. 9. -. -,.-.260 , .-., -| .-.:-|-. ,, ..,. -,.( 900): -( 120). ,(| , -
  10. 10. 10).-, .. ---.:, -., , -., -, ., , ,. ,, ,., ? ,, -,( ,) ( - -).:-. ,.-, -. -, -.-, . ,- ( -. .), .
  11. 11. 11.,, .( , -, ). :Introduction to AlgorithmsMIT Labratory for Computer Science545 Technology SquareCambridge, Massachusetts 02139-,algorithms@theory.lcs.mit.edu , Subject:help . ,., -( 1997), , -, , , -( , . )., , -: , !, algor@mccme.ru( , 121002, ., 11,, ).]. -.(Massachusetts Institute of Technology, Laboratory forComputer Science) -. -. :Baruch Awerbuch, Sha Goldwasser, Leo Guibas, Tom Leighton, Al-bert Meyer, David Shmoys, Eva Tardos. , -( : Microvax, Apple Macintosh, Sun Sparc-station) William Ang, Sally Bemus, Ray HirschfeldMark Reinhold TEX, -.Thinking Machines
  12. 12. 12.,. -: Richard Beigel (Yale), Andrew Goldberg (Stanford), JoanLucas (Rutgers), Mark Overmars (Utrecht), Alan Sherman (Tufts,Maryland), Diane Souvaine (Rutgers).-, . -: Alan Baratz, Bonnie Berger, Aditi Dhagat, Burt Kaliski,Arthur Lent, Andrew Moulton, Marios Papaefthymiou, Cindy Phillips,Mark Reinhold, Phil Rogaway, Flavio Rose, Arie Rudich, Alan Sher-man, Cli Stein, Susmita Sur, Gregory Troxel, Margaret Tuttle.-: (Denise Sergent),(Maria Sensale), (Al-bert Meyer), (Shlo-mo Kipnis, Bill Niehaus, David Wilson), (MariosPapaefthymiou, Gregory Troxel), (Inna Radzi-hovsky, Denise Sergent, Gayle Sherman, Be Hubbard)., BobbyBlumofe, Bonnie Eisenberg, Raymond Johnson, John Keen, RichardLethin, Mark Lillibridge, John Pesaris, Steve Ponzio, Margaret Tuttle., -Bill Aiello, Alok Aggrawal, Eric Bach,Vasek Chvatal, Richard Cole, Johan Hastad, Alex Ishii, David Johnson,Joe Kilian, Dina Kravets, Bruce Maggs, Jim Orlin, James Park, ThanePlambeck, Herschel Safer, Je Shallit, Cli Stein, Gil Strang, Bob Tar-jan, Paul Wang., Andrew Goldberg, Danny Sleator, Umesh Vazirani.LATEX( TEX). -Apple Macintosh Mac Draw II -(Joanna Terry, Claris Corporation Michael Mahoney, Advanced Com-puter Graphics).Windex, . -BibTEX. --Autologic(Ralph Youngen,). : Rebecca Daw, Amy Henderson ( -LATEX), Jeannet Leendertse ( ).-MIT Press (Frank Sallow, Terry Ehling, Larry Cohen,
  13. 13. 13Lorrie Lejeune) McGraw-Hill (David Shapiro),(Larry Cohen)., (Nicole Cormen, Lina LueLeicerson, Gail Rivest) (Ricky, William Debby LeicersonAlex Christopher Rivest)(Alex Rivest( 6.6.1). ,.,1990(Thomas H. Cormen)(Charles E. Leiserson)(Ronald L. Rivest):MIT, ( -).-( . . ).-, -,:K. , . , . , . , .. , . , . , . , . -, . , . , . , . , .( ). , . , . , . , . -, . , . . , A. ( -). ( ). . ( )
  14. 14. 1,, -|.,, -, -, ,.1.1.(algorithm) | -, (input),, -(output).(computational problems). ,, -, , ,.(sorting prob-lem)-. :: n (a1 a2 ::: an).: (a01 a02 ::: a0n) -, a01 6 a02 6 ::: 6 a0n., h31 41 59 26 41 58i, -h26 31 41 41 58 59i.(instance) .
  15. 15. 15-.-, , ,( , ,).(correct), -( ), ., (solves) -. () .( , |.33 ., .),|, .(pseu-docode), -( , , ). ,, -. , -( , ),, .(insertion sort) -. -:,, ( . . 1.1)Insertion-Sort, -A 1::n] (n, ). -A length A].(in place), ().Insertion-Sort A.
  16. 16. 16 1. 1.1Insertion-Sort(A)1 for j 2 to length A]2 do key A j]3 . A j] A 1::j ;1].4 i j ;15 while i > 0 and A i] > key6 do A i+ 1] A i]7 i i;18 A i + 1] key. 1.2 Insertion-Sort A = h5 2 4 6 1 3i. -j .. 1.2 A = h5 2 4 6 1 3i.j ( -). A 1::j ; 1]( ), A j + 1::n] | . forj . A j]
  17. 17. 17( 2 )( j ; 1- ) , -. ( 4{7). 8 A j]., :1. ., for ( 1) 2{8, -while ( 5) 6{7, 8.if-then-else. -begin end . (-, ,.)2. while, for, repeat if, then, else, .3. . ( ).4. i j e ( i je) j e i j ().5. ( i j key) -( ).6. : A i] i-A. :: : A 1::j]A, A 1] A 2] ::: A j].7. (objects), -( elds), , , -(attributes).]. ,length, Alength A].( ), ., , -. y xf f y] = f x]. ,f x] 3, f x] = 3,f y] = 3, y x x y.nil, -.8. (by value): --. -
  18. 18. 18 1, ,| . , x | -, x y, ,, f x] 3 | .1.1-1 . 1.2, ,Insertion-Sort A = h31 41 59 26 41 58i.1.1-2 Insertion-Sort , -( -).1.1-3 :: n A = ha1 a2 ::: ani v.: i, v = A i],nil, v A.(linear search),A v.1.1-4 n- ,n- A B. () (n+1)- C. --.1.2.-, , -( , ), -. , , -.(random-access machine, RAM), -. ( --.):-: ,
  19. 19. 19. -. ( ,, :, .)(input size)? -.( , ). -, -. -, ( ,).(running time), |, . ,-( - -| x- ).(call) () (execution),., Insertion-Sort( ) , -. j 2 n (n = length A] | ) ,5, tj. ( ,, -, .)Insertion-Sort(A)1 for j 2 to length A] c1 n2 do key A j] c2 n ;13 . A j] -. A 1::j ;1]. 0 n ;14 i j ;1 c4 n ;15 while i > 0 and A i] > key c5Pnj=2 tj6 do A i+ 1] A i] c6Pnj=2(tj ; 1)7 i i; 1 c7Pnj=2(tj ; 1)8 A i+ 1] key c8 n ;1c, m , cm -. (
  20. 20. 20 1!) ,T(n) = c1n+ c2(n; 1)+ c4(n ; 1)+ c5nXj=2tj ++ c6nXj=2(tj ; 1)+ c7nXj=2(tj ;1) + c8(n;1):,n, , n .Insertion-Sort , -. 5( A i] 6 key i = j ;1),tj 1,T(n) = c1n+ c2(n; 1)+ c4(n ; 1)+ c5(n;1) + c8(n;1) == (c1 + c2 + c4 + c5 + c8)n;(c2 + c4 + c5 + c8):, T(n), -n,(linear function) n, . . T(n) = an + ba b. ( -c1 ::: c8.)( ) ,:A j] A 1]:::A j ; 1].tj = j. ,nXj=2j = n(n + 1)2 ;1nXj=2(j ;1) = n(n ;1)2( . . 3), ,T(n) = c1n + c2(n ;1)+ c4(n; 1)+ c5n(n + 1)2 ; 1 ++ c6n(n ; 1)2 + c7n(n;1)2 + c8(n ; 1) == c52 + c62 + c72 n2 + c1 + c2 + c4 + c52 ; c62 ; c72 + c8 n ;; (c2 + c4 + c5 + c8):T(n) | (quadratic function), . .T(n) = an2 + bn + c. ( a, b c -c1{c8.)
  21. 21. 21, ,. -(worst-case running time),. ? ., ,, -, ( ) .( -) . ,( ).. , , -n Insertion-Sort. 5{8?A 1::j ; 1]A j], tj j=2, -T(n) n.-(average-case running time, expexted running time) -. ,( -), -. (, .)Insertion-Sort., i- -ci. an2+bn+c.,(rate of growth, order of growth) n2, -( )n2. : T(n) = (n2) ().: , ,(n2), | (n3), (| ).
  22. 22. 22 11.2-1 n :,., .(selection sort). -., - .1.2-2 ( . 1.1-3).,( -)?? - ?1.2-3 x1 x2 ::: xn. ,(nlogn) , -.1.2-4 a0 a1 ::: an;1x. -, (n2).(n), ?:n;1Xi=0aixi = (:::(an;1x + an;2)x+ :::+ a1)x + a0:1.2-5 n3=1000; 100n2 ; 100n + 3 -- ?1.2-6 , -. ?1.3., -. -, (incremental approach): -., -(divide-and-conquer approach),.
  23. 23. 231.3.1.(recursive algorithms):,.. -. (| , ). -,.. -. -.-. -, (1 )..Merge(A p q r). -A p q r,. , p 6 q < rA p::q] A q + 1::r] , (merges)A p::r].( . 1.3-2), , Merge(n), n | (n = r;p+1).. ,.?( ). , -. , -, (n).Merge-Sort(A p r),A p::r] A, -. p > r, .q,A p::q] ( dn=2e ) A q + 1::r]( bn=2c ). bxcx ( , x),dxe | , x.
  24. 24. 24 1sorted sequence |merge |initial sequence |. 1.3 A = h5 2 4 6 1 3 2 6i.Merge-Sort(A p r)1 if p < r2 then q b(p + r)=2c3 Merge-Sort(A p q)4 Merge-Sort(A q + 1 r)5 Merge(A p q r)Merge-Sort(A 1 length A]). n = length A],2,4n (n=2). . 1.3.1.3.2.? -, -,(recurrence equation). ,.. ,n a , -b . ,D(n), | C(n).
  25. 25. 25T(n)n ( ): T(n) = aT(n=b) + D(n) + C(n).n,. n,, - -. n ,., (n). ( 4, -.). ( )(1), | (n). -T(n) =((1) n = 1,2T(n=2)+ (n=2) n > 1.4, T(n) =(nlogn), log ( -, , ,). n -,(n2).1.3-1 . 1.3, -A = h3 41 52 26 38 57 9 49i.1.3-2 Merge(A p q r).1.3-3 ,T(n) =(2 n = 2,2T(n=2)+ n n = 2k k > 1,T(n) = nlogn ( n, ).1.3-4: A 1::n], ( ) -A 1::n ; 1], A n] -A 1::n;1]. -.
  26. 26. 26 11.3-5 ( . 1.1-3), ,, ,, -. (binary search)., -. , (logn).1.3-6 , while 5{7Insertion-Sort ( . 1.1) -A 1::j ; 1] .( . 1.3-5),(logn).(nlogn)?1.3-7? S n ,x. (nlogn) , xS?, -| .: , , -, : -.-, ..| (100 -)(1 )? -, n, , 2n2 .50nlogn.2 (106)2108 = 20000 5 5650 (106)log(106)106 1000 17., |, -. .
  27. 27. 1 271.3-18n2 64nlogn .n -? ?1.3-2 n ,100n2 , , 2n ?1-1, n f(n). ,t? , -.1 1 1 1 1 1 1lognpnnnlognn2n32nn!1-2, n ., -. ,.. n k n=k. -, () (nk).. , -(nlog(n=k))..(nk+nlog(n=k)). kn, - (nlogn)?. k -
  28. 28. 28 1?1-3A 1::n] | n . -(inversions) , . .i < j, A i] > A j].. h2 3 8 6 1i.. -n?.? .. , -n (nlogn). ( : -.).: , 4,5], 14], -14], 105], 121, 122, 123],142], 144, 145, 146], 164], -, 167], 175], 201]. -:24,25], 90].1968 -121, 122, 123],.., -- (al-Khow^arizm^, al-Khw^arizm^)., 4] --. -.123] -. -, (). -, (D.L.Shell),-.,, -1938 . -
  29. 29. 1 29, (J. von Neumann), -,EDVAC 1945 .
  30. 30. I
  31. 31. , -.,.2 , -( .), .- , -.3( -).4. -( 4.1),. ,, -.5 ,, , , ,.6. -, () ,.
  32. 32. 21, ,( ) -n2, ( ) | nlgn.,n ., -.,(asymp-totic e ciency). ,,, . ( .)2.1.-, .-2 , T(n) -n (n2). -: c1 c2 > 0n0, c1n2 6 T(n) 6 c2n2 n > n0. ,g(n) | , f(n) = (g(n)) ,c1 c2 > 0 n0, 0 6 c1g(n) 6 f(n) 6 c2g(n)n > n0 ( . . 2.1). ( f(n) = (g(n)) :.)!!!!!!!!! 2.1 - : ]f(n) = (g(n)), f(n) = O(g(n))f(n) = (g(n))., -: , f1(n) = (g(n)) f2(n) = (g(n)),
  33. 33. 33, f1(n) = f2(n)!(g(n)) , f(n) g(n), . . -n. , f g -, n0 (c1 c2 , n -).f(n) = (g(n)), , g(n) -f(n).: f(n) = (g(n)), g(n) = (f(n)).1 , (1=2)n2 ; 3n =(n2). , -c1 c2 n0 ,c1n2 6 12n2 ;3n 6 c2n2n > n0. n2:c1 6 12 ; 3n 6 c2,c2 = 1=2. , ( ) n0 = 7 c1 =1=14.: -, 6n3 6= (n2). , c2 n0,6n3 6 c2n2 n > n0. n 6 c2=6 n > n0| ., -,n . -,( c1 c2). -, f(n) = an2 + bn + c,a b c | a > 0. -, ,f(n) = (n2). , -c1 = a=4, c2 = 7a=4 n0 = 2 max((jbj=a)pjcj=a) ( ,). ,p(n) d -p(n) = (nd) ( 2-1).-: (1) , -. (, .)
  34. 34. 34 2O- -f(n) = (g(n)) :. . , f(n) = O(g(n)),c > 0 n0, 0 6 f(n) 6cg(n) n > n0 , f(n) = (g(n)),c > 0 n0, 0 6 cg(n) 6 f(n)n > n0. :, .- , f g -.( . 2.1-5), :2.1. f(n) g(n) f(n) =(g(n)) , f(n) = O(g(n))f(n) = (g(n)).f(n) = O(g(n)) g(n) =(f(n)) ., an2 + bn + c = (n2) ( a).an2 + bn + c = O(n2). : a > 0an + b = O(n2) ( c = a + jbj n0 = 1). ,an + b 6= (n2 an + b 6= (n2).( , O ). , 1T(n) = 2T(n=2)+ (n). (n), ,c1n c2n c1c2 n., -. ,nXi=1O(i)h(1) + h(2) + :::+ h(n), h(i) |, h(i) = O(i). ,n O(n2).-| 2n2 + 3n + 1 = 2n2 + (n) =(n2). (2n2 + (n) = (n2)): h(n) = (n), 2n2 + h(n) (n2).
  35. 35. 35o- !-f(n) = O(g(n)) , nf(n)=g(n) .limn!1f(n)g(n) = 0 (2.1)f(n) = o(g(n)) (). , f(n) = o(g(n))," > 0 n0, 0 6 f(n) 6 "g(n)n > n0. ( f(n) = o(g(n)) ,f(n) g(n) n.): 2n = o(n2), 2n2 6= o(n2).!- : ,f(n) !(g(n)) ( ), -c n0, 0 6cg(n) 6 f(n) n > n0. , f(n) = !(g(n)), g(n) = o(f(n)).: n2=2 = !(n), n2=2 6= !(n2)., ::f(n) = (g(n)) g(n) = (h(n)) f(n) = (h(n)),f(n) = O(g(n)) g(n) = O(h(n)) f(n) = O(h(n)),f(n) = (g(n)) g(n) = (h(n)) f(n) = (h(n)),f(n) = o(g(n)) g(n) = o(h(n)) f(n) = o(h(n)),f(n) = !(g(n)) g(n) = !(h(n)) f(n) = !(h(n)).:f(n) = (f(n)), f(n) = O(f(n)), f(n) = (f(n)).:f(n) = (g(n)) g(n) = (f(n)).:f(n) = O(g(n)) g(n) = (f(n)),f(n) = o(g(n)) g(n) = !(f(n)).:f g a b:f(n) = O(g(n)) a 6 bf(n) = (g(n)) a > bf(n) = (g(n)) a = bf(n) = o(g(n)) a < bf(n) = !(g(n)) a > b
  36. 36. 36 2, , : -. ,a b a 6 b, a > b, -, ( ) f(n) g(n)f(n) = O(g(n)), f(n) = (g(n)). , -,f(n) = n g(n) = n1+sinn (g(n) 0 2). , -a 6 b a < b a = b,f(n) = O(g(n)) f(n) = o(g(n)) f(n) = (g(n)).2.1-1 f(n) g(n)n. , max(f(n) g(n)) = (f(n) + g(n)).2.1-2 ,(n+ a)b = (nb) (2.2)a b > 0.2.1-3 A -O(n2) ?2.1-4 , 2n+1 = O(2n)? 22n = O(2n)?2.1-5 2.1.2.1-6 f(n) g(n),f(n) = O(g(n)), f(n) 6= o(g(n)) f(n) 6= (g(n)).2.1-7 , f(n) = o(g(n)) f(n) = !(g(n)).2.1-8, . ,f(m n) = O(g(m n)), n0, m0 c,0 6 f(m n) 6 cg(m n) n > n0 m > m0.(g(m n)) (g(m n)).2.2., f(n) (is monoton-ically increasing), f(m) 6 f(n) m 6 n. ,
  37. 37. 37f(n) (is monotonically decreasing), -f(m) > f(n) m 6 n. , f(n)(is strictly increasing), f(m) < f(n) m < n., f(n) (is strictly decreasing),f(m) > f(n) m < n.x bxc (the oor of x), . . , -x. dxe (the ceiling of x) -, x. ,x;1 < bxc 6 x 6 dxe < x+ 1x. ,dn=2e+ bn=2c = nn. , xa bddx=ae=be = dx=abe (2.3)bbx=ac=bc = bx=abc (2.4)( , , zn n 6 z n 6 bzc ).x 7! bxc x 7! dxe .( ) d n (polyno-mial in n of degree d)p(n) =dXi=0aini(d | ). a0 a1 ::: ad(coe cients) . , -ad ( , d| , -).n p(n)(
  38. 38. 38 2), ad > 0 p(n) -( n) p(n) =(nd).a > 0 n 7! na , a 60 | . , f(n) -, f(n) = nO(1), , ,f(n) = O(nk) k ( . . 2.2-2).m, n a 6= 0a0 = 1 (am)n = amna1 = a (am)n = (an)ma;1 = 1=a aman = am+n:a > 1 n 7! an .00 = 1.n 7! an , -(exponential). a > 1: b,limn!1nban = 0 (2.5), , nb = o(an). -e = 2 71828:::,ex = 1 + x + x22!+ x33!+ ::: =1Xk=0xkk!(2.6)k! = 1 2 3 ::: k ( . ).xex > 1 + x (2.7)x = 0. jxj 6 1ex :1 + x 6 ex 6 1 + x + x2 (2.8), ex = 1 + x + (x2) x ! 0,( n ! 1x ! 0).x limn!1;1+ xnn = ex.
  39. 39. 39:lgn = log2 n ( ),lnn = loge n ( ),lgk n = (lgn)klglgn = lg(lgn) ( ).,,lgn+k lg(n)+k ( lg(n+k)). b > 1 n 7! logb n( n) .a > 0, b > 0, c > 0n ( 1):a = blogb alogc(ab) = logc a + logc blogb an = nlogb alogb a = logc alogc blogb(1=a) = ;logb alogb a = 1loga balogb c = clogb a(2.9),O(logn) , -.( , )lg.(jxj < 1):ln(1+ x) = x ; x22 + x33 ; x44 + x55 ;:::x > ;1x1 + x 6 ln(1+ x) 6 x (2.10)x = 0., f(n) (is poly-logaritmically bounded), f(n) = lgO(1) n. (2:5) -n = lgm a = 2climm!1lgb m(2c)lgm = limm!1lgb mmc = 0, , lgb n = o(nc) c > 0. -, -.
  40. 40. 40 2n! ( , n factorial")1 n. 0! = 1, n! =n (n; 1)! n = 1 2 3 :::., n! 6 nn ( -n). (Stirlingsapproximation), ,n! =p2 n nen(1+ (1=n)) (2.11),n! = o(nn)n! = !(2n)lg(n!) = (nlgn)::p2 n nen6 n! 6p2 n nene1=12n: (2.12)log n () : (iter-ated logarithm). . -i- , lg(i), :lg(0) n = n lg(i)(n) = lg(lg(i;1) n) i > 0. (, lg(i;1) n .) -: lgi n lg(i) n ,.lg n i > 0, -lg(i) n 6 1. , lg n | ,lg, n , -1.lg n :lg 2 = 1lg 4 = 2lg 16 = 3lg 65536 = 4lg 265536 = 5:-1080, 265536, n,lg n > 5, .
  41. 41. 41(Fibonacci numbers) -:F0 = 0 F1 = 1 Fi = Fi;1 + Fi;2 i > 2 (2.13),0 1 1 2 3 5 8 13 21 34 55 :::.(goldenratio) ^: = 1 +p52 = 1 61803:::^ = 1 ;p52 = ;0 61803:::(2.14),Fi = i ; ^ip5(2.15)( . 2.2-7). j^j <1, j^i=p5j 1=p5 < 1=2, Fii=p5, .Fi ( ) i.2.2-1 , f(n)g(n) f(n) + g(n) f(g(n)) -. f(n) g(n) n,f(n)g(n) .2.2-2 , T(n) = nO(1) ,k, T(n) = O(nk) ( ,T(n) > 1).2.2-3 (2.9).2.2-4 , lg(n!) = (nlgn) n! = o(nn).2.2-5? dlgne! ?dlglgne! ?2.2-6? ( n): lg(lg n) lg (lgn)?
  42. 42. 42 22.2-7 (2.15).2.2-8 : Fi+2 > ii > 0 ( | ).2-1p(n) = a0+a1n+:::+adnd | d,ad > 0. ,. p(n) = O(nk) k > d.. p(n) = (nk) k 6 d.. p(n) = (nk) k = d.. p(n) = o(nk) k > d.. p(n) = !(nk) k < d.2-2, A O, o, , ! B(k > 1, " > 0, c > 1 | ).A B O o !. lgk n n". nk cn.pn nsinn. 2n 2n=2. nlgm mlgn. lg(n!) lg(nn)2-3. 30 -( O( )) , -( ):lg(lg n) 2lg n (p2)lgn n2 n! (lgn)!(3=2)n n3 lg2 n lg(n!) 22nn1=lgnlnlnn lg n n 2n nlglgn lnn 12lgn (lgn)lgn en 4lgn (n+ 1)!plgnlg lgn 2p2lgn n 2n nlgn 22n+1. f(n), -gi (f(n) O(gi(n))gi(n) O(f(n))).
  43. 43. 2 432-4f(n) g(n) -n. ,. f(n) = O(g(n)), g(n) = O(f(n))?. f(n) + g(n) = (min(f(n) g(n)))?. f(n) = O(g(n)) lg(f(n)) = O(lg(g(n))), lg(g(n)) > 0f(n) > 1 n?. f(n) = O(g(n)) 2f(n) = O(2g(n))?. f(n) = O((f(n))2)?. f(n) = O(g(n)) g(n) = (f(n))?. f(n) = (f(n=2))?. f(n) + o(f(n)) = (f(n))?2-5- -. 1 ,. f(n) g(n) | -. , f(n) = 1(g(n)),c, f(n) > cg(n) > 0 -n.. , f(n) g(n), -n, f(n) = O(g(n)),f(n) = 1(g(n)),(g(n)) .. -1 ?f(n) = O(g(n)) , -f(n) . -O0 , f(n) = O0(g(n)),jf(n)j = O(g(n)).. -2.1?:, f(n) = ~O(g(n)),c k, 0 6 f(n) 6 cg(n)lgk nn.. ~ ~2.1.2-6,. f(n) |, f(n) < n. f(i)(n), f(0)(n) = nf(i)(n) = f(f(i;1)(n)) i > 0.c fc (n) -
  44. 44. 44 2i > 0, f(i)(n) 6 c. ( , fc |f, n, c.) , fc (n).f(n) cfc :f(n) c fc (n). lgn 1. n ;1 0. n=2 1. n=2 2.pn 2.pn 1. n1=3 2. n=lgn 2121], O- -(P. Bachmann, 1892). -o(g(n)) (E. Landau) 1909 -.- - 124]: -O- ( -). .121, 124] 33].-, , , ., -n ( )., -: 1], 27].( ., , 12]192]). 121] -, -.
  45. 45. 3(for, while),. , -1.2, j-, j.nXj=1j(n2).( , 4 ).3.1 .3.2 --.3.1.a1 + a2 + :::+ annXk=1ak:n = 0 0., |. ( , .).(series)a1 + a2 + a3 + ::: 1Xk=1ak
  46. 46. 46 3limn!1nXk=1ak:, , (di-verges) .P1k=1 jakj -,P1k=1 ak (absolutelyconvergent series) ,. -.,nXk=1(cak + bk) = cnXk=1ak +nXk=1bkca1 ::: an b1 ::: bn.,.nXk=1k = 1 + 2+ :::+ n,(arithmetic series). -nXk=1k = 12n(n + 1) = (3.1)= (n2): (3.2)x 6= 1 (geometric ex-ponential series)nXk=0xk = 1 + x + x2 + :::+ xn
  47. 47. 47nXk=0xk = xn+1 ;1x;1 : (3.3)(jxj < 1)1Xk=0xk = 11; x: (3.4)1+1=2+1=3+:::+1=n+::: n-(nth harmonic number)Hn = 1 + 12 + 13 + :::+ 1n =nXk=11k = lnn + O(1): (3.5)-, . , -(3.4) x,1Xk=0kxk = x(1;x)2: (3.6)a0 a1 ::: an -nXk=1(ak ; ak;1) = an ; a0 (3.7)( ). - -telescoping series. ,n;1Xk=0(ak ; ak+1) = a0 ; an:
  48. 48. 48 3Pn;1k=11k(k+1). -1k(k+1) = 1k ; 1k+1, ,n;1Xk=11k(k + 1)=n;1Xk=11k ; 1k + 1= 1 ; 1n:a1 ::: annYk=1ak:n = 0 defn (product) -1. :lgnYk=1ak =nXk=1lgak:3.1-1Pnk=1(2k ; 1).3.1-2? , -,Pnk=1 1=(2k ; 1) = ln(pn) + O(1).3.1-3? ,P1k=0(k ;1)=2k = 0.3.1-4? P1k=1(2k + 1)x2k.3.1-5 ,O-.3.1-6 , --.3.1-7Qnk=1 2 4k.3.1-8? Qnk=2(1 ;1=k2).
  49. 49. 493.2., -( ).,. : ,Sn =Pnk=1 k n(n+1)=2. n =1 . , Sn = n(n + 1)=2n n + 1. ,n+1Xk=1k =nXk=1k + (n+ 1) = n(n+ 1)=2+ (n+ 1) = (n+ 1)(n+ 2)=2:. , -,Pnk=0 3k O(3n)., ,Pnk=0 3k 6 c 3nc ( ). n = 0P0k=0 3k = 1 6c 1 c > 1.n, n + 1. :n+1Xk=03k =nXk=03k + 3n+1 6 c3n + 3n+1 = 13 + 1c c3n+1 6 c3n+1:, (1=3+ 1=c) 6 1, . . c > 3=2.Pnk=0 3k = O(3n), ., -, -. ,Pnk=1 k = O(n). ,P1k=1 k = O(1). -n, n. ,n+1Xk=1k =nXk=1k + (n+ 1) = O(n)+ (n+ 1) !]= O(n+ 1):, ,O(n), n.,( ,
  50. 50. 50 3). , -Pnk=1 knXk=1k 6nXk=1n = n2:nXk=1ak 6 namaxamax | a1 ::: an.|. ,Pnk=0 ak , ak+1=ak 6 rk > 0 r < 1. ak 6 a0rk,:nXk=0ak 61Xk=0a0rk = a01Xk=0rk = a011 ;r:P1k=1 k3;k.1=3,(k + 1)3;(k+1)k3;k = 13k + 1k 6 23k > 1. ,(1=3)(2=3)k,1Xk=1k3;k 61Xk=11323k= 1311; 23= 1:, 1,r < 1,. , (k + 1)-k- kk+1 < 1.1Xk=11k = limn!1nXk=11k = limn!1 (lgn) = 1:r,.
  51. 51. 51. Pnk=1 k. -,Pnk=1 k > n.O(n2) , -:nXk=1k =n=2Xk=1k +nXk=n=2+1k >n=2Xk=10 +nXk=n=2+1n2= n22:(, , -).-, ( k0)nXk=0ak =k0Xk=0ak +nXk=k0+1ak = (1)+nXk=k0+1ak:, 1Xk=0k22k(k + 1)2=2k+1k2=2k = (k + 1)22k21. ,, .(k > 3) 8=9,1Xk=0k22k =2Xk=0k22k +1Xk=3k22k 6 O(1)+ 981Xk=089k= O(1)|.-. , ,Hn =Pnk=11k. 1 n blgnc -1+(1=2+1=3)+(1=4+1=5+1=6+1=7)+:::.1 ( ), -blgnc + 1 ( ). ,1+ 1=2+ 1=3+ :::+ 1=n 6 lgn + 1: (3.8)
  52. 52. 52 3fPnk=m f(k) :nZm;1f(x)dx 6nXk=mf(k) 6n+1Zmf(x)dx: (3.9), . 3.1, ( -) ( -) ( ). -f:n+1Zmf(x)dx 6nXk=mf(k) 6nZm;1f(x)dx: (3.10):nXk=11k >n+1Z1dxx = ln(n + 1) (3.11)( )nXk=21k 6nZ1dxx = lnnnXk=11k 6 lnn + 1: (3.12)3.2-1 ,Pnk=11k2 -( n).3.2-2blgncXk=0dn=2ke:
  53. 53. 53. 3.1Pnk=m f(k) . -... ( ) ,Rnm;1f(x)dx 6 Pnk=m f(k). ( ) -, ,Pnk=m f(k) 6 Rn+1m f(x)dx.
  54. 54. 54 33.2-3 , , n-(lgn).3.2-4Pnk=1 k3 .3.2-5 --(3.10)?3-1( r > 0 s > 0 ):.Pnk=1 kr..Pnk=1 lgs k..Pnk=1 kr lgs k.121] |.( -12] 192]).
  55. 55. 4, -,-. (recur-rences). , 1, -Merge-SortT(n) =((1) n = 1,2T(n=2)+ (n) n > 1.(4.1)( ), T(n) = (nlgn).,, . . (O ) . - , ,, -( , substitutionmethod). - , ,, (, iteration method). , -T(n) = aT(n=b)+ f(n)a > 1, b > 1 | , f(n) | -. -(master theorem). -,.-, ., Merge-
  56. 56. 56 4Sort (T(n) -n):T(n) =((1) n = 1,T(dn=2e)+ T(bn=2c)+ (n) n > 1.(4.2), ,, T(n) = (1) n. , -(4.1)T(n) = 2T(n=2)+ (n): (4.3), ( T(1)) -,T(n)., , -, ( ) ,., ,( . 4.1 4.5).4.1.: ., ,., -. ,T(n) = 2T(bn=2c)+ n (4.4)(4.2) (4.3). , T(n) =O(nlgn), . . T(n) 6 cnlgn c > 0. -. bn=2c, . .T(bn=2c) 6 cbn=2clg(bn=2c). ,T(n) 6 2(cbn=2clg(bn=2c))+ n 66 cnlg(n=2)+ n = cnlgn ;cnlg2 + n = cnlgn ;cn+ n 66 cnlgn:c > 1.-, . . n. -, n = 1 -, c ( lg1 = 0). -,
  57. 57. 57n, . c ,T(n) 6 cnlgn n = 2 n = 3. n, n = 1( bn=2c > 2 n > 3).?. -..T(n) = 2T(bn=2c+ 17) + n:(4.4) 17. , , -: nbn=2c + 17 bn=2c ., T(n) = O(nlgn) ,( . . 4.1-5).. -, . , -(4.1) T(n) = (n) (n), T(n) = O(n2) (). -,, .,. ,..T(n) = T(bn=2c)+ T(dn=2e)+ 1:, T(n) = O(n). -. , , , T(n) 6 cn -c.T(n) 6 cbn=2c+ cdn=2e+ 1 = cn+ 1c T(n) 6 cn.,O(n2), :
  58. 58. 58 4, ,.: T(n) 6 cn;b -b c.T(n) 6 (cbn=2c;b)+ (cdn=2e;b)+ 1 = cn; 2b+ 1 6 cn;bb > 1. -c .:, ( ) , -? |,.:T(n) = O(n)(4.4). , T(n) 6 cn, -T(n) 6 2(cbn=2c)+ n 6 cn+ n = O(n):, , , -, cn cc, O(n).. , -T(n) = 2T(bpnc) + lnn,. m = lgn,T(2m) = 2T(2m=2) + m:T(2m) S(m),S(m) = 2S(m=2)+ m(4.4). : S(m) = O(mlgm).T(n) S(m),T(n) = T(2m) = S(m) = O(mlgm) = O(lgnlglgn):
  59. 59. 59, , , -T(n) n,. ,S(m) T(n) n, 2m.4.1-1 , T(n) = T(dn=2e)+1 , T(n) =O(lgn).4.1-2 , T(n) = 2T(bn=2c) + n T(n) =(nlgn), T(n) = (nlgn).4.1-3 n = 1(4.4), -, ?4.1-4 , (4.2)(nlgn).4.1-5 , T(n) = 2T(bn=2c + 17) + n T(n) =O(nlgn).4.1-6T(n) = 2T(pn) + 1, ( , ,| ).4.2., ? , -( ), ,.T(n) = 3T(bn=4c)+ n:, :T(n) = n + 3T(bn=4c) = n + 3(bn=4c+ 3T(bn=16c))= n + 3(bn=4c+ 3(bn=16c+ 3T(bn=64c)))= n + 3bn=4c+ 9bn=16c+ 27T(bn=64c), , (2.4), bbn=4c=4c = bn=16cbbn=16c=4c = bn=64c. ,? i- -T(bn=4ic), T(1), bn=4ic = 1, . .
  60. 60. 60 4i > log4 n. , bn=4ic 6 n=4i,( , -3log4 n ):T(n) 6 n+ 3n=4+ 9n=16+ 27n=64+ :::+ 3log4 n (1)6 n1Xi=034i+ (nlog4 3)= 4n + o(n) = O(n)( log4 n + 1, 3log4 n nlog4 3,o(n), log4 3 < 1.)-.:, .,( ).( -). , -, (n = 4k ). , -,,. 4.3, -( . 4-5).(recursion tree). ,. 4.1T(n) = 2T(n=2)+ n2:, n | .( ) ( ), T(n), -T(n), T(n=2), T(n=4) . . -T(n), -. n2, | (n=2)2 +(n=2)2 =n2=2, | (n=4)2 + (n=4)2 + (n=4)2 + (n=4)2 = n2=4. -,-. , T(n) = (n2).. 4.2 | -T(n) = T(n=3)+ T(2n=3)+ n
  61. 61. 61Total=. 4.1 T(n) = 2T(n=2) +n2. -( ) lgn ( lgn+ 1 ).. 4.2 T(n) = T(n=3) +T(2n=3) +n.
  62. 62. 62 4( ).n. ,1. -,n ! (2=3)n ! (2=3)2n ! ! 1 k = log3=2 n( k (2=3)kn = 1). T(n)O(nlgn).4.2-1 ( ) T(n) =3T(bn=2c) + n,T(n).4.2-2 , , T(n) =T(n=3)+ T(2n=3)+ n T(n) = (nlgn).4.2-3 T(n) = 4T(bn=2c) + nT(n).4.2-4 T(n) = T(n ;a) + T(a) + n, a > 1 | .4.2-5 T(n) =T( n)+T((1; )n)+n, | 0 < < 1.4.3.T(n) = aT(n=b)+ f(n) (4.5)a > 1 b > 1 | , f |( ) .,.(4.5) ,n a n=b,( T(n=b)) -.f(n) ( 1.3.2 f(n) = C(n)+ D(n))., Merge-Sort a = 2, b = 2,f(n) = (n)., (4.5) -: n=b .
  63. 63. 63T(n=b) T(bn=bc) T(dn=be). ,, ,.4.1. a > 1 b > 1 | , f(n) | ,T(n) nT(n) = aT(n=b)+ f(n)n=b dn=be, bn=bc. :1. f(n) = O(nlogb a;") " > 0, T(n) =(nlogb a).2. f(n) = (nlogb a), T(n) = (nlogb a lgn).3. f(n) = (nlogb a+") " > 0 af(n=b) 6cf(n) c < 1 n,T(n) = (f(n)).? -f(n) nlogb a -, T(n) ( 1 3).( 2), -(nlogb a lgn) = (f(n)lgn).. -, f(n) , nlogb a: -n" " > 0.f(n) nlogb a ,af(n=b) 6 cf(n), , ., -: , , f(n) ,nlogb a, , -.2 3. , -., -.T(n) = 9T(n=3)+ n:a = 9, b = 3, f(n) = n, nlogb a = nlog3 9 = (n2).
  64. 64. 64 4f(n) = O(nlog3 9;") " = 1,, T(n) = (n2).T(n) = T(2n=3)+ 1:a = 1, b = 3=2, f(n) = 1 nlogb a = nlog3=2 1 = n0 = 1.2, f(n) = (nlogb a) = (1), ,T(n) = (lgn).T(n) = 3T(n=4)+ nlgna = 3, b = 4, f(n) = nlgn nlogb a =nlog4 3 = O(n0 793). ( " 0 2) , -. n af(n=b) =3(n=4)lg(n=4) 6 (3=4)nlgn = cf(n) c = 3=4.T(n) = (nlgn)., : T(n) =2T(n=2)+nlgn. a = 2, b = 2, f(n) = nlgn, nlogb a = n. ,f(n) = nlgn , nlogb a, -: f(n)=nlogb a = (nlgn)=n = lgnn" " > 0. -2 3. 4.4-2.4.3-1 ,. T(n) = 4T(n=2)+ n. T(n) = 4T(n=2)+ n2. T(n) = 4T(n=2)+ n3.4.3-2 AT(n) = 7T(n=2)+n2, A0 | -T0(n) = aT0(n=4)+n2. aA0 , A?4.3-3 , ,T(n) = T(n=2)+ (1) ( , . . 1.3-5)T(n) = (lgn).4.3-4 , ( 3) -: f,", -.
  65. 65. 4.4 4.1 65? 4.4 4.14.1 -,.. -n, b -. -, -. .-: -, b,,., ,, : T(n), T(n) = O(n) n,, n. ( ,T(n) = n n = 1 2 4 8 ::: T(n) = n2 n.)4.4.1.T(n) , ( )b > 1 ( )(4.5), . .T(n) = aT(n=b)+ f(n):T :( 4.2), ( -4.3) ( 4.4).4.2. a > 1, b > 1 | , f(n) |, b.T(n) | , bT(n) = aT(n=b)+ f(n) n > 1, T(1) > 0.T(n) = (nlogb a) +logb n;1Xj=0ajf(n=bj): (4.6)
  66. 66. 66 4. 4.3 T(n) = aT(n=b) + f(n)a- logb n nlogb a. -, (4.6)..,T(n) = f(n)+ aT(n=b)= f(n)+ af(n=b)+ a2T(n=b2)= f(n)+ af(n=b)+ a2f(n=b2) + :::+ alogb n;1f(n=blogb n;1) + alogb nT(1):alogb n = nlogb a,(nlogb a). ,.4.2( . 4.3), a (). f(n), a -f(n=b), a2 f(n=b2) . .j aj | f(n=bj). -logb n ,T(1) alogb n = nlogb a .
  67. 67. 4.4 4.1 67(4.6) , :j- ajf(n=bj),logb n;1Xj=0ajf(n=bj):,.nlogb a 1, -(nlogb a)., -., | ,.(4.6).4.3. a > 1, b > 1 | , f(n) | -, b. -g(n),g(n) =logb n;1Xj=0ajf(n=bj) (4.7)( n, b).1. f(n) = O(nlogb a;") " > 0,g(n) = O(nlogb a).2. f(n) = (nlogb a), g(n) = (nlogb a lgn).3. af(n=b) 6 cf(n) c < 1n > b, g(n) = (f(n)).. 1. -f(n) = n , = logb a;"f (4.7) : (= logb a)g(n) = f(n) + af(n=b)+ a2f(n=b2) + :::+ ak;1f(n=bk;1)= n + a(n=b) + a2(n=b2) + :::+ ak;1(n=bk;1) (4.8)-k = logb n a=b 1,< logb a b < a. -(). O(ak) = O(nlogb a)..
  68. 68. 68 42.:g(n) = f(n) + af(n=b)+ a2f(n=b2) + :::= n + a(n=b) + a2(n=b2) + ::: (4.9)= logb a -1 . logb n, -nlogb a logb n = (nlogb a lgn):2 .3. f ,-, c < 1.c, -( 1=(1 ; c))( , -). , g(n) = (f(n)) n,b. ., n b.4.4. a > 1, b > 1 | , f(n) |, b.T(n) | , bT(n) = aT(n=b)+ f(n) n > 1 T(1) > 0. :1. f(n) = O(nlogb a;") " > 0, T(n) =(nlogb a).2. f(n) = (nlogb a), T(n) = (nlogb a)lgn.3. f(n) = (nlogb a+") " > 0 af(n=b) 6cf(n) c < 1 -n, T(n) = (f(n)).??????? ?. 4.2 4.3.T(n) = (nlogb a) + O(nlogb a) = (nlogb a):T(n) = (nlogb a) + (nlogb a lgn) = (nlogb a lgn):
  69. 69. 4.4 4.1 69T(n) = (nlogb a) + (f(n)) = (f(n)):, f(n) = (nlogb a+")" > 0 ,( . . 4.4-3).4.4 .4.4.2.n, -b. n=b -T(n) = aT(dn=be)+ f(n) (4.10)T(n) = aT(bn=bc) + f(n): (4.11), ., .n n=b n=b2 ::: -ni, :ni =(n i = 0,dni;1=be i > 0.(4.12)( ). -| , ., logb n -, n ( b)., dxe 6 x + 1 ,n0 6 nn1 6 nb + 1n2 6 nb2 + 1b + 1n3 6 nb3 + 1b2 + 1b + 1::::::::::::::::::::::1 + 1=b + 1=b2 + ::: 6 1=(b ; 1), i = blogb ncni 6 n=bi + b=(b;1) 6 b + b=(b;1) = O(1).
  70. 70. 70 4(4.10),T(n) = f(n0) + aT(n1)= f(n0) + af(n1)+ a2T(n2)6 f(n0) + af(n1)+ a2f(n2) + :::++ ablogb nc;1f(nblogb nc;1) + ablogb ncT(nblogb nc)= (nlogb a) +blogb nc;1Xj=0ajf(nj): (4.13)(4.6), nb., ., T(ndlogbne) ., f(n) , . .n, n0., n0..]g(n) =blogb nc;1Xj=0ajf(nj): (4.14)-, ( -), ( ) ( -). -, -( ,). , -n=bi ni. -, b=(b ; 1), -. ,f(nj) = O(nlogb a=aj) = O((n=bj)logb a), -4.3 ( 2). , bj=n 6 1 j 6 blogb nc.f(n) = O(nlogb a) , c
  71. 71. 4 71njf(nj) 6 c nbj + bb;1logb a= c nlogb aaj 1+ bjnbb;1logb a6 c nlogb aaj 1+ bb;1logb a= O nlogb aaj :, c(1 + b=(b ; 1))logb a | -. , 2 .1 .f(nj) = O(nlogb a;") ,2, ., n., , njn=bj.4.4-1? ni (4.12), b|.4.4-2? , f(n) = (nlogb a lgk n), k > 0,(4.5) T(n) = (nlogb a lgk+1 n).b.4.4-3? , 3 -: (af(n=b) 6 cf(n) -c < 1) , " > 0,f(n) = (nlogb a+").4-1-( , T(n) | -n 6 2):. T(n) = 2T(n=2)+ n3.. T(n) = T(9n=10)+ n.
  72. 72. 72 4. T(n) = 16T(n=4)+ n2.. T(n) = 7T(n=3)+ n2.. T(n) = 7T(n=2)+ n2.. T(n) = 2T(n=4)+pn.. T(n) = T(n;1) + n.. T(n) = T(pn) + 1.4-2A 1::n] 0 n, -. , -B 0::n] , A,, ( -O(n)). A.-A: -A., -O(n).4-3, -, |. ,, . -. -:1. (1).2. (N), N | .3. , -. (q ;p + 1),A p::q]..( . 1.3-5). -? ( -, .). Merge-Sort -1.3.1.4-4T(n) ., T(n) | n 6 8.. T(n) = 3T(n=2)+ nlgn.
  73. 73. 4 73. T(n) = 3T(n=3+ 5)+ n=2.. T(n) = 2T(n=2)+ n=lgn.. T(n) = T(n ;1) + 1=n.. T(n) = T(n ;1)+ lgn.. T(n) =pnT(pn) + n.4-5T(n) n, -b. -n?. T(n) h(n) | , -( -), T(n) 6 h(n) n, -b > 1. , , h: h(n) = O(h(n=b)). ,T(n) = O(h(n)).. T T(n) =aT(n=b) + f(n) n > n0 a > 1, b > 1 f(n) -. T(n) n 6 n0,T(n0) 6 aT(n0=b)+f(n0): , T(n).. 4.1f(n).4.4.4-6(2.13).. -(generating function), -(formal power series)F =1Xi=0Fizi = 0 + z + z2 + 2z3 + 3z4 + 5z5 + 8z6 + 13z7 + :::. , F(z) = z + zF(z)+ z2F(z).. ,F(z) = z1 ;z ;z2 = z(1 ;z)(1 ; bz) = 1p511 ;z ; 11 ; bz = 1 +p52 = 1 61803:::b = 1;p52 = ;0 61803:::
  74. 74. 74 4. ,F(z) =1Xi=01p5(i ; bi)zi:. , Fi i > 0 i=p5. ( : jbj < 1.). , Fi+2 > i i > 0.4-7n ,, | . -,. -,.A BB AB AB AB A. , ,, -( )..n , . ,bn=2c , -.. . ,(n) .( .): -n , -. ,, . ,. -O(n) . -, -. ,, , . -, -:.]
  75. 75. 4 75(L. Fibonacci)1202 . (A. De Moivre)( . 4-6). --, 26], -( . 4.4-2). 121] 140],. -164].
  76. 76. 76 41257
  77. 77. 5, , -, , ,. , , -( ).5.1.(set) (members, elements).x S, x 2 S ( -x S ). x S, x =2 S.-. , S = f1 2 3g -1 2 3 . 2, 4 | , 2 2 S, 4 =2 S., -