The content of this repository is also hosted at: https://peter-lucia.github.io/algorithms/
- Graph
- Tree / Binary Search Tree
- HashTables
- Sorting And Searching
- Dynamic Programming
- Number Theory
- Math: Combinatorics / Probability)
- String / Array / Stack
- Linked List
- BIT Manipulation
- Python
- NP-Complete
- References
- Breadth First Search (BFS)
- Depth First Search (DFS)
- Shortest Path from source to all vertices Dijkstra
- Shortest Path from every vertex to every other vertex Floyd Warshall
- To detect cycle in a Graph DFS
- To detect cycle in a Graph Union Find
- Minimum Spanning tree Prim
- Minimum Spanning tree Kruskal
- Topological Sort
- Boggle (Find all possible words in a board of characters)
- Bridges in a Graph
- There are 3 basic ways to represent a graph in memory (objects and pointers, matrix, and adjacency list). Each representation and its pros + cons.
- 1293. Shortest Path in a Grid with Obstacles Elimination
- Basic tree construction, traversal and manipulation algorithms
- Binary Trees
- N-ary trees
- Trie-trees
- BFS Binary Tree
- AVL Tree
- Tree traversal algorithms: BFS Adj list and DFS Adj list
- The difference between inorder, postorder and preorder.
- Find Minimum Depth of a Binary Tree
- Maximum Path Sum in a Binary Tree
- Check if a given array can represent Preorder Traversal of Binary Search Tree
- Check whether a binary tree is a full binary tree or not
- Bottom View Binary Tree
- Print Nodes in Top View of Binary Tree
- Remove nodes on root to leaf paths of length < K
- Lowest Common Ancestor in a Binary Search Tree
- Check if a binary tree is subtree of another binary tree
- Reverse alternate levels of a perfect binary tree
- Find and Remove Leaves of Binary Tree
- Find and Remove Leaves of Binary Tree (DFS)
- Find mode in binary search tree (BFS)
- 116. Populating Next Right Pointers in Each Node in a Perfect Binary Tree
- 1026. Maximum Difference Between Node and Ancestor
- How to implement one using only arrays.
- 432. Reconstruct original digits from english
- 811. Subdomain Visit count
- 49. Group Anagrams
- 249. Group Shifted Strings
- 347. Top k frequent elements
- Binary Search
- Search an element in a sorted and rotated array
- Bubble Sort
- Insertion Sort
- Merge Sort can be highly useful in situations where quicksort is impractical
- Heap Sort (Binary Heap)
- Quick Sort
- Interpolation Search
- Find Kth Smallest/Largest Element In Unsorted Array
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
- Counting Sort Pseudocode Worst Time: O(n+k), Worst Space: O(k), k = max(nums)
- Stock Buy Sell to Maximize Profit
- 843. Guess the word
- Longest Common Subsequence
- Longest Increasing Subsequence
- Edit Distance
- Minimum Partition
- Ways to Cover a Distance
- Longest Path In Matrix
- Subset Sum Problem
- Optimal Strategy for a Game
- 0-1 Knapsack Problem
- Boolean Parenthesization Problem
- Get nth number in the Fibonacci Sequence
- Longest string chain
- 792. Number of matching subsequences
- 70. Climb Stairs
- 416. Partition Equal Subset Sum
- Modular Exponentiation
- Modular multiplicative inverse
- Primality Test | Set 2 (Fermat Method)
- Euler’s Totient Function
- Sieve of Eratosthenes
- Convex Hull
- Basic and Extended Euclidean algorithms
- Segmented Sieve
- Chinese remainder theorem
- Lucas Theorem
- Check if a number is prime or not
- Number of primes less than n
- 1015. Smallest Integer Divisible by K
- Probability problems, and other Discrete Math 101 situations.
- The essentials of combinatorics and probability.
- N-choose-K problems
- Reverse an array without affecting special characters
- All Possible Palindromic Partitions
- Count triplets with sum smaller than a given value
- Convert array into Zig-Zag fashion
- Generate all possible sorted arrays from alternate elements of two given sorted arrays
- Pythagorean Triplet in an array
- Length of the largest subarray with contiguous elements
- Find the smallest positive integer value that cannot be represented as sum of any subset of a given array
- Smallest subarray with sum greater than a given value
- 735. Asteroid Collision
- 20. Valid Parentheses
- 189. Rotate Array
- 68. Text Justification
- 2007. Find Original Array from doubled array
- 822. Find And Replace String
- 384. Shuffle an Array
- 53. Maximum subarray
- 28. Implmeent strStr() / Rabin-Karp find needle in haystack
- 2128. Remove All Ones With Row and Column Flips
- Insertion of a node in Linked List (On the basis of some constraints)
- Delete a given node in Linked List (under given constraints)
- Compare two strings represented as linked lists
- Add Two Numbers Represented By Linked Lists
- Merge A Linked List Into Another Linked List At Alternate Positions
- Reverse A List In Groups Of Given Size
- Union And Intersection Of 2 Linked Lists
- Detect And Remove Loop In A Linked List
- Merge Sort For Linked Lists
- Select A Random Node from A Singly Linked List
- Reverse a linked list
- 2095. Delete the Middle Node of a Linked List
- 21. Merge Two Sorted Lists
- Maximum Subarray XOR
- Magic Number
- Sum of bit differences among all pairs
- Swap All Odds And Even Bits
- Find the element that appears once
- Binary representation of a given number
- Count total set bits in all numbers from 1 to n
- Rotate bits of a number
- Count number of bits to be flipped to convert A to B
- Find Next Sparse Number
- 476. Number Complement
NP-Complete means a problem is both NP-Hard and a solution is verifiable in polynomial time.
Structure of NP-Complete proofs
- Demonstrate that we can validate a solution for B in polynomial time (B is in NP)
- Show the reduction from a known problem,
$A \leq_p B$ (A is no harder than B and B is at least as hard as A). (B is NP_Hard)- Instance of A converted to instance of B in polynomial time
- Solution of B converted to solution of A in polynomial time
- If you have a solution for B you have a solution for A
- If no solution for B no solution for A (or contra-positive – if you have a solution for A then you have a solution for B)
- Big-O Cheatsheet
- Determine Primes via Square Root
- Primes Stackoverflow
- Baillie-PSW Primality Test
- Wiki - Fermat Pseudoprime
- Primality Test
- Youtube: Khan Academy Combination formula
- Dijkstra's Algorithm
- Graph data structure
- Adjacency List vs. Adjacency Matrix
- Common algorithms
- Python heapq
- Heapsort
Python Version: 3.8.7