Data Structures and Algorithms
Complexity, lists, trees, graphs, sorting and dynamic programming, implemented step by step.
Data Structures and Algorithms feels huge until you learn it in the right order. Here is what to know first, a topic sequence that builds on itself, and a way to practise that works.
By Ali Sher AbbasiPublished 4 min read
Data Structures and Algorithms (DSA) is the study of how to store data so it is quick to use, and how to write step-by-step methods that solve problems efficiently. It is a core university course, the basis of most technical job interviews, and the difference between code that works on ten records and code that works on ten million. It is also the course many students find hardest, usually because they start in the wrong place.
You do not need advanced maths. You do need to be comfortable in one programming language, which means you can write the following without looking anything up:
If any of these feel shaky, spend a week or two on them first. Most DSA confusion is really programming confusion in disguise. Any language works; Python is the shortest to read, and C++ and Java are common in university courses.
Big-O notation describes how the work an algorithm does grows as the input grows. It ignores the speed of your computer and asks: if the list doubles, does the work stay the same, double, or quadruple? Learn this first, because every later topic is judged by it.
O(1), constant: the same work whatever the size. Reading marks[5].O(log n), logarithmic: the problem halves at each step. Binary search.O(n), linear: look at every item once. Finding the largest mark.O(n log n): efficient sorting such as merge sort.O(n²), quadratic: a loop inside a loop over the same data. Comparing every pair.Binary search shows why this matters. To find a value in a sorted list, check the middle; if your target is larger, throw away the left half, otherwise the right half, and repeat.
def binary_search(items, target):
"""Index of target in a sorted list, or -1. O(log n)."""
low, high = 0, len(items) - 1
while low <= high:
mid = (low + high) // 2
if items[mid] == target:
return mid
if items[mid] < target:
low = mid + 1 # target is in the right half
else:
high = mid - 1 # target is in the left half
return -1
print(binary_search([3, 8, 15, 21, 42, 57, 90], 42)) # 4Checking one item at a time would need up to a million comparisons in a list of a million items. Binary search needs about twenty, because a million can only be halved about twenty times before one item is left.
Each step below uses the ones before it. Resist jumping to graphs or dynamic programming early; they are much easier once the foundations are automatic.
O(n²) into O(n).Watching explanations feels productive but fades quickly. For each new topic, work through these four steps:
Keep a short log: the problem, the idea that cracked it, and its Big-O. Before an exam or interview, rereading this log is worth more than starting new problems.
O(n²) when O(n) is possible will often lose marks or time out.DSA is easier to learn with someone who can watch you solve a problem and spot exactly where your reasoning slips. Our Data Structures and Algorithms tutoring is one-to-one and live, in Python, Java or C++, for university courses and interview preparation. We explain and review; we do not complete graded assignments for you. The first class is free.
One-to-one live classes on this topic. The first class is free.
Complexity, lists, trees, graphs, sorting and dynamic programming, implemented step by step.
Classes, inheritance, polymorphism and class design in Java, C++ or Python.
Python fundamentals, C and C++, Java, and JavaScript with web development, taught one-to-one.
Your first language matters less than you think, but the right one for your goal saves weeks of frustration. Here is how to choose, by what you want to do next.
4 min read
Object-oriented programming is easier when every idea is shown on the same example. We build a small library system step by step and name each OOP concept as it appears.
4 min read
Cybersecurity is a huge field, and most beginners start with tools instead of foundations. This roadmap gives you an order that builds real understanding, and shows how to practise without breaking the law.
4 min read