0% found this document useful (0 votes)
31 views33 pages

Advanced Data Structures and Algorithms Roadmap PDF by ScholarHat

Advanced Data Structures and Algorithms Roadmap PDF by ScholarHat

Uploaded by

ScholarHat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views33 pages

Advanced Data Structures and Algorithms Roadmap PDF by ScholarHat

Advanced Data Structures and Algorithms Roadmap PDF by ScholarHat

Uploaded by

ScholarHat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Swipe

Data Structures &


Algorithms (DSA)
ROADMAP (LEVEL-2)
Advanced
2024 EDITION

Level Up Your Career

AMIT KUMAR GHOSH


MENTOR AND VICE PRESIDENT AT SCHOLARHAT
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP

DSA Career Scope


Why learn DSA?
DSA is a fundamental skill for careers in software development, data science,
Machine learning, and many more. These stats back the statement.

World Top Companies Using DSA

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP

1 Sorting Algorithms (Review)


In this, we will be reviewing all the sorting algorithms
covered in Level-1 including Advanced Sorting Algorithms.
1. Bubble Sort
2. Selection Sort
3. Insertion Sort
4. Merge Sort
5. Quick Sort
6. Heap Sort
7. Advanced Sorting Algorithms:
Counting Sort: suitable for sorting integers within a
specific range.
Radix Sort: sorts integers by processing individual
digits of the numbers.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

2 Trees
Here's a roadmap for Trees in DSA:
1. Generic Trees
Understand the structure of a generic tree i.e., Node,
Parent and Child.
Learn about traversal on generic trees (pre-order, post-
order, level-order).
2. Binary Trees
These are the types: Full Binary Tree, Complete Binary
Tree, Perfect Binary Tree.
Implement Tree Traversal (Inorder, Preorder,
Postorder).
3. Binary Search Tree (BST)
Understand operations (Insertion, Deletion) on BST.
Implement Inorder Successor / Predecessor.
4. AVL Trees
Learn about rotations (left rotation, right rotation, double
rotation) used to maintain balance.
Understand some self-balancing trees.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Question to Master Trees


Question 1: Vertical Order Traversal of a Binary Tree
Given the root of a binary tree, calculate the vertical order
traversal of the binary tree.
For each node at position (row, col), its left and right
children will be at positions (row + 1, col - 1) and (row + 1,
col + 1) respectively. The root of the tree is at (0, 0).

The vertical order traversal of a binary tree is a list of top-to-


bottom orderings for each column index starting from the
leftmost column and ending on the rightmost column. There
may be multiple nodes in the same row and same column.
In such a case, sort these nodes by their values.
Return the vertical order traversal of the binary tree.

Question 2: Binary Tree Cameras


You are given the root of a binary tree. We install cameras
on the tree nodes where each camera at a node can
monitor its parent, itself, and its immediate children.
Return the minimum number of cameras needed to monitor
all nodes of the tree.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Question to Master Trees


Question 3: Binary Tree Max Path Sum
A path in a binary tree is a sequence of nodes where each
pair of adjacent nodes in the sequence has an edge
connecting them. A node can only appear in the sequence
at most once. Note that the path does not need to pass
through the root. The path sum of a path is the sum of the
node's values in the path.
Given the root of a binary tree, return the maximum path
sum of any non-empty path.

Question 4: Delete Node in a BST


Given a root node reference of a BST and a key, delete the
node with the given key in the BST. Return the root node
reference (possibly updated) of the BST.
Basically, the deletion can be divided into two stages:
1. Search for a node to remove.
2. If the node is found, delete the node.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Question to Master Trees


Question 5: Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or
object into a sequence of bits so that it can be stored in a
file or memory buffer, or transmitted across a network
connection link to be reconstructed later in the same or
another computer environment.

Design an algorithm to serialize and deserialize a binary


tree. There is no restriction on how your
serialization/deserialization algorithm should work. You just
need to ensure that a binary tree can be serialized to a
string and this string can be deserialized to the original tree
structure.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

