MST
A spanning tree T of an undirected graph G is a subgraph that is a tree which includes all of the vertices of G. A minimum spanning tree (MST) or minimum weight spanning tree is a spanning tree wh...
A spanning tree T of an undirected graph G is a subgraph that is a tree which includes all of the vertices of G. A minimum spanning tree (MST) or minimum weight spanning tree is a spanning tree wh...
Fundamentals Level traversal. The most common data structure used is Queue. Two rolling Lists or Sets (de-dupe) can also be used, but less common. Smallest Greater Multiple Made of Two Digits Im...
Dijkstra Fundamentals Dijkstra’s algorithm Dijkstra’s Shortest Path First algorithm (SPF algorithm) is an algorithm for finding the shortest paths between nodes in a graph. A single node as the ...
NavigableSet Prefix Suffix Parameter Comparison ceiling e >= floor e <= ...
Java Methods NavigableMap Prefix Suffix Parameter Comparison ceiling entry/key key >= floor entr...
Shuffle Fisher-Yates shuffle Shuffle an Array private int[] arr; private int[] oldArr; private Random rand = new Random(); public Solution(int[] nums) { arr = nums; oldArr = nums.clone...
Fundamentals Knapsack problem Backtracking takes \(O(2^n)\) time, so it’s less preferable. Dynamic Programming is better, and its form is like dp[i][j], which means the first i elements sums to j...
Fundamentals Disjoint-set data structure, also called union-find data structure, stores a collection of disjoint (non-overlapping) sets. Equivalently, it stores a partition of a set into disjoint ...
Sort Sort List public ListNode sortList(ListNode head) { ListNode dummy = new ListNode(); dummy.next = head; int n = 0; while (head != null) { head = head.next; n+...
Search Reduce to One-dimension Search a 2D Matrix Monotonic in Each Dimenstion Find Positive Integer Solution for a Given Equation public List<List<Integer>> findSolution(CustomFun...