This README serves as a structured record of all the Data Structures and Algorithms (DSA) topics I have studied, along with problem-solving approaches, time complexities, and solved problems. This will help in tracking progress, revisiting concepts, and improving problem-solving skills.
Each topic has:
- β Checkmark to indicate completion.
- π Priority Level (High/Medium/Low) to decide importance.
- π Understanding Section to summarize key concepts.
- π Solved Problems section to list related problems.
- Status: In Progress / Completed
- π Priority: High
- What is Binary Search?
Binary Search is an efficient searching algorithm that works on sorted arrays by repeatedly dividing the search space in half. - Approach:
- Find the middle element.
- If the target is equal to the middle element, return the index.
- If the target is smaller, search the left half.
- If the target is larger, search the right half.
- Repeat this process until the search space is exhausted.
- When to Use?
- When the array is sorted.
- When you need a logarithmic time complexity solution.
- Time Complexity:
- Best case: O(1)
- Worst & Average case: O(log n)
- Solved Problems:
- Leetcode 704: Binary Search
- [Find in Mountain Array] (https://leetcode.com/submissions/detail/1594264486/)
- [Peak Index in a Mountain Array] (https://leetcode.com/submissions/detail/1594214185/)
- [Find Peak Element] (https://leetcode.com/submissions/detail/1594139855/)
- [Ceiling and Floor number] (https://www.geeksforgeeks.org/ceiling-in-a-sorted-array/, https://www.naukri.com/code360/problems/ceiling-in-a-sorted-array_1825401?leftPanelTabValue=SUBMISSION)
- [Find First and Last Position of Element in Sorted Array] (https://leetcode.com/submissions/detail/1593118638/)
- [Search in Rotated Sorted Array] (https://leetcode.com/submissions/detail/1593897478/)
- [Find Smallest Letter Greater Than Target] (https://leetcode.com/submissions/detail/1591697009/)
- [Infinite Sorted Array] (https://www.geeksforgeeks.org/find-position-element-sorted-array-infinite-numbers/)
- [Find Minimum Element in Sorted and Rotated Array] (https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/)
- Leetcode 33: Search in Rotated Sorted Array
- [Find K Rotation] (https://takeuforward.org/arrays/find-out-how-many-times-the-array-has-been-rotated/)
- [Check if Array Is Sorted and Rotated] (https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/submissions/)
- π Priority: Medium
- What is Bubble Sort?
Bubble Sort is a simple comparison-based algorithm where each pair of adjacent elements is compared and swapped if they are in the wrong order. - Time Complexity: O(nΒ²), Best Case O(n) when array is already sorted.
- Solved Problems:
- π Priority: Medium
- What is Selection Sort?
Selection Sort selects the smallest (or largest) element from the unsorted part and swaps it with the first unsorted element. - Time Complexity: O(nΒ²)
- Solved Problems:
- π Priority: Medium
- What is Insertion Sort?
Insertion Sort builds the sorted array one element at a time by comparing and inserting elements into their correct position. - Time Complexity: O(nΒ²), Best Case O(n)
- Solved Problems:
- π Priority: High
- What is Cycle Sort?
Cycle Sort is an in-place, non-stable sorting algorithm optimal for cases where memory writes are costly. It's mainly used when elements range from 1 to n or 0 to n. - Time Complexity: O(n)
- Solved Problems:
- π Priority: High
- What is Merge Sort?
Merge Sort is a divide and conquer algorithm. It divides the array into halves, sorts each half, and merges them to produce a sorted array. - Key Idea:
Recursively split the array into two halves, then merge them in a sorted way. - Time Complexity:
- Worst:
O(n log n)
- Best:
O(n log n)
- Space:
O(n)
(not in-place by default)
- Worst:
- When to Use:
When you need guaranteedO(n log n)
performance, especially with large datasets. - Solved Problems:
- Status: In Progress / Completed
- π Priority: High
- What is Kadane's Algorithm?
Kadane's Algorithm is used to find the maximum sum subarray in an array using a dynamic approach. - Approach:
- Initialize
max_sum
andcurrent_sum
as the first element. - Iterate through the array and update
current_sum
by adding the current element or starting fresh. - Update
max_sum
whenevercurrent_sum
is higher.
- Initialize
- When to Use?
- When finding the largest sum of contiguous elements.
- Time Complexity:
- O(n)
- Solved Problems:
- [Leetcode 53: Maximum Subarray](https://leetcode.com/problems/maximum-subarray/
- Status: In Progress / Completed
- π Priority: Medium
- What are 2D Arrays?
2D arrays are arrays where each element is itself an array, forming a matrix-like structure. - Approach:
- Iterating using nested loops.
- Common operations: searching, transposing, rotating.
- When to Use?
- When dealing with matrices or grids.
- Time Complexity:
- Varies based on operation.
- Solved Problems:
-
π Priority: High
-
What is Two Pointer Technique?
This technique uses two pointers (usuallyi
andj
) that iterate through the array to solve problems in a linear or near-linear time. -
When to Use:
- On sorted arrays or strings
- To find pairs or subarrays
- Problems like removing duplicates, finding a pair with a sum, merging arrays, etc.
-
Time Complexity:
O(n)
orO(n log n)
depending on the problem -
Solved Problems:
-
π Priority: High
-
What is Sliding Window Technique?
This technique is used to reduce nested loops to a single loop by maintaining a "window" of elements over the array or string and sliding it based on conditions. -
Types:
- πΉ Fixed-size window β size
k
is constant - πΉ Dynamic-size window β window expands or shrinks based on constraints (e.g., sum, characters, frequency)
- πΉ Fixed-size window β size
-
Time Complexity:
O(n)
- You iterate through the array once using two pointers.
-
When to Use:
- Maximum or minimum of subarrays
- Longest/shortest substring problems
- Problems involving ranges or conditions that can be checked by sliding across elements
-
Solved Problems:
-
Status: In Progress / Completed
-
π Priority: High
-
What is Recursion?
Recursion is a programming technique where a function calls itself to solve smaller instances of a problem until it reaches a base case. -
Approach:
- Break down the problem into smaller sub-problems.
- Define the base case (stopping condition).
- Define the recursive case (how to reach the base case).
- Make the recursive call and combine the result if needed.
-
When to Use?
- When a problem can be divided into smaller, similar sub-problems (e.g., factorial, Fibonacci, tree/graph traversal).
-
Why to Use?
- Makes complex problems simpler to express and solve.
- Essential for solving problems involving divide-and-conquer, backtracking, and tree-like structures.
-
Remarks:
- Always define a clear base case to avoid infinite recursion.
- Each recursive call adds a new stack frame β may cause StackOverflow if depth is too large.
- Can often be converted to iteration or dynamic programming for optimization.
-
Time Complexity:
- Varies by problem (can be exponential if overlapping subproblems are not optimized).
-
Solved Problems:
-
Status: In Progress / Completed
-
π Priority: High
-
What is Prefix Sum?
Recursion -
Approach:
- Break down the problem into smaller sub-problems.
- Define the base case (stopping condition).
- Define the recursive case (how to reach the base case).
- Make the recursive call and combine the result if needed.
-
When to Use?
- When a problem can be divided into smaller, similar sub-problems (e.g., factorial, Fibonacci, tree/graph traversal).
-
Why to Use?
- Makes complex problems simpler to express and solve.
- Essential for solving problems involving divide-and-conquer, backtracking, and tree-like structures.
-
Remarks:
- Always define a clear base case to avoid infinite recursion.
- Each recursive call adds a new stack frame β may cause StackOverflow if depth is too large.
- Can often be converted to iteration or dynamic programming for optimization.
-
Time Complexity:
- Varies by problem (can be exponential if overlapping subproblems are not optimized).
-
Solved Problems:
- Two Pointers
- Sliding Window
- Recursion & Backtracking
- Dynamic Programming
- Graphs & Trees
- Sorting & Searching Algorithms
- Mark a checkbox (β ) when a topic is completed.
- Update priority levels based on difficulty.
- Add new problem links as you solve more.
- Keep refining your understanding over time.
This document will help in revisiting concepts quickly and keeping track of progress systematically. π