నేరుగా కంటెంట్‌కు వెళ్లండి

ఈ పేజీ ప్రధాన కంటెంట్ ఇంగ్లీషులో ఉంది.ఈ పేజీని అనువదించండి

నైపుణ్యాలు & సాంకేతికతలు

DSA (Data Structures & Algorithms) roadmap

Data structures and algorithms are how programs store data and solve problems efficiently. They're the core of coding interviews at product companies. This roadmap teaches the patterns behind most interview questions, so you recognise them instead of memorising hundreds of problems.

సమయం
⏱ 10–14 weeks
Level
Intermediate
Steps
6 steps
Cheat sheet ↓5 interview Q&As ↓
షేర్

The roadmap

Click a step to open the full guide.

DSA (Data Structures & Algorithms) cheat sheet

The essentials on one screen. Bookmark it for revision.

Problem → pattern

Pair/complement, countsHash map
Sorted array, pairsTwo pointers
Longest/shortest subarraySliding window
Top K / K closestHeap
Sorted search, min possible maxBinary search
Shortest path (unweighted)BFS
Dependencies / orderTopological sort
Count ways / best valueDynamic programming
All combinationsBacktracking

Complexities

Hash map get/putO(1) average
SortingO(n log n)
Heap push/popO(log n)
BFS/DFSO(V + E)
Binary searchO(log n)

Improve performance

  • Choose the right data structure first; it usually matters more than micro-optimisation.
  • Avoid nested loops over large inputs; look for hashing, sorting or two pointers.
  • Cache repeated work (memoisation).
  • Use iterative solutions when recursion depth could overflow.

Security checklist

  • Validate input sizes so algorithms can't be pushed into worst-case time (denial of service).
  • Use well-tested library implementations (sorting, hashing) in production.

Most important interview questions

Click a question to see a strong answer. Each step also has its own questions.

1How do you approach a coding problem you haven't seen?

Clarify input/output and edge cases, work small examples, state a brute force with its complexity, look for a pattern to optimise, code it cleanly, then test with examples and edge cases.

2Array vs linked list?

Arrays give O(1) index access and good cache use but O(n) inserts in the middle; linked lists give O(1) inserts with a pointer but O(n) access.

3the difference between BFS and DFS అంటే ఏమిటి?

BFS explores level by level with a queue (shortest paths); DFS goes deep first with recursion or a stack (exploring components, detecting cycles).

4When is a greedy algorithm correct?

When a locally optimal choice is always part of some globally optimal solution (greedy-choice property), e.g. interval scheduling by earliest finish time.

5a hash collision and how is it handled అంటే ఏమిటి?

Two keys mapping to the same bucket; handled by chaining (lists per bucket) or open addressing (probing for another slot).

Related రోడ్‌మ్యాప్‌లు

1

DSA (Data Structures & Algorithms) · Step 1 of 6 · 1 week

Big-O and problem-solving basics

Measure how fast and how much memory your code uses.

Big-O describes how running time or memory grows as input grows. An O(n) loop over a million items is fine; an O(n²) nested loop over a million items is not.

Use the same routine for every problem: understand the input and output, try small examples, think of a brute-force solution, then improve it using the right data structure or pattern.

What you'll learn

  • Time and space complexity
  • O(1), O(log n), O(n), O(n log n), O(n²)
  • Best, average and worst case
  • A problem-solving routine

Fastest to slowest (for large n)

  1. O(1): hash lookup
  2. O(log n): binary search
  3. O(n): one loop
  4. O(n log n): good sorting
  5. O(n²): nested loops
  6. O(2ⁿ): all subsets

Key concepts

Big-O
How time or memory grows with input size, ignoring constants.
Space complexity
Extra memory used, e.g. a hash map of n items is O(n).

Step by step

  1. 1.1

    Count operations

    How many times does the inner work run as n grows?

  2. 1.2

    Learn the ladder

    O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ).

  3. 1.3

    Use a routine

    Understand → examples → brute force → optimise → code → test.

Notes

  • Drop constants: O(2n) is O(n).
  • Nested loops over the same input usually mean O(n²).

Tips & tricks

  • Always state the complexity of your solution before coding in interviews.
  • Write the brute force first, then optimise.

Interview questions

the time complexity of binary search and why అంటే ఏమిటి?

O(log n): each step halves the remaining search space, so it takes about log₂(n) steps.

The quick way to study this

Learn the 6 common complexities and label the complexity of 20 small snippets.

