[CREDITS HERE]
Time Complexity
Space Complexity
How much memory is used?
How many comparisons are made?
How many swaps are made?
...with respect to input size
...and assuming worst case scenarios
A sorting algorithm is "stable"
if it preserves the order of
equal items.
Prompt: I want bikes sorted by price (ascending). Given equal prices, I want lighter option to be first.
The list is already sorted by weight (ascending). I just need to sort it by price. But an unstable sort based on price could "unsort" weights.
Bike A | $600 | 20 lbs. |
Bike B | $500 | 30 lbs. |
Bike C | $500 | 35 lbs. |
A sorting algorithm is "adaptive"
if it becomes more efficient
(i.e., if its complexity is reduced)
when the input is
already nearly sorted.
Visualization here:
Text
Visualization here:
Text
Visualization here:
Text
Visualization here:
arrays
linked lists
Text
Visualization here:
*Note: Complexity of swapping is implementation-specific
(there are multiple solutions)
Text