Sorting |
Bubble Sort |
(O(n^2)) |
(O(1)) |
A simple comparison-based algorithm that repeatedly swaps adjacent elements if they are in the wrong order. |
|
Selection Sort |
(O(n^2)) |
(O(1)) |
Selects the minimum element from the unsorted portion and swaps it with the first unsorted element. |
|
Insertion Sort |
(O(n^2)) |
(O(1)) |
Builds the sorted array one element at a time by repeatedly inserting elements in their correct positions. |
|
Merge Sort |
(O(n \log n)) |
(O(n)) |
A divide-and-conquer algorithm that splits the array into halves, sorts them, and then merges the sorted halves. |
|
Quick Sort |
(O(n \log n)) average, (O(n^2)) worst |
(O(\log n)) average, (O(n)) worst |
A divide-and-conquer algorithm that selects a pivot and partitions the array around it. |
|
Heap Sort |
(O(n \log n)) |
(O(1)) |
Uses a binary heap data structure to sort the array. |
|
Counting Sort |
(O(n + k)) |
(O(k)) |
A non-comparison-based sorting algorithm that counts the occurrences of each element. |
|
Radix Sort |
(O(n \cdot k)) |
(O(n + k)) |
Sorts numbers by processing individual digits. |
Searching |
Linear Search |
(O(n)) |
(O(1)) |
Searches an array sequentially until the desired element is found. |
|
Binary Search |
(O(\log n)) |
(O(1)) |
Searches a sorted array by repeatedly dividing the search interval in half. |
|
Depth-First Search (DFS) |
(O(V + E)) |
(O(V)) |
Explores as far as possible along each branch before backtracking, used in graph traversal. |
|
Breadth-First Search (BFS) |
(O(V + E)) |
(O(V)) |
Explores all neighbors at the present depth level before moving on to nodes at the next depth level, used in graph traversal. |
Dynamic Programming |
Fibonacci Sequence (Memoized) |
(O(n)) |
(O(n)) |
Computes the Fibonacci sequence using memoization to avoid redundant calculations. |
|
Longest Common Subsequence |
(O(m \cdot n)) |
(O(m \cdot n)) |
Finds the longest subsequence common to two sequences. |
|
Knapsack Problem |
(O(n \cdot W)) |
(O(n \cdot W)) |
Solves the 0/1 Knapsack problem using dynamic programming. |
Greedy Algorithms |
Dijkstra’s Algorithm |
(O((V + E) \log V)) |
(O(V)) |
Finds the shortest path from a source node to all other nodes in a graph with non-negative weights. |
|
Kruskal’s Algorithm |
(O(E \log E)) |
(O(E)) |
Finds the minimum spanning tree of a graph using a greedy approach. |
|
Prim’s Algorithm |
(O((V + E) \log V)) |
(O(V)) |
Another greedy algorithm to find the minimum spanning tree of a graph. |
Divide and Conquer |
Merge Sort |
(O(n \log n)) |
(O(n)) |
Divides the array into halves, sorts each half, and merges them. |
|
Quick Sort |
(O(n \log n)) average, (O(n^2)) worst |
(O(\log n)) average, (O(n)) worst |
Partitions the array around a pivot and recursively sorts the partitions. |
Graph Algorithms |
Depth-First Search (DFS) |
(O(V + E)) |
(O(V)) |
Explores all possible paths in a graph by diving as deep as possible first. |
|
Breadth-First Search (BFS) |
(O(V + E)) |
(O(V)) |
Explores all nodes at the present level before moving on to the next level. |
|
Bellman-Ford Algorithm |
(O(V \cdot E)) |
(O(V)) |
Computes shortest paths from a single source to all other vertices, even with negative weights. |
|
Floyd-Warshall Algorithm |
(O(V^3)) |
(O(V^2)) |
Computes shortest paths between all pairs of vertices. |
String Algorithms |
Knuth-Morris-Pratt (KMP) |
(O(n + m)) |
(O(m)) |
Searches for occurrences of a “pattern” within a “text” by using a prefix table to skip unnecessary comparisons. |
|
Rabin-Karp |
(O(n + m)) average, (O(n \cdot m)) worst |
(O(1)) |
Uses hashing to find any one of a set of pattern strings in a text. |
|
Boyer-Moore |
(O(n / m)) best, (O(n \cdot m)) worst |
(O(m)) |
Searches for a substring within a string using a heuristic-based approach that skips sections of the text. |
Backtracking |
N-Queens Problem |
(O(N!)) |
(O(N^2)) |
Places N queens on an N×N chessboard so that no two queens threaten each other, by trying all possible placements. |
Mathematical Algorithms |
Sieve of Eratosthenes |
(O(n \log \log n)) |
(O(n)) |
Finds all prime numbers up to a specified integer by iteratively marking the multiples of primes. |
|
Euclidean Algorithm |
(O(\log \min(a, b))) |
(O(1)) |
Computes the greatest common divisor (GCD) of two numbers. |
Data Structures Operations |
Hash Table (Insert/Search/Delete) |
(O(1)) average, (O(n)) worst |
(O(n)) |
A data structure that provides average constant time complexity for insert, search, and delete operations, but can degrade to linear time in the worst case. |
|
Binary Search Tree (BST) |
(O(\log n)) average, (O(n)) worst |
(O(n)) |
Provides logarithmic time complexity for insert, search, and delete operations, but can degrade to linear time if unbalanced. |
|
AVL Tree |
(O(\log n)) |
(O(n)) |
A self-balancing binary search tree that guarantees logarithmic time complexity for insert, search, and delete operations. |
|
Trie (Prefix Tree) |
(O(m)) for insert/search |
(O(m \cdot n)) |
A tree-like data structure that stores a dynamic set of strings, where ‘m’ is the length of the string and ‘n’ is the number of strings. |