CodexSec Algorithms
PROTOCOL 02 // RECURSION · ALGORITHMS COMPENDIUM

Master All 73 Algorithmic Paradigms

Interactive step-by-step visualizers, compilable polyglot implementations (C++, Java, Python), asymptotic runtime profiling, and algorithmic verification sandboxes.

Sorting Algorithms

Systematic element reordering via pairwise comparisons, partitioning, and distribution. · 12 Algorithms

O(N log N) - O(N^2)
O(N^2) Space: O(log N)

Quick Sort

Divide-and-conquer sorting algorithm that selects a pivot element and partitions the array into sub-arrays of smaller and greater elements.

O(N log N) Space: O(N)

Merge Sort

Guaranteed O(N log N) stable sorting algorithm dividing arrays into halves, recursively sorting, and merging them.

O(N log N) Space: O(1)

Heap Sort

In-place comparison sort that transforms the array into a binary max-heap, repeatedly extracting the maximum.

O(N^2) Space: O(1)

Bubble Sort

Classic educational algorithm repeatedly stepping through the list, swapping adjacent elements if in wrong order.

O(N^2) Space: O(1)

Insertion Sort

Builds sorted array one element at a time by inserting each element into its proper position among previously sorted items.

O(N^2) Space: O(1)

Selection Sort

Sorts array by repeatedly finding the minimum element from the unsorted part and placing it at the beginning.

O(N * d) Space: O(N + k)

Radix Sort (LSD)

Non-comparative integer sorting algorithm that sorts data with keys by grouping digits sharing the same significant position.

O(N + K) Space: O(N + K)

Counting Sort

Integer sorting algorithm operating by counting distinct key occurrences and using prefix sums for exact output placement.

O(N^2) Space: O(N + K)

Bucket Sort

Distribution sort partitioning elements into a number of buckets, then sorting each bucket individually using another algorithm.

O(N log N) Space: O(N)

TimSort

High-performance hybrid stable sorting algorithm combining Insertion Sort and Merge Sort, used in Python and Java standard libraries.

O(N^2) Space: O(1)

Shell Sort

Generalization of Insertion Sort that allows exchange of items that are far apart using a diminishing gap sequence.

O(N^2) Space: O(1)

Cocktail Shaker Sort

Bidirectional variation of Bubble Sort that traverses in both directions alternately through the list.

Searching & Selection

Target element location, boundary narrowing, and order-statistic selection. · 7 Algorithms

O(1) - O(log N)
O(N) Space: O(1)

Linear Search

Sequentially checks each element of the list until a match is found or the whole list has been searched.

O(log N) Space: O(1)

Binary Search

Efficiently locates target value within a sorted array by repeatedly halving the search interval.

O(sqrt(N)) Space: O(1)

Jump Search

Searches sorted arrays by jumping ahead by fixed steps of sqrt(N), then performing backward linear search.

O(N) Space: O(1)

Interpolation Search

Improves binary search for uniformly distributed sorted arrays by estimating position like looking up words in a dictionary.

O(log i) Space: O(1)

Exponential Search

Finds range where search key resides by testing powers of 2, then runs binary search within the bounded range.

O(log3 N) Space: O(1)

Ternary Search

Divide-and-conquer search dividing sorted range into three equal parts using two midpoints (mid1 and mid2).

O(N^2) Space: O(1)

Quickselect (k-th Smallest)

Selection algorithm to find the k-th smallest element in an unordered list based on QuickSort partitioning.

Graph Algorithms

Shortest paths, minimum spanning trees, topological orderings, and network flow. · 12 Algorithms

O(V + E) - O(V^2)
O(V + E) Space: O(V)

Breadth-First Search (BFS)

Traverses graph level-by-level using a FIFO queue, computing unweighted shortest paths.

O(V + E) Space: O(V)

Depth-First Search (DFS)

Explores as deep as possible along each branch before backtracking using a call stack or LIFO stack.

O((V + E) log V) Space: O(V)

Dijkstra's Algorithm

Greedy algorithm computing single-source shortest paths in graphs with non-negative edge weights using a priority queue.

O(V * E) Space: O(V)

Bellman-Ford Algorithm

Computes single-source shortest paths in graphs with negative weights and detects negative weight cycles.

O(b^d) Space: O(V)

A* Search Algorithm

Heuristic-guided graph traversal that finds the optimal path by evaluating f(n) = g(n) + h(n).

O(V^3) Space: O(V^2)

Floyd-Warshall (APSP)

