Beginner: foundations · Thinking in Big-O · topic 1 of 61 · 20 min
What DSA is, and how to learn it
Explanation
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.
| Daily life | Data structure | Algorithm | Where in this course |
|---|---|---|---|
| Finding a word in a dictionary book | Sorted array | Binary search (halve the pages each time) | Module 6 |
| The queue at a railway ticket counter | Queue (first in, first out) | Serve the person at the front, join at the back | Module 4 |
| Undo in a text editor | Stack (last in, first out) | Undo the most recent change first | Module 4 |
| A map app suggesting a route | Graph (junctions joined by roads) | Shortest path, such as Dijkstra's algorithm | Module 9 |
| Contacts in your phone | Hash map or sorted list | Look up a name quickly | Modules 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
- Understand: say the problem in your own words. What exactly is the input and the output?
- Ask about edge cases: can the input be empty? Can numbers be negative or repeated? How large can it be?
- Work two or three small examples by hand, including one tricky one.
- Write the brute-force idea first (the simplest correct way) and work out its cost.
- Improve: what work is repeated? Can a set, a dictionary, sorting or two pointers remove it?
- Code it cleanly with good names, then test it with your examples and the edge cases.
- State the time and space cost of your final answer.
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: NoneCommon 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.
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
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.
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))Practice (0/3 done)
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.
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.
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
Read more (free)
Related help
Related topics
- Big-O time complexityThinking in Big-O · same module
- Space complexity and amortised costThinking in Big-O · same module
- Best, average and worst case; analysing loops and recursionThinking in Big-O · same module
- Interview preparationFrontend Web Development · Build, deploy and get hired
- Your study plan and the job huntInterview strategy and mock problems
- Data-structure questions in JavaScriptJavaScript Programming (language in depth) · Interview preparation and career
Questions people ask about this
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.
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.
Which data structure checks balanced brackets?Related
Answer: Stack
The most recent opener must match the next closer: last in, first out.
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.
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
- 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.
- Module 1 exam: Thinking in Big-O · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Arrays and strings. 61 topics left in the course before the final exam.