Skip to content
Laviyx Learn

Try

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.

Beginner4 min readUpdated
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:

Python
taken_list = ["asha", "ravi", "meera", "john", "priya"]
taken_set = {"asha", "ravi", "meera", "john", "priya"}

print("meera" in taken_list)
print("meera" in taken_set)
Output
True
True

Both give the same answer, but they find it differently:

  • in on a list checks the names one by one. With a million users, a check can look at a million names.
  • in on 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:

Python
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")
Output
10 names -> 10 steps
1000 names -> 1000 steps
100000 names -> 100000 steps

When 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#

PartTopics
FoundationsBig O, time and space complexity, recursion
Arrays, strings and hashingDynamic arrays, hash tables, two pointers, sliding window, prefix sums
Linked lists, stacks and queuesNodes and pointers, LIFO and FIFO structures
Searching and sortingBinary search, merge sort, quick sort and more
Trees and heapsBinary trees, BSTs, AVL balancing, heaps, tries
GraphsBFS, DFS, topological sort, Dijkstra, A*, union-find, spanning trees
TechniquesBacktracking, greedy algorithms, dynamic programming
InterviewsA problem-solving method and graded practice questions

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#

  1. Type the code yourself. Reading an algorithm is not the same as being able to write it.
  2. Trace small examples by hand. Write the variables down step by step on paper.
  3. Ask "what is the cost?" for every solution: how many steps, how much extra memory.
  4. 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?