Slide 1

Slide 1 text

Basic Sort Hiroki Kumamoto

Slide 2

Slide 2 text

Selection Sort • Ұ൪খ͍͞਺Λ୳͢ͱ͍͏ͷΛNճ܁Γฦ͢ • Ұ൪খ͍͞΋ͷΛa[i]ʹ࣋ͬͯ͘Δ • 1/2N^2 ͷൺֱ • (N-1) + (N-2)+ …. + 1 + 0 • Nճͷަ׵ • O(N^2)

Slide 3

Slide 3 text

• Visualize demo • http://kumabook.github.io/playground/ index.html#selection-sort

Slide 4

Slide 4 text

Insertion sort • i-1൪໨·Ͱ͕੔ྻ͍ͯ͠Δͱͯ͠ɺi൪໨ͷཁૉ Λ0..i൪໨ͷதͰਖ਼͍͠Ґஔʹૠೖ͢Δ • best case: ੔ྻࡁΈ: N -1 ͷൺֱ + 0ަ׵ • worst case: ٯॱ: 1/2 N^2ͷൺֱ+ 1/2N^2ͷަ ׵ • O(N) ~ O(N^2)

Slide 5

Slide 5 text

• Visualize demo • http://kumabook.github.io/playground/ index.html#insertion-sort

Slide 6

Slide 6 text

Shell Sort • Insertion sort ͸ٯॱʹฒΜͰ͍Δͱ͖ʹ஗͍ • → ͱͼͱͼͷinsertion sortԿճ͔ʹ෼͚ͯ΍Δ • Best sequence of increments? • 1, 3, 7, 15, 31, 63 … Powers of two minus one. • 1, 4, 13, 40, 121, 364…3x + 1 • ฏۉɿO (N ^ 3/2)

Slide 7

Slide 7 text

Shell Sort • αΠζͷখ͍͞഑ྻʹରͯ͠༗ޮ • bzip2, /linux/kernel/groups.c • ίʔυͷfoot print ͕খ͍͞ • uClibc

Slide 8

Slide 8 text

• Visualize demo • http://kumabook.github.io/playground/ index.html#shell-sort

Slide 9

Slide 9 text

Reference • Coursera: Algorithms, Part 1 • https://www.coursera.org/course/algs4partI • http://algs4.cs.princeton.edu/home/