3 Advanced Trees
Below are some Advanced Trees in Data Structures:
1. Segment Trees
Range Queries: Find the sum, minimum, maximum,
or other aggregate value within a specific range of
indices in the original array.
Lazy Propagation: Learn about lazy propagation
techniques to optimize range update operations in
Segment Trees, especially when dealing with large
ranges or frequent updates.
2. K-dimensional Trees
K-D Trees: Learn about the recursive division
approach used to construct Kd-Trees.
3. Suffix Trees
Understand the properties of suffix trees, and their
applications in string processing.
Learn about the relationship between suffix trees
and suffix arrays.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

4 HashMap and Sets


Hashing involves mapping data of arbitrary size to fixed-size
values, typically for the purpose of quick data retrieval. It is
commonly used to implement hash tables.
Here’s a roadmap to master Hashing:
Understand what hashing is and how it involves
transforming data into a fixed-size value.
Learn hash functions that map data to hash codes.
Ensure proper handling of hashing collisions and
efficient retrieval, insertion, and deletion operations.
HashSet: Uses a HashMap internally to store elements,
allowing for constant-time operations.
TreeSet: Implements a self-balancing BST internally,
maintaining elements in sorted order.
Compare the characteristics of HashSet and TreeSet,
including performance, memory usage, and ordering.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master HashMap


Question 1: Grid Illumination
There is a 2D grid of size n x n where each cell of this grid
has a lamp that is initially turned off. You are given a 2D
array of lamp positions lamps, where lamps[i] = [rowi, coli]
indicates that the lamp at grid[rowi][coli] is turned on. Even if
the same lamp is listed more than once, it is turned on.
When a lamp is turned on, it illuminates its cell and all other
cells in the same row, column, or diagonal.

Question 2: Brick Wall


There is a rectangular brick wall in front of you with n rows
of bricks. The ith row has some number of bricks each of
the same height (i.e., one unit) but they can be of different
widths. The total width of each row is the same.
Draw a vertical line from the top to the bottom and cross the
least bricks. If your line goes through the edge of a brick,
then the brick is not considered as crossed. You cannot
draw a line just along one of the two vertical edges of the
wall, in which case the line will obviously cross no bricks.
Given the 2D array wall that contains the information about
the wall, return the minimum number of crossed bricks after
drawing such a vertical line.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master HashMap


Question 3: Find all Anagrams in a String
Given two strings s and p, return an array of all the start
indices of p's anagrams in s. You may return the answer in
any order. An Anagram is a word or phrase formed by
rearranging the letters of a different word or phrase, typically
using all the original letters exactly once.

Question 4: Minimum Window Substring


Given two strings s and t of lengths m and n respectively,
return the minimum window substring of s such that every
character in t (including duplicates) is included in the
window. If there is no such substring, return the empty string
"".

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

5 Trie
A tree-like data structure used to store a dynamic set of
strings where each node represents a common prefix of a
group of strings.
Here’s a roadmap to master Trie:
1. Introduction to Trie:
Understand the structure of a Trie, which consists
of nodes representing characters, with edges linking
nodes to form words.
Learn about the properties of Tries (prefix
matching, space optimization, and efficient string
operations).
2. Trie Implementation:
Implement different Operations on Trie like
Insertion, Searching and Deletion

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Trie


Question 1: Implement Trie (Prefix Tree)
Implement the Trie class:
Trie() Initializes the trie object.
void insert(String word) Inserts the string word into the
trie.
boolean search(String word) Returns true if the string
word is in the trie (i.e., was inserted before), and false
otherwise.
boolean startsWith(String prefix) Returns true if there is
a previously inserted string word that has the prefix
prefix, and false otherwise.

Question 2: Maximum XOR of Two Numbers in an Array


Given an integer array nums, return the maximum result of
nums[i] XOR nums[j], where 0 <= i <= j < n.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Trie


Question 3: Maximum XOR With an Element From Array
You are given an array nums consisting of non-negative
integers. You are also given a queries array, where
queries[i] = [xi, mi].

