CodeBlog.xyz

30 Fundamental Algorithms

March 3, 2025 | by codeblog.xyz

1. Sorting Algorithms (Essential for Interviews)

  1. Bubble Sort – Basic sorting algorithm, inefficient for large data.
  2. Selection Sort – Selects the smallest element and places it in order.
  3. Insertion Sort – Inserts elements into their correct position.
  4. Merge Sort – Efficient, divide-and-conquer sorting with O(n log n) complexity.
  5. Quick Sort – Fast sorting using partitioning, average O(n log n) complexity.
  6. Heap Sort – Sorting using a heap, used in priority queues.
  7. Counting Sort – Good for small range of numbers.
  8. Radix Sort – Used for sorting numbers with multiple digits efficiently.

2. Searching Algorithms

  1. Linear Search – Basic search, used in unsorted lists.
  2. Binary Search – Fast O(log n) search, works only in sorted arrays.
  3. Jump Search – Faster than binary search for sorted data.
  4. Exponential Search – Good for unbounded lists.
  5. Interpolation Search – Faster than binary search for uniformly distributed data.

3. Graph Algorithms

  1. Breadth-First Search (BFS) – Traverses level-by-level, used in shortest path problems.
  2. Depth-First Search (DFS) – Explores depth before breadth, used in tree/graph traversal.
  3. Dijkstra’s Algorithm – Finds the shortest path from a source node (greedy approach).
  4. Bellman-Ford Algorithm – Shortest path with negative weights.
  5. Floyd-Warshall Algorithm – All-pairs shortest paths.
  6. Kruskal’s Algorithm – Finds Minimum Spanning Tree (MST) using greedy approach.
  7. Prim’s Algorithm – Another approach for MST.
  8. Topological Sorting – Used in DAGs (Directed Acyclic Graphs) like dependency resolution.

4. Tree Algorithms

  1. Binary Tree Traversal (Inorder, Preorder, Postorder, Level Order BFS)
  2. Lowest Common Ancestor (LCA) – Finds the common ancestor of two nodes.
  3. Morris Traversal – In-order traversal without recursion or stack.
  4. Trie (Prefix Tree) – Used for searching strings efficiently (autocomplete systems).

5. Dynamic Programming & Recursion

  1. Fibonacci Series (DP & Recursion) – Classic problem for understanding memoization.
  2. Knapsack Problem (0/1 Knapsack & Fractional Knapsack) – Optimization problem.
  3. Longest Common Subsequence (LCS) – Used in diff utilities, DNA sequencing.
  4. Coin Change Problem – Find the minimum number of coins needed for a sum.
  5. Subset Sum Problem – Determines if a subset sums to a given value.

RELATED POSTS

View all

view all