TAILIEUCHUNG - Lecture Data structures and algorithms in Java (6th edition): Chapter 4 - Goodrich, Tamassia, Goldwasser
All other factors being equal, the running time of the same algorithm on the same input data will be smaller if the computer has, say, a much faster processor or if the implementation is done in a program compiled into native machine code instead of an interpreted implementation run on a virtual machine. We begin this chapter by discussing tools for performing experimental studies, yet also limitations to the use of experiments as a primary means for evaluating algorithm efficiency. | Analysis of Algorithms 3/16/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Analysis of Algorithms Input © 2014 Goodrich, Tamassia, Goldwasser Algorithm Output Analysis of Algorithms 1 Running Time q q q Most algorithms transform input objects into output objects. The running time of an algorithm typically grows with the input size. Average case time is often difficult to determine. We focus on the worst case running time. n n Easier to analyze Crucial to applications such as games, finance and robotics © 2014 Goodrich, Tamassia, Goldwasser best case average case worst case 120 100 Running Time q 80 60 40 20 0 1000 Analysis of Algorithms 2000 3000 4000 Input Size 2 1 Analysis of Algorithms 3/16/14 Experimental Studies q q Write a program implementing the algorithm Run the program with inputs of varying size and composition, noting the time needed: Plot the results 8000 7000 Time (ms) q 9000 6000 5000 4000 3000 2000 1000 0 0 50 100 Input Size © 2014 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 3 Limitations of Experiments It is necessary to implement the algorithm, which may be difficult q Results may not be indicative of the running time on other inputs not included in the experiment. q In order to compare two algorithms, the same hardware and software environments must be used q © 2014 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 4 2 Analysis of Algorithms 3/16/14 Theoretical Analysis Uses a high-level description of the algorithm instead of an implementation q Characterizes running time as a function of the input size, n q Takes into account all possible inputs q Allows us to evaluate the speed of an algorithm independent of the hardware/ software environment q © 2014 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 5 Pseudocode High-level
đang nạp các trang xem trước