Uploaded by abdo djahra

algo dsa roadmap

advertisement
1. Arrays & Matrices:
Patterns:
Binary Search (for sorted arrays)
Two Pointers (for finding specific patterns or sorting)
Sliding Window (for finding sub-arrays with specific properties)
Island Pattern (for finding connected components in a matrix)
Cyclic Sort (for sorting in-place)
Merge Intervals: to merge overlapping intervals efficiently
prefix sum
Algorithms:
Sorting Algorithms (Bubble Sort, Insertion Sort, Selection Sort - good for understanding basic concepts)
Quick Sort & Heap Sort: for (in-place-sorting)
Searching Algorithms (Linear Search, Sentinel Linear Search - good for understanding basic concepts)
Matrix Traversal (row-major, column-major)
Kadane's Algorithm:to find the contiguous subarray with maximum sum
2. Strings:
Patterns:
Modified Binary Search (for searching specific characters or patterns)
Two Pointers (for finding specific patterns or manipulating strings)
Bitwise XOR (for some string manipulations)
Algorithms:
String Searching Algorithms (Rabin-Karp Algorithm, KMP Algorithm - more advanced)
String Processing Algorithms (Longest Common Subsequence, Longest Common Prefix - more advanced)
Infix to Postfix/Prefix Conversion (for expression evaluation)
3. Linked Lists (including Circular & Doubly & skip list):
Patterns:
Two Pointers (for traversing or manipulating the list)
Fast & Slow Pointers : Often used with Linked Lists (e.g., cycle detection, finding middle element)
In-place Reversal (for reversing the order of elements in place)
sorting linked list
modifying linked list Algorithms:
Traversal Algorithms (iterative or recursive)
Merge two sorted linked lists
4. Stacks:
Patterns:
Two Pointers (for pushing and popping elements)
Monotonic Stack: Primarily used with Stacks to maintain a stack in sorted order (increasing or decreasing)
prefix, infix, postfix problems
Algorithms:
Implementing basic operations (push, pop, peek)
Balanced Parentheses Check (using a stack)
5. Queues & Deques & priority queues & circular:
Patterns:
Two Pointers (for enqueue and dequeue operations)
Algorithms:
Implementing basic operations (enqueue, dequeue, peek)
Breadth-First Search (BFS) implementation using a queue
6. Trees(binary,tenary,n-ary,b, b+):
Patterns:
Breadth-First Search (BFS)
Depth-First Search (DFS) (pre-order, in-order, post-order)
k-based problems
Algorithms:
Tree Traversal Algorithms (BFS, DFS)
Level Order Traversal (BFS variation, printing nodes level by level)
Finding the Height of a Tree (using DFS)
7. Binary Search Trees (BST, 2-3 , 2-3-4):
Patterns:
Binary Search (for efficient searching)
Algorithms:
Insertion (maintains BST property)
Deletion (maintains BST property)
Searching
Finding Minimum/Maximum Value
8. Self-Balancing Trees (e.g., AVL, red-black, splay trees):
Algorithms:
Insertion (balances the tree)
Deletion (balances the tree)
Searching (similar to BST)
9. Heaps (Min-Heaps & Max-Heaps):
Patterns:
Two Heaps (for combining or manipulating elements from two heaps)
Top 'K' Elements (for finding minimum/maximum k elements)
Priority Queue
k-way merge
Algorithms:
Heapify (to convert an array into a heap)
Insert (maintain heap property)
Extract-Min/Max (remove and return min/max element)
Merge two sorted arrays using heaps
interval problems
10. Trie (Prefix Tree):
Patterns:
Trie Operations (insertion, searching for prefixes)
Algorithms:
Implementing Trie for efficient prefix searches
11. Graphs:
Patterns:
Breadth-First Search (BFS) (used for finding shortest paths in unweighted graphs)
Depth-First Search (DFS) (used for various graph problems like cycle detection, topological sorting)
Topological Sort (for finding a linear ordering of a directed acyclic graph)
Union Find (Disjoint Set) (for finding connected components)
Floyd's Cycle Detection Algorithm (for finding cycles in a linked list or array)
union find: a graph for fast insertion of edges, fast checking if two nodes are connected
strongly connected components: max group of nodes strongly connected,else if its only one node > acyclic graph
minumum spaning tree
Algorithms:
Graph Traversal Algorithms (BFS, DFS)
Topological Sort (for directed acyclic graphs)
Dijkstra's Algorithm (finding shortest path in a weighted graph)
Floyd-Warshall Algorithm (finding all-pairs shortest paths)
Prim's Algorithm & Kruskal's Algorithm (finding minimum spanning tree)
Flood Fill Algorithm (for
Kruskal's Algorithm: to find the minimum spanning tree
Bellman-Ford Algorithm: (including graph with negative edge weights) for finding shortest paths
12. Recursion:
Concepts:
Base Case: The condition that stops the recursive calls.
Recursive Case: The function call to itself with a smaller problem.
Examples:
Factorial calculation
Fibonacci sequence generation
Simple traversals of data structures (like in-order tree traversal)
13. Divide and Conquer:
Concepts:
Divide: Break the problem into smaller subproblems.
Conquer: Solve the subproblems recursively.
Combine: Combine the solutions of the subproblems to solve the original problem.
Examples:
Merge Sort
Quick Sort
Binary Search
14. Greedy Algorithms:
Concepts:
Make the locally optimal choice at each step with the hope of finding a global optimum. This may not always guarantee the best solution.
Examples:
Activity selection problem
Fractional knapsack problem
Finding the closest pair of points
15. Backtracking:
Concepts:
Systematically explore all possible solutions in a search space.
Use recursion to explore different branches of the search tree.
Prune unpromising branches to improve efficiency.
Examples:
Generating all permutations or combinations of a set
Solving maze problems
N-Queens problem (placing N queens on a chessboard without attacking each other)
16. Dynamic Programming (DP):
Concepts:
Overlapping Subproblems: Identify problems where solutions to subproblems are used multiple times.
Memoization: Store the solutions to subproblems to avoid redundant calculations.
Bottom-up approach: Solve subproblems in increasing order of complexity and store the solutions for later use.
it's tricks and optimisations (Knuth optimisation, convex hull optimisation, bitmasks, etc.)(advanced level)
Examples:
Longest Common Subsequence (LCS)
Fibonacci sequence generation (optimized version using memoization)
Knapsack problem (with dynamic programming approach)
OTHERS:
Disjoint set
union find
minimum spaning trees
segment trees
fenwick trees
Bit Manipulating
bit and : & 1 & & = 1
bit or : | 1 or 0 , 0 or 1 , 1 or 1 , = 1
xor : ^ 1 or 0 , 0 or 1 = 1
negation: ~ ~1 = 0 , ~0 = 1 , flip bits(reverse)
right shift: 3 >> 2 3/2/2 or 11 > 1 > 0 shift bits to right ntimes
left shift: 3 << 2 pow(3,2) or 11 > 110 > 1100 shift bits to left too much left shift OVERFLOW int size == 32 bit
Download