1 / 21

CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ?

CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ?. Dr. Juman Byun The George Washington University. Please drop this course if you have not taken the following prerequisite. Sometimes enthusiasm alone is not enough. CSci 1311: Discrete Structures I (3)

alaula
Download Presentation

CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ?

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. CSCI 6212 Design and Analysis of AlgorithmsWhich algorithm is better ? • Dr. Juman Byun • The George Washington University • Please drop this course if you have not taken the following prerequisite. Sometimes enthusiasm alone is not enough. • CSci 1311: Discrete Structures I (3) • CSci 1112: Algorithms and Data Structures (3)

  2. Running Time Calculation

  3. Example: Running Time Analysis • Insertion Sort (A) • 1 for j = 2 to A.length • 2 key = A[j] • 3 // Insert A[j] into the sorted sequence A[1..j-1] • 4 i = j - 1 • 5 while i > 0 and A[i] > key • 6 A[i +1] = A[i] • 7 i = i - 1 • 8 A[i + 1] = key

  4. Best Case: already sorted Insertion Sort (A) 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[1..j-1] 4 i = j - 1 5 while i > 0 and A[i] > key 6 A[i +1] = A[i] 7 i = i - 1 8 A[i + 1] = key

  5. Best Case: already sorted Insertion Sort (A) 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[1..j-1] 4 i = j - 1 5 while i > 0 and A[i] > key 6 A[i +1] = A[i] 7 i = i - 1 8 A[i + 1] = key

  6. Best Case: already sorted

  7. Best Case: already sorted • simply express it

  8. Worst Case: reverse sorted Insertion Sort (A) 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[1..j-1] 4 i = j - 1 5 while i > 0 and A[i] > key 6 A[i +1] = A[i] 7 i = i - 1 8 A[i + 1] = key

  9. Worst Case: reverse sorted Insertion Sort (A) 1 for j = 2 to A.length 2 key = A[j] 3 // Insert A[j] into the sorted sequence A[1..j-1] 4 i = j - 1 5 while i > 0 and A[i] > key // for entire A[1..j-1] 6 A[i +1] = A[i] //∴tj = (j - 1) + 1 7 i = i - 1 // = j 8 A[i + 1] = key

  10. Worst Case: reverse sorted

  11. Worst Case: reverse sorted

  12. Worst Case: reverse sorted

  13. Worst Case: reverse sorted

  14. Worst Case: reverse sorted

  15. Worst Case: reverse sorted

  16. Worst Case: reverse sorted

  17. Worst Case: reverse sorted

  18. Worst Case: reverse sorted • To abstract running time T(n) using constants • Notation of "Worst-Case Running Time of Insertion Sort"

  19. Worst Case: reverse sorted • Simply abstract it using constants

  20. To Denote Relative Algorithm Performance • Algorithm 1 input size n with running time f(n) • Asymptotic Notation

More Related