The answer to the ith query is the maximum bitwise XOR


value of xi and any element of nums that does not exceed
mi. In other words, the answer is max(nums[j] XOR xi) for all
j such that nums[j] <= mi. If all elements in nums are larger
than mi, then the answer is -1.
Return an integer array answer where answer.length ==
queries.length and answer[i] is the answer to the ith query.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

6 Advanced Heap: Binary Heap


A binary heap is a complete binary tree that adheres to a
specific heap property. This property defines how elements
are arranged based on their values.
Here's a roadmap for Binary Heap in DSA:
1. Introduction to Heap
Understand what a heap is and its basic properties.
Types of Heap: Min Heap and Max Heap.
Heap property: There are two types of binary
heaps: Min-heap: The value at each node is less
than or equal to the values of its children.
Max-heap: The value at each node is greater than
or equal to the values of its children.
2. Heapify Operations
Explore different strategies for heapify operations,
such as bottom-up heap construction and top-
down heap construction.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Heap


Question 1: Minimum number of refueling spots
A car travels from a starting position to a destination which
is target miles east of the starting position.
There are gas stations along the way. The gas stations are
represented as an array stations where stations[i] =
[positioni, fueli] indicates that the ith gas station is positioni
miles east of the starting position and has fueli liters of gas.
The car starts with an infinite tank of gas, which initially has
startFuel liters of fuel in it. It uses one liter of gas per one
mile that it drives. When the car reaches a gas station, it
may stop and refuel, transferring all the gas from the station
into the car.

Return the minimum number of refueling stops the car must


make in order to reach its destination. If it cannot reach the
destination, return -1.
Note that if the car reaches a gas station with 0 fuel left, the
car can still refuel there. If the car reaches the destination
with 0 fuel left, it is still considered to have arrived.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Heap


Question 2: Find Median from Data Stream
The median is the middle value in an ordered integer list.
If the size of the list is even, there is no middle value, and
the median is the mean of the two middle values.
For example, for arr = [2,3,4], the median is 3.
For example, for arr = [2,3], the median is (2 + 3) / 2 =
2.5.
Implement the MedianFinder class:
MedianFinder() initializes the MedianFinder object.
void addNum(int num) adds the integer num from the
data stream to the data structure.
double findMedian() returns the median of all elements
so far. Answers within 10-5 of the actual answer will be
accepted.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

7 Graphs
Graphs are used to represent relationships between pairs of
objects. Graphs are composed of vertices (nodes) and
edges (connections between nodes).
Here's a roadmap for Graphs in DSA:
1. Introduction to Graphs
Understand graphs including vertices, edges etc.
2. Graph Representation
Adjacency Matrix: two-dimensional array (matrix)
where each cell indicates whether there is an edge
between two vertices.
Adjacency List: store the graph as an array of lists
where each list represents the neighbors of a vertex
3. Graph Traversal
Depth-First Search (DFS)
Breadth-First Search (BFS)

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Graphs


Question 1: Bus Routes
ou are given an array routes representing bus routes where
routes[i] is a bus route that the ith bus repeats forever.
For example, if routes[0] = [1, 5, 7], this means that the
0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7
-> 1 -> ... forever.
You will start at the bus stop source (You are not on any
bus initially), and you want to go to the bus stop target. You
can travel between bus stops by buses only.
Return the least number of buses you must take to travel
from source to target. Return -1 if it is not possible.

Question 2: Swim in Rising Water


You are given an n x n integer matrix grid where each value
grid[i][j] represents the elevation at that point (i, j).
The rain starts to fall. At time t, the depth of the water
everywhere is t. You can swim from a square to another 4-
directionally adjacent square if and only if the elevation of
both squares individually are at most t. You can swim infinite
distances in zero time. Return the least time until you can
reach the bottom right square (n - 1, n - 1) if you start at the
top left square (0, 0).
www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master Graphs


