算法(Algorithms)第4版 练习 2.1.27
2017-03-22 15:03
274 查看
package com.qiusongde; import edu.princeton.cs.algs4.StdOut; public class Exercise2127 { public static void main(String[] args) { int T = 100; double previnsert = SortCompare.timeRandomInput("Insertion", 64, T); double prevselection = SortCompare.timeRandomInput("Selection", 64, T); double prevshell = SortCompare.timeRandomInput("Shell", 64, T); StdOut.printf("%-10s %-13s %-13s %-13s\n", "N", "Insertion", "Selection", "Shell"); int N = 128; while(true) { double timeinsert = SortCompare.timeRandomInput("Insertion", N, T); double timeselection = SortCompare.timeRandomInput("Selection", N, T); double timeshell = SortCompare.timeRandomInput("Shell", N, T); double ratioinsert = timeinsert/previnsert; double ratioselection = timeselection/prevselection; double ratioshell = timeshell/prevshell; StdOut.printf("%-10d %-6.3f %-6.1f %-6.3f %-6.1f %-6.3f %-6.1f\n", N, timeinsert, ratioinsert, timeselection, ratioselection, timeshell, ratioshell); N += N; previnsert = timeinsert; prevselection = timeselection; prevshell = timeshell; } } }
N Insertion Selection Shell 128 0.005 0.6 0.023 3.8 0.001 0.3 256 0.007 1.4 0.005 0.2 0.005 5.0 512 0.026 3.7 0.025 5.0 0.005 1.0 1024 0.113 4.3 0.084 3.4 0.015 3.0 2048 0.463 4.1 0.331 3.9 0.028 1.9 4096 1.880 4.1 1.317 4.0 0.069 2.5 8192 7.605 4.0 5.251 4.0 0.161 2.3
相关文章推荐
- 算法(Algorithms)第4版 练习 2.2.11(3)
- 算法(Algorithms)第4版 练习 2.2.26
- 算法(Algorithms)第4版 练习 1.3.29
- 算法(Algorithms)第4版 练习 1.3.219
- 算法(Algorithms)第4版 练习 1.3.12
- 算法(Algorithms)第4版 练习 1.3.4
- 算法(Algorithms)第4版 练习 1.5.10
- 算法(Algorithms)第4版 练习 1.5.22
- 算法(Algorithms)第4版 练习 2.3.17
- 算法(Algorithms)第4版 练习 1.3.11
- 算法(Algorithms)第4版 练习 1.3.3
- 算法(Algorithms)第4版 练习 1.3.41
- 算法(Algorithms)第4版 练习 1.5.5
- 算法(Algorithms)第4版 练习 1.3.10
- 算法(Algorithms)第4版 练习 1.3.2
- 算法(Algorithms)第4版 练习 1.3.31
- 算法(Algorithms)第4版 练习 1.4.9
- 算法(Algorithms)第4版 练习 链表类 1.3.19~1.3.29
- 算法(Algorithms)第4版 练习 1.3.9
- 算法(Algorithms)第4版 练习 1.5.6