Dsa Cheat Sheet
Dsa Cheat Sheet
Array
• Methods:
2. Linked List
• Definition: A linear data structure where each element is a separate object (Node) linked
using pointers.
• Methods:
3. Stack
• Definition: A linear data structure following the LIFO (Last In First Out) principle.
• Methods:
4. Queue
• Definition: A linear data structure following the FIFO (First In First Out) principle.
• Methods:
• Definition: A data structure that maps keys to values for efficient lookup.
• Methods:
6. Binary Tree
• Definition: A tree data structure in which each node has at most two children (left and right).
• Methods:
• Definition: A special form of binary tree where left children are smaller, and right children
are larger than the parent node.
• Methods:
8. Heap
• Definition: A complete binary tree where each node follows the heap property (min-heap or
max-heap).
• Methods:
9. Graph
• Methods:
o Shortest Path: Find the shortest path between two vertices (Dijkstra’s Algorithm,
Bellman-Ford, etc.).
• Bubble Sort: Repeatedly swap adjacent elements if they are in the wrong order.
• Selection Sort: Repeatedly select the smallest element and move it to the correct position.
• Insertion Sort: Build the sorted array one element at a time by inserting elements into their
correct position.
• Merge Sort: Divide the array into halves, sort each half, and merge them back.
• Quick Sort: Select a pivot, partition the array, and recursively sort the subarrays.
• Heap Sort: Convert the array into a heap, then repeatedly extract the minimum/maximum
element.
• Linear Search: Sequentially check each element until the target is found.
• Binary Search: Efficiently search a sorted array by dividing the search interval in half.
• Depth First Search (DFS): Explore each branch of a graph as deeply as possible before
backtracking.
• Breadth First Search (BFS): Explore the neighbor nodes at the present depth level before
moving on to nodes at the next depth level.
12. Recursion
• Definition: A function that calls itself to solve a smaller instance of the problem.
• Common Patterns:
• Methods:
o Tabulation: Use a table to store intermediate results and solve the problem bottom-
up.
• Definition: A problem-solving technique where you pick the locally optimal choice at each
step with the hope of finding a global optimum.
15. Backtracking
• Definition: A recursive technique used to solve problems by trying out different possibilities
and undoing (backtracking) when a solution fails.