1 / 21

COM S 228 Algorithms and Analysis Instructor: Ying Cai Department of Computer Science

COM S 228 Algorithms and Analysis Instructor: Ying Cai Department of Computer Science Iowa State University yingcai@iastate.edu Office: Atanasoff 201. Algorithm. An algorithm is a strategy for solving a problem, independent of the actual implementation. Which algorithms are faster.

bfierro
Download Presentation

COM S 228 Algorithms and Analysis Instructor: Ying Cai Department of Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COM S 228 Algorithms and Analysis Instructor: Ying Cai Department of Computer Science Iowa State University yingcai@iastate.edu Office: Atanasoff 201

  2. Algorithm • An algorithm is a strategy for solving a problem, independent of the actual implementation

  3. Which algorithms are faster • Implement both algorithms and measure them with a stopwatch or count CPU cycles • This approach has several problems • The system may be running other applications, which share the same CPU • Many other factors impact the speed • Memory swapping • Garbage collection • Both must be implemented, which is often not practical • It is unclear how the algorithms scale when you give a faster CPU

  4. Time Complexity (Run Time) • The time complexity of an algorithm is a function that describes the number of basic execution steps in terms of the input size • We express time complexity using Big-O notation

  5. Algorithm: Sequential Search Basic idea Pseudocode The running time of the sequential search depends on the particular values in A. If v is the first item, it takes one step; If v is not present, which is the worst case, it takes T(n) = 3n+3. The worst-case time complexity of this algorithm is O(n), or “big-O of N”

  6. Notion of O(f(n))

  7. Notion of O(f(n))

  8. Notion of O(f(n))

  9. Array Equality Revisited Algorithm 1 In the worst case, this algorithm needs to search the entire array B for A[i]

  10. Array Equality Revisited

  11. Algorithm Analysis in Practice In practice, algorithm analysis is seldom done at the level of detail as we have done so far

  12. Example 1 void printAll(int[] array) { for (int i=0; i< array.length; i++) { System.out.println(array[i]); } }

  13. Example 2 // assuming array.length >= 1000 void sumDouble(double [] array) { double sum = 0.0; for (int i=0; i< 1000; i++) { sum = sum + i; } }

  14. Example 3 for (int i =0; i< array.length; i++) { method1(); // take O(n) method2(); // takes O(n2) }

  15. Example 4

  16. Practical Implication of Asymptotic Analysis

  17. Computation Time

More Related