Skip to content

Commonly encountered Data Strucutues and Algorithms implemented in python

Notifications You must be signed in to change notification settings

Achint08/algo-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 

Repository files navigation

Basic Data Structures And Algorithms

Central idea behind this project

The idea is to focus on implementing basic important data structures and algorithms on very basic problems. These data structures are not exhaustive, but these are the algorithms that we occasionally come across. This would help in two ways:

  • Learn the exact insights and mechanisms about algorithms by heart.
  • Developing Template for the common data structures and algorithms for later reuse.

Note:

  1. When using python, use pypy in contests, if available, when solving questions because it's a faster alternative to cpython. Just read about it.

  2. All FAANG companies mostly focus on these algorithms only. This are high leverage algorithms from the interview perspective.

List of data structures and algorithms

  • (Two Pointers) Floyd's Algorithm (The Tortoise and the Hare)
  • (Two Pointers) Old and new state
  • (Two Pointers) Start and end of sliding window
  • Linked List
  • Doubly Linked List
  • Circular Linked List
  • Hash Table
  • Stack
  • Monotonic stack
  • Queue
  • Recursion example
  • Divide and Conquer
  • Insertion Sort
  • Merge Sort/(Two Pointers) Pointer-1 and pointer-2 from two sequences
  • Bubble Sort
  • Selection Sort
  • Quick Sort
  • Counting Sort
  • (Order Statistics) Quick Select
  • Binary Search/ (Two Pointers) Left and right boundary
  • Binary Search(using bisect)
  • Heap/Priority Queue
  • Trie
  • Rolling hash
  • Disjoint Set
  • Binary Tree
  • Binary Search Tree
  • Adjacency List
  • Adjacency Matrix
  • Edge List
  • Breadth First Search
  • Depth First Search
  • Tree Traversal (Inorder, Preorder, Postorder, Level Order)
  • Dijkstra's Algorithm (Priority queue)
  • Bellman Ford Algoritm
  • Floyd Warshall Algorithm
  • Prim's Algorithm
  • Krushkal's Algorithm
  • Eular Path/Circuit
  • Kosaraju’s algorithm(Strongly connected components)
  • Detecting Cycle in graph(Back/Forward/tree edge)
  • Topological Sort
  • Backtracking
  • Greedy Algorithm Knapsack
  • Dynamic Programming Top down DP
  • Bottom Up DP
  • DP with bit masking
  • Euclid's Algorithm (Greatest common divisor)
  • Exponentiation algorithm (Exponentiation by squaring D&C)
  • Sieve of Eratosthenes

For more advanced topics and deep dive into competitive programming, refer this book: https://cses.fi/book/book.pdf as suggested by top coders.

I came across some new things about python while learning. You might also come across these at some time. Read these blogs for help understanding them, beforehand, so that you don't get stuck like me:

  1. https://book.pythontips.com/en/latest/for_-_else.html
  2. https://stackoverflow.com/questions/1907565/c-and-python-different-behaviour-of-the-modulo-operation
  3. https://www.programiz.com/python-programming/global-local-nonlocal-variables#:~:text=Nonlocal%20variables%20are%20used%20in,keywords%20to%20create%20nonlocal%20variables.
  4. https://stackoverflow.com/a/9674327/6725646

Input size and time complexity reference

Input size Target time complexity
n ≤ 12 O(n!)
n ≤ 25 O(2^n)
n ≤ 100 O(n^4)
n ≤ 500 O(n^3)
n ≤ 10 000 O(n^2)
n ≤ 1 000 000 O(n log n)
n ≤ 100 000 000 O(n)
n > 100 000 000 O(1) or O(log n) or O(n ^ (1/2))

Suggestions

Are there any other algorithm that I might be missing? Please open a pull request and contribute! Let's learn together.

References

Thank You. :)