1.
1 PackageAlgorithms.analysis14;2 3 ImportAlgorithms.util.StdOut;4 ImportAlgorithms.util.StdRandom;5 6 /******************************************************************************7 * Compilation:javac Doublingtest.java8 * Execution:java doublingtest9 * Dependencies:ThreeSum.java Stopwatch.java stdrandom.java Stdout.javaTen * One *% java doublingtest A * 0.0 - * 0.0 - * 0.1 the * 0.6 - * 4000 4.5 - * 8000 35.7 - * ... + * - ******************************************************************************/ + A /** at * The <tt>DoublingTest</tt> class provides a client for measuring - * The running time of a method using a doubling test. - * <p> - * For additional documentation, see <a href= "http://algs4.cs.princeton.edu/14analysis">section 1.4</a> - * of <i>algorithms, 4th edition</i> by Robert Sedgewick and Kevin Wayne. - * in * @authorRobert Sedgewick - * @authorKevin Wayne to */ + Public classDoublingtest { - Private Static Final intMaximum_integer = 1000000; the * //This is class should not being instantiated. $ Privatedoublingtest () {}Panax Notoginseng - /** the * Returns The amount of time to call <tt>threesum.count () </tt> with <em>N</em> + * Random 6-digit integers. A * @paramN the number of integers the * @returnamount of time (in seconds) to call <tt>threesum.count () </tt> + * with <em>N</em> random 6-digit integers - */ $ Public Static DoubleTimetrial (intN) { $ int[] A =New int[N]; - for(inti = 0; i < N; i++) { -A[i] = Stdrandom.uniform (-Maximum_integer, Maximum_integer); the } -Stopwatch timer =NewStopwatch ();Wuyi Threesum.count (a); the returntimer.elapsedtime (); - } Wu - /** About * Prints table of running times to call <tt>threesum.count () </tt> $ * For arrays of size, $, $, + , and so forth. - */ - Public Static voidMain (string[] args) { - for(intN = 250;true; N + =N) { A DoubleTime =timetrial (N); +stdout.printf ("%7d%5.1f\n", N, time); the } - } $}
2.
1 PackageAlgorithms.analysis14;2 3 ImportAlgorithms.util.StdOut;4 ImportAlgorithms.util.StdRandom;5 6 /******************************************************************************7 * Compilation:javac Doublingratio.java8 * Execution:java Doublingratio9 * Dependencies:ThreeSum.java Stopwatch.java stdrandom.java Stdout.javaTen * One * A *% java doublingratio - * 0.0 2.7 - * 0.0 4.8 the * 0.1 6.9 - * 0.6 7.7 - * 4000 4.5 8.0 - * 8000 35.7 8.0 + * ... - * + ******************************************************************************/ A at /** - * The <tt>DoublingRatio</tt> class provides a client for measuring - * The running time of a method using a doubling ratio test. - * <p> - * For additional documentation, see <a href= "http://algs4.cs.princeton.edu/14analysis">section 1.4</a> - * of <i>algorithms, 4th edition</i> by Robert Sedgewick and Kevin Wayne. in * - * @authorRobert Sedgewick to * @authorKevin Wayne + */ - Public classDoublingratio { the Private Static Final intMaximum_integer = 1000000; * $ //This is class should not being instantiated.Panax Notoginseng PrivateDoublingratio () {} - the /** + * Returns The amount of time to call <tt>threesum.count () </tt> with <em>N</em> A * Random 6-digit integers. the * @paramN the number of integers + * @returnamount of time (in seconds) to call <tt>threesum.count () </tt> - * with <em>N</em> random 6-digit integers $ */ $ Public Static DoubleTimetrial (intN) { - int[] A =New int[N]; - for(inti = 0; i < N; i++) { theA[i] = Stdrandom.uniform (-Maximum_integer, Maximum_integer); - }WuyiStopwatch timer =NewStopwatch (); the Threesum.count (a); - returntimer.elapsedtime (); Wu } - About /** $ * Prints table of running times to call <tt>threesum.count () </tt> - * For arrays of size, $, $, $, and so forth, along - * with ratios of running times between successive array sizes. - */ A Public Static voidMain (string[] args) { + DoublePrev = timetrial (125); the for(intN = 250;true; N + =N) { - DoubleTime =timetrial (N); $stdout.printf ("%6d%7.1f%5.1f\n", N, Time, time/prev); thePrev =Time ; the } the } the}
Algorithm Sedgewick Fourth Edition-1th chapter basic -1.4 Analysis of Algorithms-005 meter test algorithm