This repository contains JavaScript based examples of many popular algorithms and data structures.
Each algorithm and data structure has its own separate README with related explanations and links for further reading (including ones to YouTube videos).
Read this in other languages: 简体中文, 繁體中文, 한국어, Polski, Français
We’re writing a book that will clearly explain, in detail, the main algorithms. If you’d like to be notified when the “JavaScript Algorithms” book launches, click here.
A data structure is a particular way of organizing and storing data in a computer so that it can be accessed and modified efficiently. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.
B - Beginner, A - Advanced
BLinked ListBDoubly Linked ListBQueueBStackBHash TableBHeapBPriority QueueATrieATreeABinary Search TreeAAVL TreeARed-Black TreeASegment Tree - with min/max/sum range queries examplesAFenwick Tree (Binary Indexed Tree)
AGraph (both directed and undirected)ADisjoint SetABloom Filter
An algorithm is an unambiguous specification of how to solve a class of problems. It is a set of rules that precisely define a sequence of operations.
B - Beginner, A - Advanced
- Math
BBit Manipulation - set/get/update/clear bits, multiplication/division by two, make negative etc.BFactorialBFibonacci NumberBPrimality Test (trial division method)BEuclidean Algorithm - calculate the Greatest Common Divisor (GCD)BLeast Common Multiple (LCM)BSieve of Eratosthenes - finding all prime numbers up to any given limitBIs Power of Two - check if the number is power of two (naive and bitwise algorithms)BPascal's TriangleAInteger PartitionALiu Hui π Algorithm - approximate π calculations based on N-gons
- Sets
BCartesian Product - product of multiple setsBFisher–Yates Shuffle - random permutation of a finite sequenceAPower Set - all subsets of a setAPermutations (with and without repetitions)ACombinations (with and without repetitions)ALongest Common Subsequence (LCS)ALongest Increasing SubsequenceAShortest Common Supersequence (SCS)AKnapsack Problem - "0/1" and "Unbound" onesAMaximum Subarray - "Brute Force" and "Dynamic Programming" (Kadane's) versionsACombination Sum - find all combinations that form specific sum
- Strings
BHamming Distance - number of positions at which the symbols are differentALevenshtein Distance - minimum edit distance between two sequencesAKnuth–Morris–Pratt Algorithm (KMP Algorithm) - substring search (pattern matching)AZ Algorithm - substring search (pattern matching)ARabin Karp Algorithm - substring searchA