Lessons
1 · Foundations (Think Like a Programmer)
2 · Data Structures and Recursion
- 05Arrays and Array-Based Problem Solving
- 06Strings: Characters, Immutability, and Efficient Manipulation
- 07Linked Lists: Nodes, Pointers, and Pointer Reasoning
- 08Stacks and Queues
- 09Hashing: HashMap, HashSet, and Frequency Patterns
- 10Recursion and Backtracking
- 11Trees and Binary Search Trees
- 12Heaps and Priority Queues
3 · Core Algorithms and Reusable Patterns
4 · Advanced Interview Topics
Lesson 1 · Foundations (Think Like a Programmer)
Start Here: Your Roadmap from Zero to Job-Ready DSA
What data structures and algorithms are, why employers test them, what you can honestly expect from this free 28-article course, and the repeatable six-step loop you will use on every problem.
For
Students, fresh graduates and early-career developers who want to learn DSA from the beginning and prepare for software-development interviews.
Level
Before you start
You can type and run a small program in some language. If you have never programmed, read the next three articles slowly; they teach the Java you need.
On this page
Key takeaways
- DSA is about choosing how to store data and how to process it, so that your program stays fast as the input grows.
- Employers use DSA problems as a way to watch you reason, communicate and write careful code. It is not the whole job.
- Learn in order: foundations, essential data structures, reusable patterns, advanced topics, then interview practice.
- Use the same six-step loop on every problem: clarify, example, brute force, optimize, code, test.
- An hour a day for twelve weeks is a realistic start. Nothing here guarantees a job, but it builds the skills interviews look for.
Most people start DSA by opening a coding site, picking a problem called something like "Longest Valid Parentheses", staring at it for forty minutes, and closing the tab feeling stupid. Then they try again the next week. After a month they conclude that they are "not a DSA person".
The problem was never the person. It was the order. Nobody told them that a hard problem is built from smaller ideas, and that those ideas can be learned one at a time.
This course is that order. It has 28 articles, it is free, it uses Java, and it assumes you are starting from the beginning. This first article explains what you are getting into, how to study, and the one habit that will carry you through the rest.
What you will learn
#- What "data structures" and "algorithms" actually mean, in plain words.
- Why companies ask DSA questions, and what they are really checking.
- What this course covers and what you can honestly expect to be able to do afterwards.
- How to study each article so the knowledge sticks.
- A six-step loop that turns "I have no idea" into a plan.
- A progress checklist and a study routine you can follow with limited time.
What DSA means
#A data structure is a way of organising data in memory so that certain operations are easy. An algorithm is a step-by-step procedure for solving a problem.
Everyday life is full of both. Think about how you keep your phone contacts. You could keep them in the order you added them, or alphabetically. Finding "Priya" in the first arrangement means scrolling through everyone. In the second, you can jump to the P section. The contacts are the same. The arrangement (the data structure) changed how quickly you can answer "where is Priya?".
Now think about the procedure you use to find her. "Start at the top and check every name" is an algorithm. "Open the middle, decide whether she comes before or after, and repeat on the correct half" is a different algorithm. Both are correct. One is much faster when you have 5,000 contacts.
So DSA comes down to two questions you will keep asking:
- How should I store this data?
- What steps should I follow to get the answer?
The skill is not memorising a hundred named techniques. It is learning to see which arrangement and which procedure fit a problem, and being able to explain why.
Why employers ask DSA questions
#You may have heard that "nobody uses a red-black tree at work", and that is partly true. Most day-to-day programming is about reading requirements, calling libraries, and fixing bugs. So why do many interviews still include DSA?
Here is the honest answer, without the hype:
- It is a common, comparable test. Interviewers see many candidates. A problem with clear inputs and outputs lets them compare people fairly, especially freshers who have little work history.
- It shows how you think. Do you ask what the input looks like? Do you try a simple solution first? Can you notice that your solution is slow? Can you test your own code?
- It shows whether you can write careful code. Off-by-one mistakes, forgotten empty inputs and unhandled duplicates are the same mistakes that cause production bugs.
- It is a proxy for learning ability. Someone who can learn a new structure and apply it to a fresh problem will probably cope with a new framework too.
None of this means DSA is the only thing that matters. Projects, communication, fundamentals such as databases and operating systems, and attitude all count. But DSA is a skill you can improve with deliberate practice, and that is good news.
What you can honestly expect
#If you work through this course, here is a realistic picture of where you will be:
- You will understand the core data structures and when each one is a good choice.
- You will recognise common patterns such as two pointers, sliding window, recursion, BFS and basic dynamic programming.
- You will be able to read a problem, ask good questions, reason about its complexity and write clean Java for it.
- You will have a process for practising, revising and doing mock interviews.
And here is what this course cannot promise:
- It cannot promise a job. Hiring depends on openings, competition, your projects, your communication and a fair amount of timing.
- It cannot replace practice on problems beyond the exercises here. The exercises teach technique. Fluency comes from solving more problems on your own, and the study plan in Your 12-Week DSA Study and Revision Plan shows how.
- It does not cover every advanced topic. We mark clearly what is essential and what is optional.
How the course is organised
#The articles are in a deliberate order. Each one uses ideas from the ones before it.
Module | Articles | What it builds |
|---|---|---|
1. Foundations | 1 to 4 | How to approach problems, the Java you need, and how to measure speed |
2. Data Structures and Recursion | 5 to 12 | Arrays, strings, linked lists, stacks, queues, hashing, recursion, trees, heaps |
3. Core Algorithms and Patterns | 13 to 18 | Searching, sorting, two pointers, sliding window, prefix sums, greedy, bits and math |
4. Advanced Interview Topics | 19 to 24 | Graphs, shortest paths, dynamic programming, tries, range queries, union-find |
5. From Practice to Job-Ready | 25 to 28 | Interview workflow, a practice project, a study plan, placement preparation |
You will notice recursion sits before trees. That is on purpose: tree code is naturally recursive, so it is easier if you have met recursion first.
What you need before you begin
#- A computer where you can install the Java Development Kit (JDK). This course targets Java 17, a long-term support release, and the code also works on newer versions.
- A way to run Java. Any of these is fine: an IDE such as IntelliJ IDEA Community or VS Code with the Java extensions, or just a terminal with
javacandjava. - Basic programming exposure. If you know what a variable and a loop are, you are ready. If not, Java Essentials for DSA covers what you need, and you can read it right after the next article.
- A notebook or a plain text file for dry runs. Tracing code by hand is the most useful habit in this course.
To check your setup, save the program below as Main.java, then run javac Main.java followed by java Main.
// File: Main.javapublic class Main { // Returns the largest value in numbers. Assumes numbers has at least one element. static int largest(int[] numbers) { int best = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] > best) { best = numbers[i]; } } return best; } public static void main(String[] args) { System.out.println(largest(new int[] {7, 2, 9, 4})); System.out.println(largest(new int[] {-5, -2, -8})); System.out.println(largest(new int[] {42})); }}You should see this:
9-242If you do, your setup works. Notice that the code ran in order from the first line of main, and that we used the first element as the starting "best so far". That small decision, starting from the first element instead of from 0, is why the second call correctly returns -2. If we had started best at 0, an array of negative numbers would wrongly return 0. Small decisions like this are what DSA is made of.
The six-step loop
#Here is the habit that matters most. Whenever you meet a problem, do these six things in order. Do not skip ahead to code.
- Clarify. What is the input? What must the output be? What are the limits on size? What should happen for empty or odd inputs?
- Example. Write one normal example and one tricky example, and work out the answers by hand.
- Brute force. Describe the simplest correct approach, even if it is slow. This is your safety net.
- Optimize. Ask where the brute force wastes work. Which data structure or pattern removes that waste?
- Code. Translate the plan into Java, with clear names and small steps.
- Test. Run your examples, then the edge cases. Trace the code by hand if something is off.
We will deepen each step over the next few articles. For now, watch the loop in action on a small problem.
The loop on "Does this array contain a duplicate?"
#- Clarify. Input: an array of integers. Output:
trueif any value appears at least twice, otherwisefalse. An empty array or an array with one element has no duplicate, so the answer isfalse. - Example.
[3, 1, 4, 1]has two 1s, sotrue.[3, 1, 4]isfalse. - Brute force. Compare every element with every element after it. If any pair is equal, return
true. - Optimize. The brute force compares many pairs. What if we remembered each value we had already seen, and asked "have I seen this before?" for each new value? A structure that answers "have I seen this?" quickly is a
HashSet. We study it properly in Hashing. For now, think of it as a bag that remembers values and can answer yes or no almost instantly. - Code. Both versions are below.
- Test. Run both versions on the examples and on the empty array.
// File: Main.javaimport java.util.HashSet;import java.util.Set;public class Main { // Brute force: compare every pair. Checks about n * (n - 1) / 2 pairs. static boolean hasDuplicateBrute(int[] numbers) { for (int i = 0; i < numbers.length; i++) { for (int j = i + 1; j < numbers.length; j++) { if (numbers[i] == numbers[j]) { return true; } } } return false; } // Optimized: remember what we have seen. One pass over the array. static boolean hasDuplicateSet(int[] numbers) { Set<Integer> seen = new HashSet<>(); for (int value : numbers) { if (seen.contains(value)) { return true; } seen.add(value); } return false; } public static void main(String[] args) { int[][] tests = {{3, 1, 4, 1}, {3, 1, 4}, {}, {5}}; for (int[] test : tests) { System.out.println(hasDuplicateBrute(test) + " " + hasDuplicateSet(test)); } }}true truefalse falsefalse falsefalse falseBoth versions agree on every test, which is a good sign. If they ever disagreed, we would know one of them has a bug.
Dry run of the optimized version
#A dry run means following the code by hand and writing down the state after each step. For [3, 1, 4, 1]:
Step |
|
| Already in | Action |
|---|---|---|---|---|
1 | 3 | empty | no | add 3 |
2 | 1 | {3} | no | add 1 |
3 | 4 | {3, 1} | no | add 4 |
4 | 1 | {3, 1, 4} | yes | return |
The loop stops at step 4, without looking at the rest of the array.
Complexity at a glance: how much faster is it?
#For an array of n values with no duplicate, the brute force does n * (n - 1) / 2 comparisons. The set version does about n look-ups. For n = 1000 that is 499,500 comparisons versus about 1,000 look-ups. For n = 100,000 the brute force needs almost five billion comparisons and will feel stuck, while the set version still finishes quickly. Time and Space Complexity Without the Confusion gives you the language to talk about this precisely. Note that the set version uses extra memory, so it trades space for time. Such trade-offs appear in almost every article.
How to study each article
#Reading about code is not the same as learning to write it. Use this routine for each article:
- Read once for the idea. Do not type anything yet. Aim to explain the idea to an imaginary friend.
- Trace by hand. Follow the dry run on paper. Then change the input and trace again.
- Type the code yourself. Do not copy and paste. Typing makes you notice details.
- Break it on purpose. Give it an empty array, a negative number, a duplicate. See what happens.
- Do the exercises before reading the solutions. Struggling for 15 to 20 minutes is where learning happens. If you are still stuck, read only the first line of the solution, then try again.
- Revise. Come back after a day, a week and a month. The study plan article shows a simple schedule.
How to use the exercises
#Each article ends with three to five exercises, in this rough order of difficulty:
- Trace exercises ask you to predict what code does. They build the habit of reading code carefully.
- Implementation exercises ask you to write a method.
- Debug exercises give you broken code and ask you to find the bug.
- Interview-style exercises are open problems where you apply the six-step loop.
Every exercise has a full solution in a collapsed section underneath, with the reasoning and the complexity, not just the answer. Open a solution only after a real attempt.
A realistic study routine
#You do not need marathon sessions. Consistency beats intensity. A good default is 60 to 90 minutes a day, split like this:
Block | Time | What you do |
|---|---|---|
Learn | 20 minutes | Read part of the article, trace the dry run |
Build | 25 minutes | Type and run the code, change it, break it |
Practise | 20 to 30 minutes | Exercises, attempted before looking at solutions |
Revise | 10 minutes | Review notes from earlier days |
If you only have 30 minutes on some days, do the Learn and Revise blocks and leave coding for the weekend. If you have a busy college semester or a full-time job, the plan in article 27 includes a lighter and an intensive version.
Progress checklist
#Copy this into your notes and tick items as you finish them. "Finished" means you read the article, traced the dry run, typed the code and attempted every exercise.
- 1. Start Here: Your Roadmap from Zero to Job-Ready DSA
- 2. Problem Solving Fundamentals
- 3. Java Essentials for DSA
- 4. Time and Space Complexity
- 5. Arrays
- 6. Strings
- 7. Linked Lists
- 8. Stacks and Queues
- 9. Hashing
- 10. Recursion and Backtracking
- 11. Trees and Binary Search Trees
- 12. Heaps and Priority Queues
- 13. Searching and Sorting
- 14. Two Pointers
- 15. Sliding Window
- 16. Prefix Sums and Difference Arrays
- 17. Greedy Algorithms and Intervals
- 18. Bit Manipulation and Mathematical Patterns
- 19. Graphs
- 20. Shortest Paths and Topological Sorting
- 21. Dynamic Programming Foundations
- 22. Dynamic Programming Practice
- 23. Tries
- 24. Range Queries and Disjoint Set Union
- 25. The Interview Problem-Solving Workflow
- 26. Build a DSA Practice Project
- 27. Your 12-Week Study and Revision Plan
- 28. Indian Fresher Placement and Coding Interview Preparation
Must-know versus nice-to-know
#Not every topic carries equal weight in interviews, and not every company asks the same things. As a rough guide for fresher roles:
- Core for almost everyone: arrays, strings, hashing, sorting and searching, linked lists, stacks and queues, recursion, basic trees, two pointers, sliding window.
- Common at product-focused companies: graphs, heaps, dynamic programming basics, binary search variations, greedy and interval problems.
- Useful but less common: tries, union-find, bit manipulation, segment trees and Fenwick trees.
We label optional material as optional when we get there. If you are short of time, protect the core list first.
Edge cases and common mistakes when starting
#- Jumping to code too early. Most wrong solutions come from solving a problem you did not fully understand.
- Looking at solutions too quickly. If you read the answer after five minutes, you practised reading, not solving.
- Collecting problems instead of understanding patterns. Fifty problems you understood are worth more than three hundred you skimmed.
- Skipping the dry run. If you cannot trace your code by hand, you cannot debug it under interview pressure.
- Comparing yourself to others. Someone else's "I solved it in ten minutes" skips the weeks of practice behind it.
- Never revisiting old problems. Without revision, you forget most of what you learn within weeks.
Exercises
#Exercise 1
Trace
#In the first program above, what does largest(new int[] {3, 3, 3}) return? What happens if you call largest(new int[] {})?
Exercise 2: Apply the loop
#Write the six steps for this problem: "Given an array of integers, count how many of them are even." Include at least two examples and at least one edge case.
Exercise 3: Count the comparisons
#hasDuplicateBrute is given an array of 20 distinct numbers. Exactly how many times is numbers[i] == numbers[j] evaluated? Give the formula and the number.
Exercise 4: Plan your routine
#You have 8 hours a week for DSA. Decide how many articles you will read per week and how you will split the time. Write it down as a short schedule.
Show solutionHide solution
largest(new int[] {3, 3, 3}) returns 3. The loop compares 3 > 3, which is false, so best stays 3.
largest(new int[] {}) throws ArrayIndexOutOfBoundsException because numbers[0] does not exist. The method says in its comment that it assumes at least one element, so this is a contract violation by the caller. In a real program you would either document and enforce this assumption (for example by throwing an IllegalArgumentException with a clear message) or change the method's return type so that "no answer" is possible. The lesson: always decide what should happen for empty input, and write it down.
Exercise 2
Show solutionHide solution
- Clarify. Input: an array of integers (negative values and zero are allowed). Output: a single non-negative integer, the count of even values. Zero counts as even. An empty array returns
0. - Example.
[2, 7, 4, 9]has two even values, so the answer is2. Tricky:[-4, 0, 3]has-4and0as even values, so the answer is2. In Java,-4 % 2is0, so the checkvalue % 2 == 0works for negatives. - Brute force. Walk through the array and test each value. This is already the simplest approach.
- Optimize. Each value must be examined at least once, so one pass of
nsteps is the best possible. Extra memory is not needed. - Code.
// File: Main.javapublic class Main { static int countEven(int[] numbers) { int count = 0; for (int value : numbers) { if (value % 2 == 0) { count++; } } return count; } public static void main(String[] args) { System.out.println(countEven(new int[] {2, 7, 4, 9})); System.out.println(countEven(new int[] {-4, 0, 3})); System.out.println(countEven(new int[] {})); }}220- Test. The three calls above cover a normal case, negatives with zero, and an empty array. Complexity: time O(n), extra space O(1).
Note that the test value % 2 == 0 is safe for negative numbers, whereas value % 2 == 1 would miss negative odd numbers, because -3 % 2 is -1 in Java.
Exercise 3
Show solutionHide solution
With 20 distinct values the code never returns early, so every pair (i, j) with i < j is compared once. The number of such pairs is n * (n - 1) / 2. For n = 20: 20 * 19 / 2 = 190 comparisons.
Why the formula works: the first element is compared with 19 others, the second with 18 others (it was already compared with the first), and so on down to 0. The sum 19 + 18 + ... + 1 + 0 equals 190. You will see this "triangular number" pattern again whenever a loop starts its inner counter from i + 1.
Exercise 4
Show solutionHide solution
There is no single right answer, but here is a sensible one. The first four articles are foundations, so spend one week on those (about 8 hours: 2 hours per article). After that, aim for one article every 4 to 5 hours of study, which is about 1.5 to 2 articles per week at 8 hours.
A weekly shape that works for most people:
Day | Time | Activity |
|---|---|---|
Mon, Tue, Thu | 1.5 hours | Read, trace, type code |
Wed, Fri | 1 hour | Exercises and revision |
Saturday | 2.5 hours | Finish exercises, one timed problem, review notes |
Sunday | rest, or 30 minutes of light revision |
The exact numbers matter less than two things: you have a fixed time slot, and you reserve part of the week for revision. Adjust after the first two weeks, based on what actually happens.
Where to go next
#- Next: Problem Solving Fundamentals: From a Question to an Algorithm turns the six-step loop into a skill.
- If Java is new to you: continue to Java Essentials for DSA straight after.
- A shorter overview of learning DSA is in How to Learn Data Structures and Algorithms Without Burning Out.
- For the interview side, Software Interview Preparation: A 6-Week Plan That Actually Works covers more than DSA, and we come back to the interview process in articles 25 and 28.
Connected lessons
References
Linked from 2 guides
Other pages in the library that point here.
Keep reading
More in Technology →Guide · Technology
API Design for System Design: REST, Status Codes, Pagination and Versioning
Guide · Career
The OA Landscape: Platforms, Formats, Proctoring and Rules
Guide · Career
A LinkedIn Profile That Gets Recruiter Messages

