Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

アルゴリズムイントロダクション 第2章

5,391 views

Published on

アルゴリズムイントロダクション 第2章の勉強会資料

下記でPPT版,KEY版も配布してます.
http://tniky1.com/study/

Published in: Technology, Business
  • Be the first to comment

アルゴリズムイントロダクション 第2章

  1. 1. 2010 CS
  2. 2. 2010 CS    Copyright© 2010 tniky1 All rights reserved. Page 2
  3. 3. 2010 CS   -  -    -    - Θ Copyright© 2010 tniky1 All rights reserved. Page 3
  4. 4. 2010 CS Copyright© 2010 tniky1 All rights reserved. Page 4
  5. 5. 2010 CS j 1 1 2 3 4 5 6 2 5 4 6 1 3 i length[A] procedure Insertion-Sort(A) for j ← 2 to length[A] do key ← A[j] i←j−1 while i > 0 and A[i] > key do A[i+1] ← A[i] i←i−1 A[i+1] ← key Copyright© 2010 tniky1 All rights reserved. Page 5
  6. 6. 2010 CS (1) (2) Copyright© 2010 tniky1 All rights reserved. Page 6
  7. 7. 2010 CS     -  A[1...j-1] → j 2 5 4 6 1 3 A[1...j-1] Copyright© 2010 tniky1 All rights reserved. Page 7
  8. 8. 2010 CS   -  -  -  -  -  -  ( ) Copyright© 2010 tniky1 All rights reserved. Page 8
  9. 9. 2010 CS j 2 5 4 6 1 3 A[1...j-1] for j ← 2 to length[A] J=2 do key ← A[j] A[1] A[1..j-1] i←j−1 while i > 0 and A[i] > key A[j] A[j-1],A[j-2]... do A[i+1] ← A[i] A[j] i←i−1 (A[1..j-1] ) A[i+1] ← key Copyright© 2010 tniky1 All rights reserved. Page 9
  10. 10. 2010 CS j=n+1 1 2 3 4 5 6 A[1...j-1]=A[1..n] for j ← 2 to length[A] j=n+1 do key ← A[j] A[1..j-1]=A[1..n] ! i←j−1 while i > 0 and A[i] > key do A[i+1] ← A[i] i←i−1 A[i+1] ← key Copyright© 2010 tniky1 All rights reserved. Page 10
  11. 11. 2010 CS (1) (2) Copyright© 2010 tniky1 All rights reserved. Page 11
  12. 12. 2010 CS   -  -  -  ( )   -  ( DB DB ) - Copyright© 2010 tniky1 All rights reserved. Page 12
  13. 13. 2010 CS j 1 2 3 4 5 6 2 5 4 6 1 3 i n for j ← 2 to length[A] n do key ← A[j] n-1 i←j−1 n-1 while i > 0 and A[i] > key do A[i+1] ← A[i] i←i−1 tj A[i+1] ← key n-1 ( ) Copyright© 2010 tniky1 All rights reserved. Page 13
  14. 14. 2010 CS for j ← 2 to length[A] C1 n do key ← A[j] C2 n-1 i←j−1 C3 n-1 while i > 0 and A[i] > key C4 do A[i+1] ← A[i] C5 i←i−1 C6 A[i+1] ← key C7 n-1 T(n) Copyright© 2010 tniky1 All rights reserved. Page 14
  15. 15. 2010 CS T(n) ( ) j 1 2 3 4 5 6 [ ] 5 6 4 3 2 1 i=0 i tj=i Copyright© 2010 tniky1 All rights reserved. Page 15
  16. 16. 2010 CS   -  -    -  -  - Copyright© 2010 tniky1 All rights reserved. Page 16
  17. 17. 2010 CS Copyright© 2010 tniky1 All rights reserved. Page 17
  18. 18. 2010 CS A 2 4 5 7 1 2 3 6 p q r i j 1 2 3 4 5 1 2 3 4 5 L 2 4 5 7 ∞ R 1 2 3 6 ∞ n1 n2 k A 1 2 2 3 4 2 3 6 p q r Copyright© 2010 tniky1 All rights reserved. Page 18
  19. 19. 2010 CS   -  A L R k−p -  L[i] R[j] L R A i j 1 2 3 4 5 1 2 3 4 5 L 2 4 5 7 ∞ R 1 2 3 6 ∞ k A 1 2 2 3 4 2 3 6 p r Copyright© 2010 tniky1 All rights reserved. Page 19
  20. 20. 2010 CS i j 1 2 3 4 5 1 2 3 4 5 L 2 4 5 7 ∞ R 1 2 3 6 ∞ k A 1 2 2 3 4 2 3 6 p r k=p A[p..k-1] i=j=1 L,R L[i]<=R[j] L[i] A L[i] A[k] i k L[i],R[j]Copyright© 2010 tniky1 All rights reserved. Page 20
  21. 21. 2010 CS i j 1 2 3 4 5 1 2 3 4 5 L 2 4 5 7 ∞ R 1 2 3 6 ∞ k A 1 2 2 3 4 2 3 6 p r k=r+1 A[p..k-1]=A[p..r] ! 2 n (n1+n2 ) : Θ(n)Copyright© 2010 tniky1 All rights reserved. Page 21
  22. 22. 2010 CS MERGE Copyright© 2010 tniky1 All rights reserved. Page 22
  23. 23. 2010 CS A p r p r A /* ( ) */ Copyright© 2010 tniky1 All rights reserved. Page 23
  24. 24. 2010 CS -  a 1/b -  If n <= c -  D(n): -  C(n): Copyright© 2010 tniky1 All rights reserved. Page 24
  25. 25. 2010 CS T(n) = aT(n/b) + D(n) + C(n) 2 Merge Θ(n) 1/2 a = b = 2 D(n) = Θ(1) T(n) = 2T(n/2) + Θ(1) + Θ(n) if n > 1 =Θ(1) if n = 1Copyright© 2010 tniky1 All rights reserved. Page 25
  26. 26. 2010 CS cn( ) Copyright© 2010 tniky1 All rights reserved. Page 26
  27. 27. 2010 CS log2n Copyright© 2010 tniky1 All rights reserved. Page 27
  28. 28. 2010 CS   OK -  -  Copyright© 2010 tniky1 All rights reserved. Page 28

×