The Lycoris Team · · 5 min read Kadane's Algorithm Explained: Maximum Subarray in O(n)
Kadane's algorithm finds the maximum-sum contiguous subarray in one O(n) pass. How it works, why it's correct, code, edge cases, and common variations.
Topic
59 posts tagged “Algorithms”.
The Lycoris Team · · 5 min read Kadane's algorithm finds the maximum-sum contiguous subarray in one O(n) pass. How it works, why it's correct, code, edge cases, and common variations.
The Lycoris Team · · 4 min read A rope is a binary tree of string chunks that makes inserting, deleting, and slicing huge strings fast, which is why text editors use it over plain arrays.
The Lycoris Team · · 4 min read Memoization caches results top-down via recursion; tabulation builds a table bottom-up with loops. Same technique, opposite direction, different tradeoffs.
The Lycoris Team · · 4 min read Manacher's algorithm finds the longest palindromic substring in linear time by reusing symmetry from palindromes already found, avoiding redundant checks.
The Lycoris Team · · 4 min read The Z-algorithm builds a Z-array in linear time to find every occurrence of a pattern in a text — a fast alternative to naive string search.
Takina · · 4 min read Most regex engines backtrack through an NFA; a few compile to a DFA instead. The difference explains why some patterns hang forever and others never do.
The Lycoris Team · · 5 min read Binary search finds a value in a sorted array in O(log n) time by repeatedly halving the search space. How it works, why it needs sorted input, and common pitfalls.
The Lycoris Team · · 4 min read Breadth-first search explores a graph level by level using a queue; depth-first search follows one path as far as it goes using a stack. When to use each.
The Lycoris Team · · 4 min read A splay tree is a self-adjusting binary search tree that rotates recently accessed nodes to the root, giving fast amortized access to hot data.
The Lycoris Team · · 4 min read The halting problem proves no algorithm can determine, for every program and input, whether that program eventually stops. Why this limit is unavoidable.
The Lycoris Team · · 5 min read The traveling salesman problem asks for the shortest route visiting every city once — a classic NP-hard problem with major real-world stakes.
The Lycoris Team · · 4 min read Bloom filters and cuckoo filters both test set membership in constant space, but only one supports deletion. How they work and when to pick each.
The Lycoris Team · · 4 min read A Turing machine is a simple abstract model of computation — a tape, a head, and a set of rules — that defines what it means for something to be computable.
The Lycoris Team · · 4 min read Reservoir sampling picks a uniform random sample from a stream of unknown length using constant memory, without knowing the size in advance.
The Lycoris Team · · 4 min read Radix sort and counting sort can beat comparison sorts by never comparing elements at all — sorting integers in linear time under the right conditions.
The Lycoris Team · · 4 min read A suffix array sorts every suffix of a string into one compact index, enabling binary-search pattern matching without a full suffix tree.
The Lycoris Team · · 5 min read A monotonic stack keeps elements in strictly increasing or decreasing order, solving next-greater-element and range problems in linear time.
The Lycoris Team · · 4 min read Bellman-Ford handles negative edge weights and detects negative cycles; Dijkstra is faster but can't. When to use each shortest-path algorithm.
The Lycoris Team · · 4 min read Floyd-Warshall finds shortest paths between every pair of nodes in a weighted graph using dynamic programming — how the recurrence works and when to use it.
The Lycoris Team · · 4 min read The master theorem gives a direct formula for the time complexity of divide-and-conquer recurrences, skipping recursion-tree analysis by hand.
The Lycoris Team · · 4 min read The Rabin-Karp algorithm finds substrings by hashing, sliding a window in O(1) time per step instead of rehashing from scratch. Here's how it works.
The Lycoris Team · · 5 min read Prim's and Kruskal's both build a minimum spanning tree but grow it differently — one from a single node, the other by sorted edges. Here's how each works.
The Lycoris Team · · 5 min read Divide and conquer solves problems by splitting them into smaller subproblems, solving each recursively, and combining the results.
The Lycoris Team · · 4 min read Tail call optimization reuses a function's stack frame for its final call instead of pushing a new one, turning some recursion into constant stack space.
The Lycoris Team · · 4 min read HyperLogLog is a probabilistic algorithm that estimates the number of distinct items in a huge dataset using only a few kilobytes of memory.
The Lycoris Team · · 4 min read A Count-Min Sketch is a probabilistic data structure that estimates item frequencies in a stream using fixed memory, trading exactness for space.
The Lycoris Team · · 4 min read Regular expressions are matched by finite automata or backtracking engines. How regex engines parse patterns, and why some patterns run slowly.
The Lycoris Team · · 4 min read P is problems solvable quickly; NP is problems whose solutions are quickly checkable. Whether P equals NP is one of computing's open questions.
The Lycoris Team · · 4 min read The Knuth-Morris-Pratt algorithm finds a pattern inside a text in linear time by never re-examining characters it has already matched.
The Lycoris Team · · 5 min read A ring buffer is a fixed-size array that wraps its read and write pointers around, giving O(1) enqueue and dequeue without ever resizing.
The Lycoris Team · · 5 min read A Fenwick tree, or binary indexed tree, answers prefix-sum queries and point updates in O(log n) with far less memory than a segment tree.
The Lycoris Team · · 4 min read Bit manipulation uses operators like AND, OR, XOR, and shifts to work directly on binary representations — the basics behind flags, masks, and fast math.
The Lycoris Team · · 4 min read Amortized analysis measures the average cost of an operation over a sequence of calls, not its worst case. How dynamic array resizing gets O(1) amortized inserts.
The Lycoris Team · · 4 min read When two keys hash to the same slot, a hash table needs a collision strategy. Chaining and open addressing solve it differently — here's the tradeoff.
The Lycoris Team · · 5 min read A segment tree answers range queries — sum, min, max — over an array in logarithmic time, and supports updates without rebuilding the whole structure.
The Lycoris Team · · 4 min read Backtracking solves problems by building candidate solutions incrementally and abandoning any path that can't lead to a valid answer. How it works, with examples.
The Lycoris Team · · 5 min read Union-find tracks a collection of disjoint sets and answers 'are these two items connected?' in near-constant time. How it works and where it's used.
The Lycoris Team · · 4 min read Topological sort orders the nodes of a directed acyclic graph so every dependency comes before what depends on it. How it works and where it's used.
The Lycoris Team · · 5 min read Two pointers walk a sorted array or string from both ends (or in tandem) to solve problems in one linear pass instead of nested loops.
The Lycoris Team · · 4 min read The sliding window technique tracks a moving subrange of an array or string, turning many O(n²) brute-force problems into a single O(n) linear pass.
The Lycoris Team · · 6 min read Dijkstra's algorithm finds shortest paths by exploring uniformly outward; A* reaches the same answer faster by using a heuristic to aim at the goal.
The Lycoris Team · · 4 min read A skip list is a layered linked list with shortcut pointers giving O(log n) search, insert, and delete — a simpler alternative to balanced trees.
The Lycoris Team · · 5 min read Greedy algorithms commit to the locally best choice at each step; dynamic programming weighs every subproblem. When each one actually works.
The Lycoris Team · · 4 min read Red-black and AVL trees both keep binary search trees balanced, but trade off rebalancing cost against lookup speed differently. How each works.
The Lycoris Team · · 4 min read A finite state machine models a system as a fixed set of states and the transitions between them. How FSMs work and where they show up in real software.
The Lycoris Team · · 4 min read An LRU cache evicts the least recently used item first when it runs out of room, keeping the most useful data in memory. Here's how it's built.
The Lycoris Team · · 4 min read Recursion solves a problem by calling itself on smaller inputs; iteration solves it with a loop. Same results, different trade-offs in memory and clarity.
The Lycoris Team · · 5 min read Quicksort and mergesort are the two classic O(n log n) sorting algorithms — how they differ in memory use, stability, and worst-case behavior.
The Lycoris Team · · 4 min read Consistent hashing maps keys and nodes onto the same ring so adding or removing a server only reshuffles a small fraction of keys, not all of them.
The Lycoris Team · · 5 min read Graphs model networks of connected nodes; BFS and DFS are the two core ways to traverse them. How each works, and which to reach for.
The Lycoris Team · · 4 min read Stacks remove the most recent item first (LIFO); queues remove the oldest first (FIFO). How each works, their operations, and where they show up.
The Lycoris Team · · 4 min read A trie stores strings by sharing common prefixes across tree branches, making prefix lookups and autocomplete fast. How it compares to hash tables and BSTs.
The Lycoris Team · · 4 min read A heap is a tree-based structure that keeps the smallest or largest element at the root, enabling priority queues and heap sort in logarithmic time.
The Lycoris Team · · 5 min read A Bloom filter is a compact data structure that tests whether an item might be in a set, using far less memory than storing the set itself.
The Lycoris Team · · 4 min read A linked list stores elements as nodes linked by pointers rather than contiguous memory, trading fast random access for cheap insertion and removal.
The Lycoris Team · · 4 min read Dynamic programming solves complex problems by breaking them into overlapping subproblems and caching results, avoiding redundant recomputation.
The Lycoris Team · · 4 min read A binary search tree keeps every left descendant smaller and every right descendant larger than its parent. How lookups, inserts, and balance work.
The Lycoris Team · · 4 min read A hash table maps keys to array slots with a hash function for near O(1) lookups. How hashing, collisions, and resizing actually work under the hood.
The Lycoris Team · · 5 min read Big O notation describes how an algorithm's time or memory grows as input grows. The common classes, what they mean, and how to reason about them.