Skip to content

Latest commit

 

History

History
executable file
·
65 lines (50 loc) · 3.33 KB

sorting.md

File metadata and controls

executable file
·
65 lines (50 loc) · 3.33 KB

Sorting

Joke Sorting Algorithms

  • Is this the simplest (and most surprising) sorting algorithm ever?
    • Algorithm 1 ICan’tBelieveItCanSort(A[1..n])
    •   for i = 1 to n do
        for j = 1 to n do
        if A[i] < A[j] then
        swap A[i] and A[j]
      
    • There is nothing good about this algorithm. It is slow – the algorithm obviously runs in Θ(n2) time, whether worst-case, average-case or best-case. It unnecessarily compares all pairs of positions, twice (but see Section 3). There seems to be no intuition behind it, and its correctness is not entirely obvious. You certainly do not want to use it as a first example to introduce students to sorting algorithms.

Time Sort

Each item - sleep for n seconds - n is value - when process wakes up, add to list This is crap - but runs in O(n) complexity - and is racy and inefficent - what does that tell us about O(n) measure?

Examples