Question 3: Sliding Puzzle
On an 2 x 3 board, there are five tiles labeled from 1 to 5,
and an empty square represented by 0. A move consists of
choosing 0 and a 4-directionally adjacent number and
swapping it.
The state of the board is solved if and only if the board is
[[1,2,3],[4,5,0]].
Given the puzzle board board, return the least number of
moves required so that the state of the board is solved. If it
is impossible for the state of the board to be solved, return
-1.

Question 4: Regions Cut by Slashes


An n x n grid is composed of 1 x 1 squares where each 1 x
1 square consists of a '/', '\', or blank space ' '. These
characters divide the square into contiguous regions.
Given the grid grid represented as a string array, return the
number of regions.
Note that backslash characters are escaped, so a '\' is
represented as '\\'.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

8 Greedy Algorithms
1. Dijkstra's Algorithm:
Learn about Dijkstra's algorithm for finding the
shortest path from a single source vertex to all other
vertices in a weighted graph with non-negative edge
weights.
2. Huffman Coding:
Learn about Huffman coding, uses a greedy
approach to construct an optimal prefix-free binary
tree for encoding symbols.
3. Spanning Tree Algorithms:
Prim's algorithm: starts with an arbitrary vertex,
iteratively adds the edge with the minimum weight
that connects the current tree to an unvisited vertex,
until all vertices are included.
Kruskal's algorithm: Another greedy algorithm that
sorts edges by weight in ascending order, and
iteratively adds edges to the tree as long as they
don't create a cycle.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

9 Backtracking
Backtracking is a systematic method for generating all
possible solutions to a problem by traversing a search
space, making choices at each step and backtracking when
a solution cannot be found
Here's a roadmap for Backtracking in DSA:
1. Introduction to Backtracking:
Learn about the recursive nature of backtracking
algorithms and how to design them to efficiently
explore the solution space.
2. Typical Backtracking Problems:
N-Queens Problem:
Understand the classic N-Queens problem, where
the goal is to place N queens on an NxN
chessboard such that no two queens attack each
other.
Sudoku Solver:
Explore the Sudoku puzzle-solving problem, where
the goal is to fill a 9x9 grid with digits from 1 to 9
subject to certain constraints.
www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Backtracking
Question 1: Permutations
Given an array nums of distinct integers, return all possible
permutations. You can return the answer in any order.

Question 2: Permutation Sequence


The set [1, 2, 3, ..., n] contains a total of n! unique
permutations. By listing and labeling all of the permutations
in order, we get the following sequence for n = 3:
1. "123"
2. "132"
3. "213"
4. "231"
5. "312"
6. "321"
Given n and k, return the kth permutation sequence.

Question 3: N Queens
Given a string containing digits from 2-9 inclusive, return all
possible letter combinations that the number could
represent.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

10 Dynamic Programming
A powerful optimization technique used to solve problems
by breaking them down into smaller subproblems and
storing the solutions to these subproblems to avoid
redundant calculations.
Here's a roadmap for Dynamic Programming in DSA:
1. Introduction to Dynamic Programming: Understand
the concepts of Dynamic Programming.
2. Understand common DP techniques:
Tabulation: uses an iterative approach to store
solutions in a table, avoiding recursion altogether.
Memoization: stores solutions to subproblems in a
dictionary or hash table, allowing for efficient
retrieval when needed during recursion.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Dynamic Programming
Question 1: Russian Doll Envelopes
You are given a 2D array of integers envelopes where
envelopes[i] = [wi, hi] represents the width and the height of
an envelope.
One envelope can fit into another if and only if both the
width and height of one envelope are greater than the other
envelope's width and height.
Return the maximum number of envelopes you can Russian
doll (i.e., put one inside the other).

Question 2: Burst Balloons


