Algorithms Visualized
Watch code think
Watch code think
An algorithm is just a recipe - a set of steps to solve a problem. Making a sandwich? That's an algorithm. Finding a word in a dictionary? Algorithm. Sorting your playlist by name? You guessed it - algorithm!
The same problem can often be solved by different algorithms. Some are fast, some are slow, some use lots of memory. Computer scientists spend their careers finding better algorithms!
Sorting is one of computing's most studied problems. Watch different algorithms race to sort the same data. All algorithms run to completion so you can see just how much faster the efficient ones really are!
O(n²) algorithms (Bubble, Selection, Insertion) compare each element to every other element.
With 100 items, that's up to 10,000 comparisons!
O(n log n) algorithms (Quick, Merge) use "divide and conquer" - they split the problem
in half repeatedly. With 100 items, that's only about 700 comparisons. 14x fewer!
Imagine you need to find a specific card in a deck. You could check every card one by one... or you could be smarter about it. Let's see the difference!
Programmers use Big O to describe this difference:
O(n) = "Check every box" -
With 1000 boxes, check up to 1000 times
O(log n) = "Smart search" -
With 1000 boxes, only ~10 checks needed!
The "n" just means "how many items you have." As n gets bigger, the difference becomes HUGE.
Like knowing exactly which locker is yours. Always 1 step.
Like the guessing game - cut possibilities in half each time.
Check everything once. 100 items = 100 checks.
Compare everything to everything. 100 items = 10,000 checks!
Finding a number in a sorted list: should you check every item, or be clever about it? Watch linear search plod through vs binary search's magical halving technique!
Binary search is like finding a name in a phone book: open to the middle, check if your name is before or after, then repeat with half the book. A 1000-page book takes at most 10 checks!
How does GPS find the fastest route? The A* algorithm! It explores possibilities while always heading toward the goal. Click to add walls, then watch it find the path.
A* and its variants power Google Maps, game AI (enemies chasing you!), robot navigation, and even protein folding simulations. It's one of the most important algorithms ever invented.
Pick any algorithm and watch it work step by step. See exactly how each one approaches the sorting problem differently.
You've seen the invisible logic that powers every app, game, and website.
Step-by-step instructions that solve problems - from making sandwiches to sorting data.
O(n log n) algorithms can be thousands of times faster than O(n²) with large data.
The fastest algorithms split problems in half repeatedly instead of checking everything.
GPS, games, search engines, social media - all powered by algorithms running millions of times per second.
Put your new knowledge into practice!