2

DSA (Data Structures & Algorithms) · Step 2 of 6 · 2 weeks

Arrays, strings and hashing

The most common interview topics.

Most easy and medium questions use arrays with a hash map, two pointers or a sliding window. A hash map turns 'search for a matching item' from O(n) into O(1), which is often the whole trick.

Sliding window handles 'longest/shortest subarray or substring with a condition' problems in O(n).

What you'll learn

  • Arrays and dynamic arrays
  • Strings
  • Hash maps and sets
  • Prefix sums
  • Two pointers
  • Sliding window

Pick the pattern

Hashing

  • Pairs/complements
  • Counting, duplicates
  • Anagrams

Two pointers

  • Sorted arrays
  • Palindromes
  • Remove duplicates in place

Sliding window

  • Longest/shortest substring
  • Max sum of k items
  • At most k distinct

Key concepts

Hash map
Key → value store with O(1) average lookup.
Sliding window
A moving range over an array/string for subarray problems.
Two pointers
Two indexes moving toward/along the data to avoid nested loops.

Step by step

  1. 2.1

    Hash map tricks

    Store what you've seen to find complements, counts or duplicates in O(1).

  2. 2.2

    Two pointers

    Move from both ends of a sorted array, or fast/slow in one pass.

  3. 2.3

    Sliding window

    Grow the right edge, shrink the left when the condition breaks.

  4. 2.4

    Prefix sums

    Precompute running totals for O(1) range sums.

Notes

  • 'Find a pair that sums to X' → hash map or two pointers on sorted data.
  • 'Longest substring with…' → sliding window.

Tips & tricks

  • Draw indexes on paper for pointer problems.
  • Watch for off-by-one errors at window edges.

Interview questions

Two Sum: how do you solve it in O(n)?

Walk the array once with a hash map of value → index; for each number check if target - num is already in the map.

The quick way to study this

Solve 15 problems: 5 hashing, 5 two-pointer, 5 sliding-window.

3

DSA (Data Structures & Algorithms) · Step 3 of 6 · 1 week

Linked lists, stacks and queues

Pointer manipulation and order-based problems.

Linked-list problems test careful pointer updates: reversing, merging, finding cycles. Stacks solve 'matching' and 'next greater element' problems; queues power breadth-first search.

What you'll learn

  • Singly and doubly linked lists
  • Fast and slow pointers
  • Stacks (LIFO)
  • Queues and deques (FIFO)
  • Monotonic stack

Stack vs queue

Stack

  • push / pop at the top
  • Undo, parentheses, DFS

Queue

  • enqueue back, dequeue front
  • BFS, scheduling

Key concepts

Stack (LIFO)
Last in, first out, like a pile of plates.
Queue (FIFO)
First in, first out, like a ticket line.
Monotonic stack
A stack kept in increasing/decreasing order to find next greater/smaller items.

Step by step

  1. 3.1

    Reverse a list

    Track prev, current, next; re-point one link at a time.

  2. 3.2

    Detect a cycle

    Fast pointer moves 2, slow moves 1; if they meet, there's a cycle.

  3. 3.3

    Stack problems

    Valid parentheses, next greater element (monotonic stack).

Notes

  • Use a dummy head node to simplify edge cases.
  • Fast/slow pointers detect cycles and find the middle.

Tips & tricks

  • Draw boxes and arrows before changing pointers.

Interview questions

How do you check if parentheses are balanced?

Push opening brackets on a stack; on a closing bracket, the top must be its matching opener. At the end the stack must be empty.

The quick way to study this

Implement a linked list, stack and queue yourself once, then solve 10 problems.

4

DSA (Data Structures & Algorithms) · Step 4 of 6 · 2 weeks

Trees, heaps and binary search

Hierarchies, priorities and halving the search space.

Tree problems are mostly recursion: solve for the left and right subtrees, then combine. Heaps give quick access to the smallest or largest item, perfect for 'top K' problems. Binary search halves the search space each step: O(log n).

What you'll learn

  • Binary trees and traversals
  • Binary search trees
  • Recursion
  • Heaps / priority queues
  • Binary search (and on the answer)
  • Tries

A binary search tree

  • 8
  • 3
  • 1
  • 6
  • 10
  • 14

Key concepts

BST property
Left < node < right, so in-order traversal is sorted.
Heap
Tree where the parent is always ≤ (min-heap) its children; O(log n) insert/remove.
Height
Balanced trees have height O(log n); skewed trees O(n).

