Worst case
The most an algorithm can take or use with the least favorable input. It's used because it's a guarantee.
Example
Searching for a number one by one in a list of 1,000: in the worst case it's last and that's 1,000 steps.
Test yourself: Worst case
Time complexity
Why is the worst-case complexity almost always used?
If search is O(n) in the worst case, with 1 million items you know it's never more than 1 million steps, however the list comes.
0/1
â–¶ PlayLessons that use it
What is an algorithm
You already use algorithms
Big O notation
How much does it grow?
Time complexity
Count steps, not seconds
Space complexity
How much memory it asks for
Arrays
Adjacent cells
Building a heap
Bottom-up is cheaper
Graph operations
Adding and removing vertices and edges
Searching with a hash
From O(n²) to O(n) with a table
Choosing how to search
Brute force or using the order
What makes a good sort
5 things you ask of it
Bubble sort
The largest rises like a bubble
Insertion sort
Like arranging the cards in your hand
Quick sort
A pivot and 2 sides
Merge sort
Split in half and merge in order
Heap sort
Take the maximum and leave it at the end
Rebuilding a tree
Root, left and right
Backtracking
Try, and if it fails, go back
N-queens
None attacks another
Fractional knapsack
Most value per kilo
Measure and optimize
Measure first
Disaster recovery
Running again after the disaster
