8 algorithms every developer should learn
Most developers rarely write a sorting function or a pathfinding routine from scratch; good libraries already provide them. Knowing how the classic algorithms work still matters, because it tells you which tool fits a problem, why a feature is slow, and what a library call is really doing.
These eight cover the ideas that come up again and again in everyday software: searching, sorting, compression, walking through graphs, optimisation and secure communication. For each one, here is what it does, where you will meet it and what to remember about it.
1. Binary search
Binary search finds an item in a sorted list by checking the middle item and throwing away the half that cannot contain the target, then repeating on the half that is left. Each step halves the search, so the time grows with the logarithm of the list's size, written O(log n).
The difference is large. A list of one million sorted items needs at most 20 comparisons, because 220 is just over a million; checking items one by one could take a million. The catch is that the data must be sorted first, and keeping it sorted has its own cost.
You will meet it in database indexes, in looking up values in sorted files, and in a useful debugging habit: git bisect uses the same idea to find the commit that introduced a bug.
2. Quicksort and merge sort
Both sort a list by dividing it into smaller pieces, and both take O(n log n) time in the usual case, but they make different trade-offs:
- Quicksort picks a pivot, moves smaller items to one side and larger items to the other, and repeats on each side. It sorts in place and is fast in practice, but a poor choice of pivot on unlucky data can make it as slow as O(n2).
- Merge sort splits the list in half, sorts each half and merges the two sorted halves. It is always O(n log n) and keeps equal items in their original order, which matters when sorting records by one field after another, but it needs extra memory for the merge.
In practice you will call your language's built-in sort rather than write either one. Understanding them explains why that sort is fast, when it needs extra memory, and whether it keeps equal items in order.
3. Huffman coding
Huffman coding compresses data by giving frequent symbols short codes and rare symbols long ones. It counts how often each symbol appears, then builds a tree by repeatedly joining the two least frequent entries; the path to each symbol in that tree is its code. No code is the start of another, so the compressed stream can be decoded without separators.
It is one part of formats you use every day rather than a compressor on its own. The DEFLATE format behind ZIP and gzip, for example, combines LZ77 with Huffman coding, and JPEG images use Huffman coding as their final step.
4. Breadth-first search
Breadth-first search (BFS) explores a graph level by level: first every neighbour of the starting point, then every neighbour of those, and so on. It uses a queue to remember what to visit next and takes time proportional to the number of nodes and connections, O(V + E).
Because it moves outwards one step at a time, BFS finds the shortest route when every step costs the same. That makes it the right tool for questions such as the fewest clicks between two pages, degrees of connection in a social network, or the nearest free cell on a grid.
5. Depth-first search
Depth-first search (DFS) follows one path as far as it can go before backing up and trying the next. It uses a stack, often simply recursion, and also takes O(V + E) time.
DFS does not find shortest paths, but it is the basis of many other tasks: detecting cycles, ordering tasks so that each comes after the ones it depends on (as build tools and package managers do), finding connected groups, and solving puzzles by trying options and backtracking.
6. Gradient descent
Gradient descent finds values that make a function as small as possible. It starts with a guess, works out which direction makes the error fall fastest, takes a small step that way, and repeats. The size of that step, the learning rate, matters: too large and it overshoots, too small and it crawls.
It is how most machine learning models learn, from simple regression to large neural networks, which adjust their weights to reduce prediction error. You may never write it yourself, but if you work with data or AI, understanding it explains why training needs tuning and why results can vary from run to run.
7. Dijkstra's algorithm
Dijkstra's algorithm finds the shortest path from one point to every other point in a graph whose connections have costs, such as distances or travel times, as long as no cost is negative. It always expands the closest unvisited point next, using a priority queue to pick it efficiently.
Route planning, network routing and delivery scheduling all build on it. A* search, common in games and maps, is Dijkstra's algorithm with an estimate of the remaining distance added to steer it towards the goal.
8. Diffie-Hellman key exchange
Diffie-Hellman lets two parties agree on a shared secret key over a connection that anyone can listen to, without ever sending the key itself. Each side combines its own private value with the other side's public value, and both arrive at the same secret, while an eavesdropper who sees only the public values cannot work it out in practice. That shared key is then used to encrypt the conversation.
Diffie-Hellman does not encrypt data on its own; it solves the problem of agreeing a key. It is also far from outdated: in TLS 1.3, the version of the protocol behind HTTPS, every handshake that does not reuse a pre-shared key uses Diffie-Hellman over finite fields or elliptic curves.
How to learn them
Memorising the code is not the goal. Implement each one once in the language you use, test it against your language's built-in version, then go back to using the library. What stays with you is the reasoning: when data needs to be sorted, why a search is slow, which kind of graph search answers a given question.
That reasoning pays off well beyond interviews. It is the same thinking that goes into choosing an architecture or deciding what a feasibility study needs to test. If you are planning a product rather than a study session, our custom software development page explains how we design and build systems for clients.
Questions people ask
Which algorithm should a beginner learn first?
Binary search. It is short, it shows how much difference a good idea makes, and it teaches the habit of checking edge cases, such as an empty list or a target that is missing.
Do I need algorithms for web or app development?
Rarely by name, but the ideas appear constantly: sorting and searching data, walking through menus and dependencies, and choosing a data structure that keeps a page fast as the data grows.
Are these algorithms still relevant with AI coding tools?
Yes. An assistant can write the code, but you still need to judge whether it chose the right approach and whether it will cope with your data at scale. That judgement comes from understanding how the algorithms behave.

