Worked examples
Examples
A central index of worked examples — problems with full step-by-step solutions, paired with the concept page where the technique lives. Filter by topic, difficulty, or tag.
showing 3 of 3 examples
Detect a cycle in a graph using Union-Find
standardWalk a small undirected graph edge by edge, using Union-Find to flag the first edge that creates a cycle. The same machinery powers Kruskal’s MST.
Build a max-heap from an unsorted array
standardTake an unsorted array of 7 numbers and transform it into a max-heap in O(n), running sift-down at each internal node from the deepest backward to the root.
Estimate an integral with the trapezoidal rule
introApproximate ∫₀¹ e^(−x²) dx using the trapezoidal rule with 4 sub-intervals, then bound the error and compare to the true value.