Skip to content

Beginner: foundations · Thinking in Big-O · topic 1 of 61 · 20 min

What DSA is, and how to learn it

Explanation

A data structure is a way of storing data so that the jobs you need are quick. An algorithm is a clear, step-by-step method to solve a problem. Companies test DSA to see how you think through a new problem, not what you have memorised. This course takes about 18 weeks at one hour a day, with extra practice on free problem sites.

Two words, one idea

A data structure is a way of arranging data in memory so that the operations you need, such as finding, adding or removing an item, are fast. A list, a dictionary and a set in Python are data structures. So are the stacks, queues, trees and graphs you will meet later in this course.

An algorithm is a finite list of clear steps that turns an input into the right output. "Look at every number and remember the biggest one so far" is an algorithm for finding the maximum. A recipe is an algorithm for cooking, written for people instead of computers.

The two always go together. A good data structure makes a simple algorithm fast, and a clever algorithm often needs the right data structure to work. That is why the subject is called DSA, data structures AND algorithms.

Think of it like this: A printed dictionary is a data structure: its words are kept in alphabetical order. Because of that order, you can use a fast algorithm to find a word: open the book near the middle, see whether your word comes before or after that page, and throw away the half you do not need. You never read it page by page. Keeping the data in a smart shape is what makes the fast search possible.
Daily lifeData structureAlgorithmWhere in this course
Finding a word in a dictionary bookSorted arrayBinary search (halve the pages each time)Module 6
The queue at a railway ticket counterQueue (first in, first out)Serve the person at the front, join at the backModule 4
Undo in a text editorStack (last in, first out)Undo the most recent change firstModule 4
A map app suggesting a routeGraph (junctions joined by roads)Shortest path, such as Dijkstra's algorithmModule 9
Contacts in your phoneHash map or sorted listLook up a name quicklyModules 3 and 10

Why companies test DSA

Most coding interviews in India and abroad include one or more rounds of DSA problems, from campus placements at service companies to interviews at product companies and startups. The interviewer is not checking whether you remember a famous answer. They want to see how you think when you meet a problem you have not seen before.

  • Problem solving: can you break a vague problem into clear steps?
  • Cost awareness: do you notice that your first idea is slow, and can you make it faster?
  • Correctness: do you think about empty input, one item, duplicates and negative numbers?
  • Communication: can you explain your plan, write clean code and test it out loud?

These are the same skills you use at work. Choosing a set instead of a list for a lookup can be the difference between a page that loads at once and a report that runs for an hour.

How this course works

  • Weeks 1–6, Beginner: Big-O, arrays, strings, hashing, two pointers, sliding windows, stacks, queues and linked lists.
  • Weeks 7–12, Intermediate: recursion, backtracking, sorting, binary search, trees, heaps and greedy algorithms.
  • Weeks 13–18, Expert: graphs, tries, union-find, bit tricks, dynamic programming and interview strategy.

Plan for about one hour a day, five days a week. Each topic has a short explanation, a deep explanation like this one, a real example, a narrated lesson, coding tasks that are checked in your browser, and a quiz. Each module ends with an exam.

Also practise on free problem sites. LeetCode has interview-style problems sorted by topic and difficulty. GeeksforGeeks has articles and practice problems and is popular for placement preparation in India. HackerRank is used by many companies for online tests, so its editor is worth getting used to. Codeforces runs timed contests that build speed. Pick one main site; you do not need all four.

A problem-solving routine to use every time

  1. Understand: say the problem in your own words. What exactly is the input and the output?
  2. Ask about edge cases: can the input be empty? Can numbers be negative or repeated? How large can it be?
  3. Work two or three small examples by hand, including one tricky one.
  4. Write the brute-force idea first (the simplest correct way) and work out its cost.
  5. Improve: what work is repeated? Can a set, a dictionary, sorting or two pointers remove it?
  6. Code it cleanly with good names, then test it with your examples and the edge cases.
  7. State the time and space cost of your final answer.
python
def find_max(nums):
    if not nums:              # edge case: empty list
        return None
    best = nums[0]            # start with the first item, not 0
    for x in nums[1:]:
        if x > best:
            best = x
    return best

print(find_max([4, 9, 2]))     # Output: 9
print(find_max([-5, -2, -8]))  # Output: -2
print(find_max([]))            # Output: None
The routine in action: the empty list and all-negative numbers were thought about before coding.

