Close
Register
Close Window

Chapter 6 Week 7-8

Show Source |    | About   «  5.1. Huffman Coding   ::   Contents   ::   6.2. Sorting Part 2  »

6.1. Sorting Part 1

6.1.1. Sorting Part 1

6.1.1.1. Sorting

  • Each record contains a field called the key.
    • Linear order: comparison.
  • Measures of cost:
    • Comparisons
    • Swaps

6.1.1.2. Insertion Sort

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.3. Analysis: Worst Case

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.4. Analysis: Best Case

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.5. Analysis: Average Case

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.6. Bubble Sort

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.7. Analysis

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.8. Selection Sort

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.9. Analysis

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

6.1.1.10. Summary

\[\begin{split}\begin{array}{rccc} &\textbf{Insertion}&\textbf{Bubble}&\textbf{Selection}\\ \textbf{Comparisons:}\\ \textrm{Best Case}&\Theta(n)&\Theta(n^2)&\Theta(n^2)\\ \textrm{Average Case}&\Theta(n^2)&\Theta(n^2)&\Theta(n^2)\\ \textrm{Worst Case}&\Theta(n^2)&\Theta(n^2)&\Theta(n^2)\\ \\ \textbf{Swaps:}\\ \textrm{Best Case}&0&0&\Theta(n)\\ \textrm{Average Case}&\Theta(n^2)&\Theta(n^2)&\Theta(n)\\ \textrm{Worst Case}&\Theta(n^2)&\Theta(n^2)&\Theta(n)\\ \end{array}\end{split}\]

6.1.1.11. Code Tuning

  • General strategy: Test to avoid work
    • Balance test cost, success probability, work saved
  • "Optimizations" for quadratic sorts:
    • Insertion Sort shift vs swaps: Works
    • Selection Sort avoid self-swaps: Does not work
    • Bubble Sort avoid/count comparisions: Does not work

6.1.1.12. Exchange Sorting

  • All of the sorts so far rely on exchanges of adjacent records.
  • Inversions
  • What is the average number of exchanges required?
Settings

Proficient Saving... Error Saving
Server Error
Resubmit

   «  5.1. Huffman Coding   ::   Contents   ::   6.2. Sorting Part 2  »

nsf
Close Window