Step by step

  1. 4.1

    Traversals

    Pre-, in-, post-order (DFS) and level-order (BFS).

  2. 4.2

    Recursive thinking

    Answer = combine(left answer, right answer).

  3. 4.3

    Heaps

    Keep the top K items with a size-K heap.

  4. 4.4

    Binary search variants

    First/last position; search on the answer space.

Notes

  • In-order traversal of a BST gives sorted order.
  • 'Top K' or 'K closest' → heap.

Tips & tricks

  • Write the base case of every recursion first.

Interview questions

How do you find the K largest elements efficiently?

Keep a min-heap of size K: push each element and pop when size exceeds K. Time O(n log K).

The quick way to study this

Practise the four traversals until you can write them from memory.

5

DSA (Data Structures & Algorithms) · Step 5 of 6 · 2 weeks

Graphs

Networks, grids, dependencies and shortest paths.

Many problems are graphs in disguise: grids, course prerequisites, social networks, routes. BFS finds the shortest path in unweighted graphs; DFS explores everything; topological sort orders tasks with dependencies; Dijkstra handles weighted shortest paths.

What you'll learn

  • Adjacency lists
  • BFS and DFS
  • Grids as graphs
  • Topological sort
  • Union-find
  • Dijkstra's shortest path

Which graph algorithm?

BFS

  • Shortest path (unweighted)
  • Levels, nearest

DFS

  • Components, cycles
  • All paths

Dijkstra

  • Shortest path (weighted, no negatives)

Key concepts

BFS
Explores nearest first; gives shortest paths when edges are equal.
Topological sort
Orders tasks so each comes after its dependencies (needs no cycles).
Union-find
Tracks which items are in the same group, fast.

Step by step

  1. 5.1

    Represent graphs

    Adjacency list: node → list of neighbours.

  2. 5.2

    BFS

    Queue, visit level by level: shortest path in unweighted graphs.

  3. 5.3

    DFS

    Recursion or stack: connected components, cycle detection.

  4. 5.4

    Advanced

    Topological sort, union-find, Dijkstra.

Notes

  • Track visited nodes to avoid infinite loops.
  • Shortest path, unweighted → BFS.

Tips & tricks

  • Treat a 2D grid as a graph with 4 neighbours per cell.

Interview questions

How do you count islands in a grid?

Loop over cells; when you find unvisited land, increase the count and run BFS/DFS to mark the whole island as visited. O(rows × cols).

The quick way to study this

Solve 10 problems: islands, shortest path, course schedule, network delay.

6

DSA (Data Structures & Algorithms) · Step 6 of 6 · 3 weeks

Dynamic programming and greedy

Optimal solutions by reusing sub-results.

Dynamic programming solves a problem by combining answers to overlapping smaller problems and storing them so each is solved once. Start with a recursive solution, add a cache (memoisation), then convert to a table if needed.

Greedy algorithms take the best local choice at each step; they only work when you can prove local choices lead to the global best.

What you'll learn

  • Recursion + memoisation
  • Bottom-up tables
  • 1D and 2D DP
  • Knapsack, LIS, LCS patterns
  • Greedy choices
  • Backtracking

From brute force to DP

  1. Recursive brute force
  2. Spot repeated states
  3. Memoise (top-down)
  4. Tabulate (bottom-up)
  5. Optimise space

Key concepts

Overlapping subproblems
The same smaller problem is solved many times → cache it.
Optimal substructure
The best answer is built from best answers to subproblems.
Greedy
Take the best local choice; only correct when provable.

Step by step

  1. 6.1

    Write the recursion

    Define the answer for a smaller input.

  2. 6.2

    Add memoisation

    Cache results of each state.

  3. 6.3

    Build a table

    Fill dp from the smallest cases up.

  4. 6.4

    Optimise space

    Keep only the rows you need.

Notes

  • DP = recursion + caching.
  • Backtracking explores all choices and undoes them (permutations, subsets).

Tips & tricks

  • Define the state in words: 'dp[i] = best answer for the first i items'.

Interview questions

Climbing stairs (1 or 2 steps): how many ways to reach step n?

ways(n) = ways(n−1) + ways(n−2), like Fibonacci. Bottom-up with two variables: O(n) time, O(1) space.

The quick way to study this

Learn the 5 classic DP patterns with 3 problems each.

ఈ పేజీని షేర్ చేయండి