Algorithms with C#
Practice searching, collection choices, traversal, and small testable algorithms.
- Linear search
Search an unsorted collection with an explicit missing result.
Core ideas · 10 min - Binary search
Exploit a sorted input while preserving an index boundary.
Core ideas · 10 min - Frequency maps
Count repeated keys in one pass.
Core ideas · 10 min - Sets and uniqueness
Track whether a value has already appeared.
Core ideas · 10 min - Stacks and nesting
Use last-in-first-out order to match nested delimiters.
Working with data · 10 min - Queues and arrival order
Process work in first-in-first-out order.
Working with data · 10 min - Breadth-first traversal
Visit a graph by distance using a queue and a visited set.
Working with data · 10 min - Insertion sort
Maintain a sorted prefix as each value is inserted.
Working with data · 10 min - Two-pointer pair search
Move inward on a sorted array to find a target sum.
Putting it together · 10 min - Prefix sums
Precompute cumulative totals for repeated range queries.
Putting it together · 10 min - Run-length encoding
Accumulate adjacent equal values while preserving order.
Putting it together · 10 min - Algorithm contracts and checks
Verify edge cases using observable inputs and results.
Putting it together · 10 min - Fixed-size sliding windows
Update a neighboring window by removing one value and adding one value.
Deeper practice · 18 min - Compacting a sorted array with two pointers
Return the meaningful prefix length after removing adjacent duplicates in place.
Deeper practice · 18 min - Merging two sorted sequences
Advance the source whose next value is smaller and preserve every remainder.
Deeper practice · 18 min - Lower bound as a half-open binary search
Find the first position whose value is not less than a target.
Deeper practice · 18 min - Merging overlapping intervals
Choose an endpoint policy and fold intervals in start order.
Deeper practice · 18 min - Depth-first traversal with an explicit stack
Control exploration order and prevent cycles from revisiting nodes.
Deeper practice · 18 min - Topological order and cycle detection
Schedule directed dependencies only after all their prerequisites are satisfied.
Deeper practice · 18 min - Dijkstra with stale priority entries
Find nonnegative weighted shortest paths while ignoring superseded queue work.
Deeper practice · 18 min - Disjoint sets with path compression
Track connected components without repeatedly traversing the whole graph.
Applied techniques · 18 min - Memoization and distinct subproblems
Cache recursive results while measuring the work actually avoided.
Applied techniques · 18 min - Dynamic programming for minimum coin count
Build optimal smaller answers before solving the requested total.
Applied techniques · 18 min - Greedy interval scheduling by finish time
Maximize the number of compatible intervals under a precise adjacency rule.
Applied techniques · 18 min - Keeping the largest k values with a min-heap
Discard the smallest retained candidate as each new value arrives.
Applied techniques · 18 min - Next greater values with a monotonic stack
Resolve pending positions when a new value exceeds them.
Applied techniques · 18 min - Backtracking permutations and restoring state
Explore choices recursively while undoing each temporary decision.
Applied techniques · 18 min - Flood fill with boundary and revisit rules
Mark cells when queued to visit a connected region exactly once.
Applied techniques · 18 min