Algorithm
A list of clear steps that solves a problem and ends after a finite number of steps. With the same input, it always gives the same output.
Example
To add 1 to 100: start at 0 and add each number, 1 at a time. That's 100 steps and the result is 5,050.
Test yourself: Algorithm
What is an algorithm
What is an algorithm?
Adding 1 to 100 one number at a time is an algorithm: 100 clear steps that end with the result, 5,050. It doesn't depend on the language or the machine.
What is an algorithm
An algorithm can give different results with the same input and the same conditions.
Each step means exactly one thing, so with the same input the result repeats: sorting [3, 1, 2] gives [1, 2, 3] every time, not sometimes.
Measuring efficiency
If an algorithm is very fast, it doesn't matter that it sometimes gives a wrong result.
Being correct comes first. Sorting 1 million items in 1 second is useless if 3 end up out of place.
0/3
â–¶ PlayLessons that use it
Load balancers
Sharing the work
What is an algorithm
You already use algorithms
Big O notation
How much does it grow?
Measuring efficiency
Fast and light on memory
Time complexity
Count steps, not seconds
Space complexity
How much memory it asks for
Types of structures
How they relate and where they live
Dynamic lists
An array that grows by itself
Hash algorithms
A good hash spreads evenly
Graphs
Points and connections
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
Selection sort
Picking the smallest, over and over
Insertion sort
Like arranging the cards in your hand
Quick sort
A pivot and 2 sides
Heap sort
Take the maximum and leave it at the end
Bucket sort
Split into buckets and sort each one
Divide and conquer
Split, solve and combine
Tower of Hanoi
n − 1, 1 and n − 1
When DP works
3 properties
Greedy algorithms
The best right now
Quadtrees
Splitting the map in 4
Rate limiting algorithms
5 ways to count
