DSA course menu
Introduction to Data Structures and Algorithms (DSA)
What data structures and algorithms are, why they matter for writing fast programs and passing coding interviews, and how this DSA course is organised.
On this page
A data structure is a way of organising data so it can be used efficiently. An algorithm is a step-by-step procedure for solving a problem. Together they decide whether a program answers in a blink or keeps a user waiting.
You already use both. A Python list is a data structure; "go through the list and keep the largest value" is an algorithm.
Why the choice matters#
Suppose you need to check whether a username is already taken. Two ways to store the names:
taken_list = ["asha", "ravi", "meera", "john", "priya"]
taken_set = {"asha", "ravi", "meera", "john", "priya"}
print("meera" in taken_list)
print("meera" in taken_set)True
TrueBoth give the same answer, but they find it differently:
inon a list checks the names one by one. With a million users, a check can look at a million names.inon a set jumps almost straight to the right place using a hash (you will see how in Hash Tables). It takes about the same time with five names or five million.
The program is correct either way. The data structure decides how well it scales.
Counting the work#
We can make the difference visible by counting how many names each approach inspects:
def steps_in_list(names, target):
steps = 0
for name in names:
steps += 1
if name == target:
break
return steps
for size in [10, 1_000, 100_000]:
names = [f"user{i}" for i in range(size)]
print(size, "names ->", steps_in_list(names, f"user{size - 1}"), "steps")10 names -> 10 steps
1000 names -> 1000 steps
100000 names -> 100000 stepsWhen the list grows 100 times bigger, the worst-case search does 100 times more work. Learning to predict this growth, without running the code, is what Big O notation is for.
What you will learn#
Why Python?#
The examples use Python because it is short and readable, so the idea is not hidden behind syntax. Every structure is still built from scratch where it matters (linked lists, heaps, tries), so you see how it works inside. The ideas carry over directly to C++, Java and other languages; only the syntax changes.
You should be comfortable with Python functions, lists, dictionaries and classes before starting. If any of those are new, take the Python course first.
How to study DSA#
- Type the code yourself. Reading an algorithm is not the same as being able to write it.
- Trace small examples by hand. Write the variables down step by step on paper.
- Ask "what is the cost?" for every solution: how many steps, how much extra memory.
- Practise regularly. A few problems a day beats a marathon once a month.
Key takeaway#
Next, learn the language for describing growth: Big O Notation.
Finished this lesson?