Common mistakes

  • Jumping straight into code. Fix: spend the first few minutes on examples and edge cases; it saves time later.
  • Memorising solutions. Fix: learn the pattern behind each problem (for example "use a set to remember what you have seen") so you can use it on new problems.
  • Only reading solutions. Fix: try each problem for 20–30 minutes yourself first, then read, then solve it again a few days later without help.
  • Forgetting edge cases such as an empty list or all-negative numbers. Fix: keep a short checklist and test against it every time.
  • Solving many problems without review. Fix: keep a mistakes notebook; one problem understood well beats five copied.
Tip: Starting best at 0 is a classic bug: for [-5, -2, -8] it would wrongly say 0. Start with the first item instead.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

What DSA is, and how to learn it · 1/8

What is DSA?

Welcome to data structures and algorithms. In this first lesson you will see what the two words mean and how this course will train you for coding interviews.

Prefer a video by a teacher? Find free videos on “what is data structures and algorithms introduction for beginners” on YouTube ↗

In real life: Booking a train ticket

When you search for trains on a railway booking site, many data structures and algorithms work together. Station names are looked up in a hash map or a search index as you type. Trains between two stations are filtered and sorted by departure time. Waiting-list requests are handled first come, first served, like a queue. A site that serves crores of searches a day cannot afford slow lookups, so engineers choose structures by their cost, which is exactly what this course teaches.

python
from collections import deque

waiting = deque()                 # a queue: first in, first out
waiting.append("Asha")
waiting.append("Ravi")
waiting.append("Meena")

print(waiting.popleft())          # the person who came first is served first
print(list(waiting))
Shows Asha, then ['Ravi', 'Meena'].

Practice (0/3 done)

Task 1 · Code · Python

Write find_max(nums) that returns the largest number in the list nums WITHOUT using max() or sorting. If nums is empty, return None. Example: find_max([3, 7, 2]) returns 7. Aim for O(n) time: look at each number once.

Task 2 · Code · Python

Write index_of_max(nums) that returns the INDEX of the largest number. If the largest number appears more than once, return the first index where it appears. If nums is empty, return -1. Do not use max(), sort() or index(). Example: index_of_max([4, 9, 2, 9]) returns 1.

Task 3 · Practice

Write your personal practice plan for the next 6 weeks (Beginner level). Pick one main problem site, set fixed days and times, and decide how you will review mistakes.

Quick quiz

Question 1

1.Which of these is a data structure rather than an algorithm?

Question 2

2.Why can you find a word quickly in a printed dictionary?

Question 3

3.What is an interviewer mainly checking in a DSA round?

Question 4

4.In the routine, what should you write before trying to optimise?

Question 5

5.find_max starts with best = 0. Which input gives a wrong answer?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which of these is a data structure rather than an algorithm?

Answer: A queue

A queue is a way of storing items (first in, first out). The others are step-by-step methods, which are algorithms.

Why can you find a word quickly in a printed dictionary?

Answer: The words are sorted, so you can throw away half the pages at each step

The sorted order (the data structure) is what allows halving (the algorithm).

What is an interviewer mainly checking in a DSA round?

Answer: How you break down and solve a new problem, and explain its cost

Problems change all the time; the skill being tested is problem solving and clear thinking.

In the routine, what should you write before trying to optimise?

Answer: A simple brute-force idea and its cost

A correct brute force gives you a baseline and often shows which repeated work to remove.

find_max starts with best = 0. Which input gives a wrong answer?

Answer: [-4, -2, -9]

For all-negative numbers no item beats 0, so it wrongly returns 0. Start with best = nums[0].

In a 90-minute machine-coding round, what should you do first?Related

Answer: Clarify the requirements and plan briefly

A few minutes of questions and planning avoid building the wrong thing. Then make it work, then make it nice.

From Interview preparation

For a fresher, what is usually tested LESS than DSA and fundamentals?Related

Answer: Large-scale system design

Designing large distributed systems is usually expected after a few years of experience.

From Your study plan and the job hunt

Which data structure checks balanced brackets?Related

Answer: Stack

The most recent opener must match the next closer: last in, first out.

From Data-structure questions in JavaScript

What makes dynamic programming faster than plain recursion for problems like Fibonacci?Related

Answer: Each sub-problem's answer is stored and reused instead of recomputed

Overlapping sub-problems are solved once.

From Core DSA patterns in C++

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Thinking in Big-O” before its exam: Big-O time complexity, Space complexity and amortised cost, Best, average and worst case; analysing loops and recursion, The real cost of Python and JavaScript built-ins.
  2. Module 1 exam: Thinking in Big-O · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Arrays and strings. 61 topics left in the course before the final exam.