Making Computer Science easier to understand.
Explanations in this animation:
- Load Balancer
- How a load balancer works. Clients send requests to a single balancer, which forwards each one to the next server in turn, round robin, so the load spreads evenly across three servers. When the third server stops answering its health check, the balancer removes it from the pool and reroutes subsequent requests to the two that remain. No request is dropped and the client never sees the failure.
- Recursion
- The Tower of Hanoi with four discs, solved recursively in 15 moves. To move four discs from A to C, the three above the biggest are moved to B, the biggest crosses to C on its own, and the three are moved from B onto it — and each of those three-disc moves is the same problem stated again with a smaller number. The base case is a stack of zero discs, which needs no moves at all. Every extra disc doubles the work, so n discs take 2^n - 1 moves.
- Deadlock
- A deadlock between two processors and two devices, drawn as a resource-allocation graph. P1 acquires the printer and P2 acquires the scanner. P1 then requests the scanner, which P2 is holding, and P2 requests the printer, which P1 is holding. The two holdings and the two requests form a cycle, so each processor is waiting for a device the other will never release and neither can continue. This is circular wait, one of the four conditions that must all hold for a deadlock to occur.
- Merge Sort
- Merge sort on seven values, drawn as the recursion it is. The array is split in half, each half is split again, and the splitting stops when a piece holds a single value, which is sorted by definition. The pieces then come back up: two sorted runs are merged by comparing their front values and taking the smaller, which is where the ordering is actually created. Nothing sorts on the way down and nothing is compared until the way back up. Each level of the tree walks past every value once, and halving the array down to single values takes log n levels, so the sort costs n log n on every input there is.
- Binary Search
- Binary search over the sorted array 4, 11, 17, 23, 31, 42, 56, 68, 79, looking for 23. Each step checks the middle value of the range still in play and discards the half that cannot contain the target. The range shrinks from 9 values to 9, then 4, then 2, then 1, and 23 is found at index 3 after 4 comparisons. Because every step halves what is left, the work grows with the logarithm of the input rather than with the input itself.
Task: Keep serving requests when a server dies