WhatsAlgo icon indicating copy to clipboard operation
WhatsAlgo copied to clipboard

:mortar_board: Implementation of many essential Data Structures & Algorithms.

WhatsAlgo

Prepping for your coding interview? Want to learn data structures & algorithms but don't know where to start?

Well you have come to the right place. Data structures & algorithms are of key importance for anyone dealing with programming. Be a software engineer, a computer science student, or a fun enthusiast, having a firm grasp on various topics is crucial. This repository aims to provide implementations of many different data structures & algorithms from basic to some advanced topics. Learn and have a firm grasp on data structures & algorithms to ace your coding interviews and land that dream job!

Sorting Algorithms

  • Selection Sort - O(n²)
  • Bubble Sort - O(n²)
  • Insertion Sort - O(n²)
  • Merge Sort - O(n log n)
  • Quick Sort - O(n²)
  • Counting Sort - O(n + k)

Search Algorithms

  • Linear Search - O(n)
  • Binary Search - O(log n)
  • Find Peak 1D - O(log n)
  • Find Peak 2D - O(n)

Complete Search

  • Generating Subsets - O(n • 2ⁿ)
  • Generating Permutations (Backtracking) - O(n * n!)
  • Generating Permutations (Lexicographic) - O(n * n!)

Data Structures

  • Least Recently Used Cache
  • Least Frequently Used Cache
  • Running Median
  • Trie
  • Fenwick Tree
  • Union-Find
  • Prefix Sum - O(n)
  • Prefix Sum 2D - O(n • m)
  • Knuth–Morris–Pratt Algorithm - O(m + n)

Tree Algorithms

  • Kruskal's Minimum Spanning Tree - O(E • log E)
  • Prim's Minimum Spanning Tree - O(E • log E)

Dynamic Programming

  • Maximum Subarray - O(n)
  • Coin Change - O(n • c)
  • Edit Distance - O(m • n)
  • Longest Common Subsequence - O(m • n)
  • Longest Increasing Subsequence - O(n • log n)
  • nCr mod m - O(n • r)

Greedy Algorithms

  • Coin Change - O(c)

Bit Manipulation

  • Lowest Set Bit - O(1)
  • Highest Set Bit - O(1)
  • Count Set Bits - O(1)
  • Reverse Bits - O(1)

Mathematics

  • Primality Test - O(√n)
  • Prime Factorization - O(√n)
  • Fast Exponentiation - O(log n)
  • Fast Modular Exponentiation - O(log n)
  • Greatest Common Divisor - O(log(a + b))
  • Least Common Multiple - O(log(a + b))
  • nCr mod p - O(n)
  • Extended Euclidean Algorithm - O(log(a + b))
  • Modular Multiplicative Inverse - O(log m)

Miscellaneous

  • Boyer–Moore Majority Vote - O(n • k)