Binary Search Tree
Insert, search, and delete while keeping values sorted. Average O(log n), worst O(n) if the tree becomes a chain.
Practical snippets you can use freely, each with a short description and a real-world example.
7 results
Insert, search, and delete while keeping values sorted. Average O(log n), worst O(n) if the tree becomes a chain.
Wrap a function and reuse its result for the same inputs. The next call with the same values skips the work.
Keep a fixed number of entries and evict the least recently used item when the cache is full.
An undirected graph: visit in breadth or depth, find the shortest hop path, and detect a cycle without counting the walk back to a parent.
Run a limited number of jobs at once, retry after a failure, and start the highest priority first.
Subscribe a listener to an event and call it on emit by priority. once runs a single time.
Find a pattern in text in linear time, using a table of the longest prefix that is also a suffix.
Describe the problem or idea, and I will see if it belongs in the library.