You are given n balloons, indexed from 0 to n - 1. Each
balloon is painted with a number on it represented by an
array nums. You are asked to burst all the balloons.
If you burst the ith balloon, you will get nums[i - 1] * nums[i] *
nums[i + 1] coins. If i - 1 or i + 1 goes out of bounds of the
array, then treat it as if there is a balloon with a 1 painted on
it. Return the maximum coins you can collect by bursting the
balloons wisely.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Dynamic Programming
Question 3: Count Different Palindromic Subsequences
Given a string s, return the number of different non-empty
palindromic subsequences in s. Since the answer may be
very large, return it modulo 109 + 7.
A subsequence of a string is obtained by deleting zero or
more characters from the string.
A sequence is palindromic if it is equal to the sequence
reversed.
Two sequences a1, a2, ... and b1, b2, ... are different if
there is some i for which ai != bi.

Question 4: Regular Expression Matching


Given an input string s and a pattern p, implement regular
expression matching with support for '.' and '*' where:
'.' Matches any single character.​​
'*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not
partial).

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Dynamic Programming
Question 5: Palindrome Partitioning
Given a string s, partition s such that every substring of the
partition is a palindrome. Return the minimum cuts needed
for a palindrome partitioning of s.

Question 6: Frog Jump


A frog is crossing a river. The river is divided into some
number of units, and at each unit, there may or may not
exist a stone. The frog can jump on a stone, but it must not
jump into the water.
Given a list of stones positions (in units) in sorted ascending
order, determine if the frog can cross the river by landing on
the last stone. Initially, the frog is on the first stone and
assumes the first jump must be 1 unit.
If the frog's last jump was k units, its next jump must be
either k - 1, k, or k + 1 units. The frog can only jump in the
forward direction.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Dynamic Programming
Question 7: Longest Increasing Subsequence
Given an integer array nums, return the length of the
longest strictly increasing
subsequence.

Question 8: Minimum Path Sum


Given a m x n grid filled with non-negative numbers, find a
path from top left to bottom right, which minimizes the sum
of all numbers along its path.

Question 9: Edit Distance


Given two strings word1 and word2, return the minimum
number of operations required to convert word1 to word2.
You have the following three operations permitted on a
word:
Insert a character
Delete a character
Replace a character

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Questions to Master
Dynamic Programming
Question 10: Longest Common Subsequence
Given two strings text1 and text2, return the length of their
longest common subsequence. If there is no common
subsequence, return 0.
A subsequence of a string is a new string generated from
the original string with some characters (can be none)
deleted without changing the relative order of the remaining
characters.
For example, "ace" is a subsequence of "abcde".
A common subsequence of two strings is a subsequence
that is common to both strings.

Question 11: Best time to buy ans sell stock


You are given an array prices where prices[i] is the price of
a given stock on the ith day. You want to maximize your
profit by choosing a single day to buy one stock and
choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this
transaction. If you cannot achieve any profit, return 0.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Data Structures Tutorial


ScholarHat offers concise, insightful DSA articles.
Dive into DSA with clear explanations and
practical examples, perfect for enhancing your
programming skills.

Learn Sorting Algorithms


Learn Trees:
Trees in DSA
Segment Trees
AVL Trees
Spanning Trees
Learn Hash Table
Learn Linked List
Learn Stack
Learn Queue
Learn Heap
Learn Graphs
Learn Greedy Algorithm

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

How to follow this roadmap?


At ScholarHat, we believe mastering a technology
is a three-step process as mentioned below:

Step1 - Learn Skills: You can learn Data structures and


Algorithm through Videos on YouTube or Videos
based courses. For topic revision and recalling make
short notes. Solve Algorithmic Challenges on Platforms
like LeetCode, HackerRank, etc.
Step2 - Build Experience: You can build hands-on
experience by creating workflow using Data Structures
and Algorithms like Mini Calculator, Fitness
Application, Banking System etc.
Step3 - Empower Yourself: Build your strong profile
by mentioning all the above skills with hands-on
experience on Data Structures. Prepare yourself with
interview Q&A about DSA to crack your next job
interview.

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP Swipe

Congrats!
You are just one interview away!

www.scholarhat.com
DATA STRUCTURES FOR BEGINNERS (LEVEL-2) ROADMAP

WAS THIS
HELPFUL?
Share with your friend who needs it!

Love. Like. Comment. Share.

Learn. Build. Empower.

You might also like