Successfully reported this slideshow.
Upcoming SlideShare
×

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

5,474 views

Published on

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

http://tniky1.com/study/

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

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

1. 1. 2010 CS
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
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
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