2. Linear search
Linear search
• What is the best-case running time?
• What is the worst-case running time?
• What is the memory usage?
• Which assumptions have we made about the keys and
how the data is represented?
3. Binary search
Binary search
• What is the best-case running time?
• What is the worst-case running time?
• What is the memory usage?
• Which assumptions have we made about the keys and
how the data is represented?
Sorting
6. Insertion sort
• Which assumptions have we made?
• Is it stable?
• What is the worst-case number of comparisons?
• What is the best-case number of comparisons?
• What is the worst-case number of swaps?
• What is the best-case number of swaps?
Selection sort
7. • Termination: Trivial — nested finite for-loops
• Correctness:
Selection sort
• Which assumptions have we made?
• Is it stable?
• What is the worst-case number of comparisons?
• What is the best-case number of comparisons?
• What is the worst-case number of swaps?
• What is the best-case number of swaps?
Bubble sort
8. • Termination: Not trivial! (But wait for it…)
• Correctness:
j is # outer iterations
• Termination:
• Correctness:
j is # outer iterations
While j is only used for the analysis,
and not a real "for-loop" variable we
can use it in the termination function:
t(j) = n - j
9. Bubble sort
• Which assumptions have we made?
• Is it stable?
• What is the worst-case number of comparisons?
• What is the best-case number of comparisons?
• What is the worst-case number of swaps?
• What is the best-case number of swaps?
Index-based sorting
Count sort
10. Bucket sort
Bucket sort
• Which assumptions have we made?
• Is it stable?
• What is the best- and worst-case running time?
• What is the best- and worst-case memory usage?
Radix sort