1 / 8

Lecture 6

Lecture 6. Analysis of Iterative Algorithms Sorting Algorithms. Some useful terminology. Time and Space Complexity : analyze not just the number of steps, but also the space usage. Worst case analysis versus other types ( best case, average ). Time and Space Complexity.

jhartung
Télécharger la présentation

Lecture 6

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. Lecture 6 Analysis of Iterative Algorithms Sorting Algorithms

  2. Some useful terminology • Time and Space Complexity: analyze not just the number of steps, but also the space usage. • Worst case analysis versus other types (best case, average)

  3. Time and Space Complexity • Time: number of steps • Space: number of memory cells used by the algorithm, besides the input • Examples of space usage: • Find Min, Search, Selection Sort, Insertion Sort: no extra space (constant, in fact: O(1) ) • Merge: extra n space, O(n) • Merge Sort: O(n) extra space

  4. Best case, Average case • Sequential Search: worst case O(n), best case O(1), average case n/2= O(n) • Binary Search: best case O(1), worst case and average O(log n) • QuickSort: worst case O(n 2), average case O(n log n)

  5. Analysis of Iterative Algorithms • Examples: • Selection Sort • Insertion Sort • Correctness proof using loop invariant for Selection Sort (pb. 1.2 textbook) • Summation formulas

  6. Selection Sort • Applet and Pseudocode from Dominique’s page • Proof using loop invariant • Analysis: • Time to find minimum M(n)=n-1 • Time to do Selection Sort: T(n) = M(n)+M(n-1)+…+ M(2)+M(1) = = 1+2+…+(n-1) = n(n-1)/2 = O(n2)

  7. Insertion Sort • Applet and pseudocode from Dominique’s page • Proof of correctness using loop invariant • Analysis: • Time to search and shift at step k: S(k)=k • Time to do Insertion Sort: T(n) = S(1)+S(2)+…+S(n-1)=1+2+…+(n-1)= = n(n-1)/2 = O(n 2)

  8. Other examples from textbook

More Related