DEV Community

Nozibul Islam
Nozibul Islam

Posted on

Must Know Algorithms.

1. Searching Algorithms

  • Linear Search: Iteratively searches each element in the array.
    Time Complexity: O(n)

  • Binary Search: Compares the target with the middle element of a sorted array and narrows down the search.
    Time Complexity: O(log₂n)

2. Sorting Algorithms

  • Bubble Sort: Swaps adjacent elements in repeated passes.
    Time Complexity: O(n²)

  • Insertion Sort: Inserts elements into their correct position in a sorted part of the array.
    Time Complexity: O(n²)

  • Selection Sort: Selects the smallest value from unsorted elements in each pass.
    Time Complexity: O(n²)

  • Heap Sort: Uses heaps to sort elements.
    Time Complexity: O(n log n)

  • Merge Sort: A divide-and-conquer algorithm that divides the array, sorts each half, and merges.
    Time Complexity: O(n log n)

  • Quick Sort: Uses a pivot to partition and recursively sort arrays.
    Time Complexity: O(n log n) (average), O(n²) (worst case).

3. Basic Math Algorithms

  • Euclid's Algorithm for GCD: Finds the greatest common divisor by division.
  • Sieve of Eratosthenes: Identifies prime numbers by eliminating multiples.
  • Bit Manipulations: Uses bitwise operators for low-level operations.

4. Graph Algorithms

  • Breadth-First Search (BFS): Traverses level by level using a queue.
  • Depth-First Search (DFS): Explores depth-wise using a stack. Time Complexity: O(V + E)
  • D*ijkstra's Algorithm:* Finds the shortest path in a weighted graph.

5. Tree Algorithms

  • Inorder Traversal: Left subtree → Root → Right subtree.
  • Preorder Traversal: Root → Left subtree → Right subtree.
  • Postorder Traversal: Left subtree → Right subtree → Root. Time Complexity: O(n)
  • Kruskal's Algorithm: Finds the minimum spanning tree by adding edges in order of weight.

6. Dynamic Programming

  • Floyd-Warshall Algorithm: Finds shortest paths between all pairs in a weighted graph. Uses Memoization (top-down) and Tabulation (bottom-up).

7. Backtracking Algorithms

  • Solves problems like N-Queens, Sum of Subsets, Graph Coloring, and Hamiltonian Cycles.

8. Huffman Compression Algorithm

  • Compresses data by building a Huffman tree and assigning codes to characters based on frequency.

Top comments (1)

Collapse
 
hbthepencil profile image
HB_the_Pencil

These are useful! It would be nice to have an example function, but I know that would be complex. Good article!