explaingit

trekhleb/javascript-algorithms

195,932JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A JavaScript reference collection of classic algorithms and data structures, linked lists, graphs, dynamic programming, string matching, and more, each with its own explanation and links to videos and further reading.

Mindmap

mindmap
  root((javascript-algorithms))
    Data Structures
      Linked lists
      Trees and heaps
      Graphs
      Hash tables
    Algorithms
      Sorting
      Searching
      Dynamic programming
      String matching
    Math
      Fibonacci and primes
      Bit manipulation
      Fourier transform
    Use cases
      Interview prep
      Learning reference
      Starter code
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Study a JavaScript implementation of a specific data structure like a binary search tree or heap before a coding interview.

USE CASE 2

Copy a working reference implementation of an algorithm like Levenshtein distance or Dijkstra's into a project as a starting point.

USE CASE 3

Practice coding interview topics by reading beginner and advanced examples alongside their plain-English explanations.

USE CASE 4

Learn how classic algorithms like Fourier transform or Euclidean GCD are implemented in a modern language.

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository contains JavaScript implementations of many popular algorithms and data structures, each paired with its own explanation and links to further reading, including YouTube videos. The README describes the project as "JavaScript based examples of many popular algorithms and data structures," and the topics include algorithm, computer-science, interview, and interview-preparation, which signal that one common use is preparing for technical interviews. The way it works is that the code is organized into two top-level sections, Data Structures and Algorithms, and each item lives in its own subdirectory with its own README. Items are tagged either Beginner or Advanced so a reader can pick what is appropriate. The data structures listed include linked lists, queues, stacks, hash tables, heaps, priority queues, tries, several kinds of trees (binary search, AVL, red-black, segment, Fenwick), graphs, a disjoint set, a bloom filter, and an LRU cache. The algorithms are grouped by topic, Math (bit manipulation, factorial, Fibonacci, primes, Euclidean algorithm, sieve of Eratosthenes, discrete Fourier transform), Sets (Cartesian product, shuffle, power set, permutations, combinations, knapsack), Strings (palindrome, Levenshtein distance, KMP, Z, Rabin, Karp), Searches, and more. Someone would use this when learning data structures and algorithms in JavaScript, preparing for coding interviews, or wanting a worked reference implementation. The README is available in many languages, including Chinese, Korean, Japanese, Polish, French, Spanish, Portuguese, and Russian among others.

Copy-paste prompts

Prompt 1
Walk me through the javascript-algorithms implementation of Dijkstra's shortest path. Explain each step in plain English.
Prompt 2
I'm preparing for a coding interview. Explain the Knapsack problem solution in the trekhleb/javascript-algorithms repo and describe the dynamic programming approach.
Prompt 3
Implement a Trie data structure in JavaScript following the style and conventions used in the javascript-algorithms repo.
Prompt 4
Compare the KMP and Rabin-Karp string search algorithms using the implementations in javascript-algorithms. When would I choose each one?
Prompt 5
I'm studying AVL trees. Explain the rotation logic in the javascript-algorithms AVL tree implementation in simple terms.
Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub trekhleb on gitmyhub

Verify against the repo before relying on details.