Skip to main content

82 docs tagged with "algorithms"

View all tags

A* & Heuristic Search

Dijkstra's algorithm finds the shortest path to every vertex by always expanding the closest

Amortized Analysis

Some structures cannot be made cheap on every single call, but can be made cheap *on average over any

Arrays & Dynamic Arrays

An array is a block of contiguous memory holding equally-sized elements. That one property gives it

Backtracking

Backtracking searches a space of candidate solutions by building them one choice at a time, and

Balanced Trees

A binary search tree is $O(\log n)$ only while it stays short, and nothing in the plain

Big-O Notation

Big-O describes an upper bound on growth. Saying an algorithm is $O(n^2)$ claims that beyond some

Binary Search

Binary search compares the target against the middle element of a sorted array and discards half

Bubble Sort

Bubble sort repeatedly walks the array comparing adjacent pairs and swapping them when they are out

Choosing a Sort

In almost every situation the correct answer is call your language's built-in sort. Those

Combinatorics & Counting

"How many ways" questions tempt a direct answer: generate every arrangement, every selection, every

Common Complexities

In practice you meet perhaps eight growth classes. Recognising which one a piece of code falls into —

Complexity Cheat Sheet

This page is a reference, not a tutorial — each numbered page in this section explains the reasoning

Cycle Detection

A cycle is a path that leaves a vertex and, by following edges, returns to it. That definition reads

Divide & Conquer

Divide and conquer breaks a problem into independent subproblems of the same kind, solves those

Dynamic Programming

Dynamic programming applies when a problem has overlapping subproblems — the same sub-computation

Fast & Slow Pointers

A singly-linked list, or anything shaped like one — a permutation's i -> p[i] mapping, a

Graphs

A graph is a set of vertices and a set of edges connecting them. That is nearly no structure

Greedy Algorithms

A greedy algorithm makes the choice that looks best right now and never reconsiders it. When that

Hash Tables

A hash table turns a key into an array index by running it through a hash function, then reads or

Heapsort

Heapsort is selection sort with a better way of selecting. Selection sort scans

Insertion Sort

Insertion sort builds the sorted result one element at a time, taking the next element and sliding it

Intervals & Sweep Line

A calendar full of meetings, a set of (start, end) ranges to merge, a question like "how many

Iterators

Iterators are the glue between containers and algorithms. They provide a uniform interface for traversing and accessing elements in different container types, enabling generic algorithms.

KMP & the Z-Algorithm

The naive substring scan tries the pattern at every text position and, on a mismatch, throws away

Linear Search

Linear search examines each element in turn until it finds what it is looking for or runs out. It is

Linked Lists

A linked list stores each element in its own node, together with a pointer to the next one. Nothing

LRU & LFU Caches

A cache with unlimited capacity is just a hash table. The interesting problem

Math & Number Theory

Every algorithm folder so far has assumed arithmetic just works: a hash function combines numbers,

Mergesort

Mergesort splits the array in half, sorts each half recursively, and merges the two sorted halves

Minimum Spanning Trees

Given a connected, undirected, weighted graph, a spanning tree picks exactly V - 1 edges that keep

Monotonic Stack & Queue

"For each element, find the nearest element to the right that is bigger" looks like it needs a nested

Network Flow

A flow network is a directed graph where every edge has a capacity, one vertex is a source pumping

P, NP & Intractability

Most complexity analysis on this site asks how fast a known algorithm runs. This page asks a

Parallel Patterns

Almost every GPU kernel, however specialized, is built from a small set of recurring data-access shapes. Recognizing which pattern a problem is — before writing any code — tells you how parallelizable it is, what its likely performance limiter will be, and often points directly at a library implementation that already exists and is already tuned. This page names those shapes once, and every later applied-kernel page in this knowledge base assumes you already know these names — "this is a reduction" or "this needs a scan" is meant to carry full meaning by the time you reach folder 13.

Primes & Sieves

Testing whether a single number n is prime is a small, self-contained problem: try dividing it by

Quickselect

Finding the k-th smallest element does not require sorting the whole array. Sorting throws away no

Quicksort

Quicksort picks an element as the pivot, rearranges the array so that everything smaller sits to

Ranges Library

Ranges (C++20) is a modern library that provides composable, lazy-evaluated operations on sequences. It replaces traditional iterator pairs with range objects and introduces views for efficient data transformation pipelines.

Selection Sort

Selection sort divides the array into a sorted prefix and an unsorted remainder. Each round it scans

Shortest Paths

"Shortest" means fewest edges on an unweighted graph and lowest total weight on a weighted one, and

Sorting Cheat Sheet

This page is a reference, not a tutorial — each algorithm's own page derives the bound it gets here.

Space Complexity

Time complexity answers "how does the work grow?"; space complexity asks the same question about

Stacks & Queues

Stacks and queues are not new storage — they are restrictions on storage. Both hold a sequence,

STL Algorithms

STL algorithms are generic functions that work with any container through iterators. They provide tested, optimized implementations of common operations. Never write your own sort or search - use the STL!

String Fundamentals

Every algorithm in this folder assumes a cost model for three operations that look free and are

Strings & Text

A string is an array — but three things about it break the assumptions the rest of this section

Top-K & Streaming

"Find the k largest" looks like a sorting problem, and sorting solves it — but sorting also computes

Topological Sort

A topological sort orders the vertices of a directed acyclic graph so every edge points forward —

Traversal: BFS & DFS

Breadth-first and depth-first search both visit every vertex reachable from a start point, in

Tries (Prefix Trees)

A hash set answers "is this exact string in the set?" and nothing else. It cannot answer "what strings