Dynamic programming algorithm computing all-pairs shortest paths across positive or negative edge weights.

O(E log V) Space: O(V)

Prim's Minimum Spanning Tree

Greedy algorithm that builds a minimum spanning tree starting from a single node and growing the cut.

O(E log E) Space: O(V + E)

Kruskal's Minimum Spanning Tree

Greedy algorithm sorting all edges by weight and adding them to the MST using Disjoint Set Union (DSU) to avoid cycles.

O(V + E) Space: O(V)

Topological Sort (Kahn's)

Linear ordering of vertices in a Directed Acyclic Graph (DAG) such that for every directed edge u -> v, u comes before v.

O(V + E) Space: O(V)

Tarjan's Strongly Connected Components

Single-pass DFS algorithm that finds all maximal strongly connected components using discovery times and low-link values.

O(V + E) Space: O(V + E)

Kosaraju's SCC Algorithm

Two-pass DFS algorithm that finds strongly connected components by transposing the graph and traversing in finish-time order.

O(E * max_flow) Space: O(V^2)

Ford-Fulkerson Maximum Flow

Computes maximum flow from source to sink in a flow network by repeatedly finding augmenting paths in the residual graph.

Dynamic Programming

Optimal substructure decomposition with overlapping subproblem memoization. · 12 Algorithms

Memoized Optimality
O(N * W) Space: O(N * W) or O(W)

0/1 Knapsack Problem

Selects subset of non-divisible items with given weights and values to maximize total value without exceeding capacity W.

O(M * N) Space: O(M * N)

Longest Common Subsequence (LCS)

Finds longest subsequence present in both strings in the same relative order (not necessarily contiguous).

O(N log N) Space: O(N)

Longest Increasing Subsequence (LIS)

Finds length of longest subsequence of a given sequence such that all elements are sorted in increasing order.

O(N^3) Space: O(N^2)

Matrix Chain Multiplication (MCM)

Determines the most efficient way to parenthesize a sequence of matrices to minimize scalar multiplication operations.

O(N * Amount) Space: O(Amount)

Coin Change Problem

Calculates the minimum number of coins needed to make a target amount from given coin denominations.

O(M * N) Space: O(M * N)

Edit Distance (Levenshtein)

Quantifies dissimilarity between two strings by counting minimum insert, delete, or substitute operations.

O(N^2) Space: O(N)

Rod Cutting Problem

Determines the maximum revenue obtainable by cutting up a rod of length n and selling the pieces according to price table.

O(N * Sum) Space: O(N * Sum)

Subset Sum Problem (DP)

Decides whether any subset of integers sums to an exact target sum using dynamic programming.

O(N) Space: O(1)

Maximum Subarray (Kadane's)

Computes the maximum sum contiguous subarray in linear time by keeping a running maximum and resetting on negative dips.

O(N^2) Space: O(N)

Word Break Problem

Determines if a string can be segmented into a space-separated sequence of one or more dictionary words.

O(N * Sum/2) Space: O(Sum/2)

Partition Equal Subset Sum

Determines whether an array can be partitioned into two subsets such that the sum of elements in both subsets is equal.

O(N^2 * 2^N) Space: O(N * 2^N)

Traveling Salesperson (Held-Karp)

Exact solution to the TSP using bitmask dynamic programming to compute the minimum Hamiltonian cycle in O(N^2 * 2^N).

Backtracking & Recursion

Systematic combinatorial exploration with constraint-based pruning. · 8 Algorithms

State-Space Search
O(N!) Space: O(N)

N-Queens Problem

Places N chess queens on an N x N chessboard so that no two queens threaten each other.

O(9^81) Space: O(81)

Sudoku 9x9 Solver

Solves standard 9x9 Sudoku puzzles using recursive backtracking with constraint propagation.

O(2^(N^2)) Space: O(N^2)

Rat in a Maze

Finds a path from start to destination in a 2D grid matrix with obstacles using backtracking.

O(8^(N^2)) Space: O(N^2)

Knight's Tour Problem

Sequence of moves of a knight on a chessboard such that the knight visits every square exactly once.

O(2^N) Space: O(N)

Subset Sum (Backtracking)

Enumerates all subset combinations summing up to target sum by pruning branches exceeding target.

O(N * N!) Space: O(N)

Permutations & Combinations

Generates all N! permutations and N choose K combinations of an array using in-place swap backtracking.

O(N!) Space: O(N)

Hamiltonian Path & Cycle

Finds a path in an undirected or directed graph that visits each vertex exactly once.

O(M^V) Space: O(V)

Graph M-Coloring Problem

Assigns colors to vertices of a graph such that no two adjacent vertices share the same color using at most M colors.

Greedy Algorithms

Iterative myopic selection yielding global optimality without backtracking. · 6 Algorithms

Locally Optimal Choice
O(N log N) Space: O(1)

Fractional Knapsack

Maximizes value by sorting items by value-to-weight density (val/wt) and greedily taking fractions of items.

O(N log N) Space: O(1)

Activity Selection (Interval Scheduling)

Selects maximum number of mutually compatible activities by sorting by earliest finish time.

O(N log N) Space: O(N)

Huffman Coding Tree

Lossless data compression algorithm assigning variable-length prefix codes based on character frequencies using a min-heap.

O(N^2) Space: O(N)

Job Sequencing with Deadlines

Schedules jobs with deadlines to maximize total profit, executing each job within its available deadline slot.

O(N) Space: O(1)

Gas Station Greedy Tour

Finds the unique starting gas station from which a car can complete a circular circuit, or -1 if impossible.

O(N log N) Space: O(1)

Minimum Platforms Problem

Computes minimum number of railway platforms needed to schedule all arriving and departing trains without collision.

Divide and Conquer

Recursive problem breakdown, independent conquest, and optimal recombination. · 4 Algorithms

Recursive Subproblems
O(N log N) Space: O(N)

Closest Pair of Points

Finds two points with smallest Euclidean distance in 2D space in O(N log N) using geometric divide and conquer.

O(N^2.807) Space: O(N^2)

Strassen's Matrix Multiplication

Sub-cubic matrix multiplication multiplying two N x N matrices using 7 recursive multiplications instead of 8.

O(N^1.585) Space: O(N)

Karatsuba Multiplication

Fast multiplication algorithm for large integers multiplying two N-digit numbers in O(N^1.585) using 3 multiplications.

O(N log N) Space: O(log N)

Maximum Subarray (Divide & Conquer)

Classic divide-and-conquer approach to finding the maximum contiguous subarray in O(N log N) time.

String & Pattern Matching

Sublinear substring queries, prefix-suffix matching, and rolling hash comparisons. · 6 Algorithms

Prefix & Finite Automata
O(N + M) Space: O(M)

Knuth-Morris-Pratt (KMP)

Searches for occurrences of a pattern within text in linear time by preprocessing the pattern to avoid backtracking.

O(N * M) Space: O(1)

Rabin-Karp Rolling Hash

String-searching algorithm using rolling hash to compare pattern and text window hashes in O(1) per shift.

O(N + M) Space: O(N + M)

Z-Algorithm

Linear time string matching algorithm computing the Z-array, where Z[i] is the length of the longest common prefix of s and s[i..N-1].

O(N * M) Space: O(Alphabet)

Boyer-Moore Pattern Matcher

Benchmark string-search algorithm that scans characters from right to left using bad-character and good-suffix heuristics for sublinear shifts.

O(N + Sum(M) + Matches) Space: O(Sum(M))

Aho-Corasick Automaton

Trie-based string searching algorithm that locates all occurrences of multiple patterns concurrently in linear time.

O(N) Space: O(N)

Manacher's Algorithm

Finds the longest palindromic substring in any string in strictly linear O(N) time and space.

Geometric & Mathematical

Geometric hulls, prime sieves, modular exponentiation, and discrete transforms. · 6 Algorithms

Asymptotic Calculus
O(N log N) Space: O(N)

Convex Hull (Graham Scan)

Computes the convex hull of a finite set of points in 2D plane in O(N log N) using polar angle sorting and stack cross products.

O(N^2) Space: O(H)

Convex Hull (Jarvis March)

Output-sensitive convex hull algorithm (Gift Wrapping) that computes the hull in O(N * H) where H is number of hull vertices.

O(N log log N) Space: O(N)

Sieve of Eratosthenes

Ancient algorithm for finding all prime numbers up to any given limit by iteratively marking multiples as composite.

O(log(min(A, B))) Space: O(1)

Euclidean & Extended GCD

Computes greatest common divisor of two integers using remainder division, and Bézout coefficients with Extended Euclidean.

O(log exp) Space: O(1)

Fast Modular Exponentiation

Computes (base^exp) % mod in O(log exp) time using binary exponentiation and repeated squaring.

O(N log N) Space: O(N)

Fast Fourier Transform (FFT)

Computes the Discrete Fourier Transform in O(N log N) using the Cooley-Tukey divide-and-conquer algorithm with roots of unity.