Reference · 162 terms

Glossary

Every short form used across the series. Inside a lesson, hover or tap any dotted term to see the same entry in place.

Basics

booleanBoolean
A value that is either true or false. Every condition in an if or a loop is turned into a boolean.Lesson 3 →
data typeData type
The kind of value: number, string, boolean, undefined, null, object. typeof tells you which one you have.Lesson 2 →
dry runDry run
Run the code by hand on paper. Write down every variable after every line. It is the best way to understand loops and find bugs.Lesson 1 →
DSAData Structures and Algorithms
Data structures are ways to store data (arrays, maps, trees). Algorithms are step-by-step ways to solve a problem with them. Coding interviews test both.Lesson 1 →
moduloModulo (%)
a % b is the remainder after dividing a by b. n % 2 === 0 means n is even. n % 10 is the last digit of n.Lesson 2 →
Node.jsNode.js
A program that runs JavaScript outside the browser. You type node file.js in a terminal and it runs the file.Lesson 1 →
operatorOperator
A symbol that does something to values: + - * / % for maths, === and < to compare, && and || to combine true/false.Lesson 2 →
REPLRead–Eval–Print Loop
The prompt where you type one line and see the result at once. Type node with no file, or use the browser console.Lesson 1 →
statementStatement
One instruction, usually one line ending in a semicolon. A program is a list of statements run from top to bottom.Lesson 1 →
variableVariable
A named box that holds a value. let creates one you can change; const creates one you cannot reassign.Lesson 2 →

Loops

accumulatorAccumulator
A variable that collects a result across iterations. Start it at 0 (for a sum) or 1 (for a product), then add or multiply inside the loop.Lesson 4 →
infinite loopInfinite loop
A loop whose condition never becomes false, so it never stops. Often the update step is missing or goes the wrong way.Lesson 5 →
iterationIteration
One pass through the body of a loop. A loop that runs 5 times has 5 iterations.Lesson 4 →
loop variableLoop variable
The counter a loop changes on every iteration, usually called i. It decides when the loop stops.Lesson 4 →
nested loopNested loop
A loop inside another loop. The inner loop runs fully for every single turn of the outer loop. Think of rows and columns.Lesson 6 →
off-by-oneOff-by-one error
A loop that runs one time too many or too few. Often it is < instead of <=, or starting at 0 instead of 1. It is the most common loop bug.Lesson 4 →

Functions

argumentArgument
The actual value passed in when you call a function: in add(2, 3), 2 and 3 are the arguments.Lesson 7 →
functionFunction
A named, reusable block of code. It takes inputs (parameters) and gives back a result with return.Lesson 7 →
parameterParameter
The name a function uses for an input, written in its definition: function add(a, b) has parameters a and b.Lesson 7 →
return valueReturn value
What a function gives back to whoever called it. Without a return statement a function gives back undefined.Lesson 7 →

Collections

arrayArray
An ordered list of values in one variable. Positions are numbered from 0, so the last index is length − 1.Lesson 8 →
frequency mapFrequency map
A Map from each item to how many times it appears. Many interview questions use it: duplicates, anagrams, most frequent.Lesson 10 →
immutableImmutable
Cannot be changed after it is made. JavaScript strings are immutable: every change makes a new string.Lesson 9 →
indexIndex
The position number of an item in an array or string, starting at 0.Lesson 8 →
key–valueKey–value pair
One entry in an object or Map: a key (like a word) and the value stored under it (like its count).Lesson 10 →
linear searchLinear search
Checking items one by one from the start until you find what you want. Simple, and the baseline every faster search is compared with.Lesson 8 →
palindromePalindrome
Something that reads the same forwards and backwards: "level", "madam", the number 121.Lesson 9 →
SetSet
A collection that keeps each value only once. It answers “is this in here?” at once with has().Lesson 10 →
stringString
Text. In JavaScript a string is like a read-only array of characters: s[0], s.length. But s[0] = 'x' does nothing.Lesson 9 →

Problem solving

Big-OBig-O notation
A way to say how the work grows as the input grows. O(1) stays flat. O(n) grows in step with n. O(n²) grows with n × n.Lesson 12 →
brute forceBrute force
The simplest correct solution, usually trying every possibility. It is slow, but it is a safe start that you then improve.Lesson 11 →
constraintsConstraints
The limits printed under a problem: how big the input can be and which values are allowed. They tell you which edge cases exist and how fast your solution must be.Lesson 11 →
edge caseEdge case
An unusual but valid input at the limit of the problem: an empty array, one element, all values equal, negative numbers. Most wrong answers fail on one.Lesson 11 →
logarithmLogarithm (log n)
How many times you can halve n before you reach 1. log₂ of 1,000,000 is about 20. That is why halving algorithms are so fast.Lesson 12 →
space complexitySpace complexity
How much extra memory an algorithm needs as the input grows (the input itself is not counted). A Set of every value is O(n). A few variables is O(1).Lesson 12 →
time complexityTime complexity
How the number of steps grows as the input gets bigger. We write it in Big-O.Lesson 12 →
worst caseWorst case
The input that makes the algorithm do the most work. Big-O usually describes the worst case, because that is what you can promise.Lesson 12 →

Maths

BigIntBigInt
A JavaScript type for whole numbers of any size, written with an n at the end: 10n. You need it when results go past 2^53, where normal numbers lose exact values.Lesson 13 →
divisorDivisor
A number that divides another exactly, with remainder 0. The divisors of 12 are 1, 2, 3, 4, 6 and 12.Lesson 13 →
GCDGreatest Common Divisor
The largest number that divides both a and b. gcd(12, 18) = 6. Euclid's algorithm finds it quickly.Lesson 13 →
LCMLeast Common Multiple
The smallest number that both a and b divide. lcm(4, 6) = 12. Work it out as a / gcd(a, b) × b.Lesson 13 →
modular arithmeticModular arithmetic
Work only with remainders after dividing by a number m. It keeps huge answers small: you can take (a + b) % m and (a × b) % m step by step.Lesson 13 →
prime numberPrime number
A whole number greater than 1 whose only divisors are 1 and itself: 2, 3, 5, 7, 11 … 1 is not prime.Lesson 13 →
Sieve of EratosthenesSieve of Eratosthenes
A way to find every prime up to n. Cross out the multiples of each prime in turn. What is never crossed out is prime. About O(n log log n).Lesson 13 →

Recursion and hashing

base caseBase case
The input that a recursive function answers directly, without calling itself again. Without one, the recursion never stops.Lesson 14 →
call stackCall stack
The list of function calls that have started but not finished. Each call goes on top. When it returns, it is removed.Lesson 14 →
collisionCollision
Two different keys that land in the same bucket. The fix is to keep a short list of entries in each bucket (chaining).Lesson 15 →
counting arrayCounting array
An array where the index is the value and the box holds how many times it appears. It works when values are small whole numbers in a known range, like 26 letters.Lesson 15 →
hash functionHash function
A function that turns a key into a number. That number picks the bucket where the key is stored. The same key always gives the same number.Lesson 15 →
hash tableHash table
An array of buckets plus a hash function that turns each key into a bucket number. JavaScript's Map and Set are hash tables, so a lookup is O(1) on average.Lesson 15 →
recursionRecursion
Solve a problem by having a function call itself on a smaller version of the same problem, until it reaches a base case.Lesson 14 →
stack overflowStack overflow
The error when the call stack runs out of room. In JavaScript: “RangeError: Maximum call stack size exceeded”. Often there is no base case, or the recursion is too deep.Lesson 14 →

Sorting

comparatorComparator
The function you give to sort: (a, b) => negative if a goes first, positive if b goes first, 0 if equal. For numbers, use (a, b) => a - b.Lesson 18 →
counting sortCounting sort
Sort by counting each value in a counting array, then write the values back in order. O(n + range). Good when values come from a small range.Lesson 16 →
divide and conquerDivide and conquer
Split a problem into smaller copies, solve each one by recursion, then combine the answers. Merge sort and quick sort both do this.Lesson 17 →
in placeIn place
Rearranging the input array itself with only O(1) extra memory, not building a new array.Lesson 16 →
inversionInversion
A pair of positions i < j where arr[i] > arr[j]. A sorted array has none. Bubble sort makes exactly one swap per inversion.Lesson 16 →
mergeMerge (two sorted arrays)
Join two sorted arrays into one sorted array. Keep taking the smaller front item. O(n + m).Lesson 17 →
partitionPartition
Rearrange an array in one pass, so items smaller than a pivot come before it and the rest come after it.Lesson 18 →
pivotPivot
The value that quick sort splits around. Smaller items go to its left, the rest go to its right, and the pivot ends in its final place.Lesson 18 →
quickselectQuickselect
Find the k-th smallest item by partitioning and then continuing into only one side. O(n) on average.Lesson 18 →
stable sortStable sort
A sort that keeps items with equal keys in their first order. JavaScript's sort is stable. Selection sort and quick sort are not.Lesson 16 →

Array patterns

Kadane's algorithmKadane's algorithm
Finds the largest subarray sum in one pass. The best sum ending at each index is max(x, previous best + x).Lesson 24 →
matrixMatrix
A grid of values stored as an array of rows. m[r][c] is row r, column c.Lesson 25 →
prefix sumPrefix sum
pre[i] = the sum of the first i items. Then any range sum is pre[r + 1] − pre[l], in O(1).Lesson 20 →
sliding windowSliding window
A block of neighbouring items that moves along an array. Its state (sum, count, map) updates as one item enters and one leaves.Lesson 22 →
subarraySubarray
A continuous slice of an array, like nums[2..5]. It is not a subsequence, which may skip items.Lesson 20 →
subsequenceSubsequence
Items taken from an array or string in their first order, and you may skip some. "ace" is a subsequence of "abcde".Lesson 21 →
transposeTranspose
Swapping the rows and columns of a matrix: t[c][r] = m[r][c].Lesson 25 →
two pointersTwo pointers
Two indices that move through an array, from both ends inwards or in the same direction. One pass replaces a nested loop.Lesson 21 →
anagramAnagram
A word made by rearranging the letters of another: "listen" and "silent". Group them with a key such as the sorted letters.Lesson 27 →
binary searchBinary search
Find a target in sorted data. Check the middle and throw away half of the range each step. O(log n).Lesson 28 →
lower boundLower bound
The first index whose value is ≥ the target. It is also where the target would go to keep the array sorted.Lesson 28 →
majority elementMajority element
A value that appears more than n/2 times. Boyer–Moore voting finds it in O(1) space.Lesson 27 →
monotonicMonotonic
Only moves one way: a yes/no check that is false…false and then true…true. Binary search needs this.Lesson 29 →
upper boundUpper bound
The first index whose value is > the target. upper bound − lower bound = how many times the target appears.Lesson 28 →

Strings, recursion and backtracking

backtrackingBacktracking
Build an answer one choice at a time. Undo the choice afterwards. Stop a partial answer as soon as it cannot work.Lesson 34 →
combinationCombination
A choice of k items where order does not matter. There are C(n, k) of them.Lesson 33 →
memoisationMemoisation
Save each answer in a Map the first time you work it out, so you never compute the same call twice. It turns naive Fibonacci from exponential into linear.Lesson 32 →
permutationPermutation
One ordering of all the items. n items have n! permutations.Lesson 33 →
pruningPruning
Cut off a branch of the search early, because it can never give a valid answer. The worst case stays the same, but the real work can shrink a lot.Lesson 34 →
recursion treeRecursion tree
A drawing of every call a recursive function makes, one node per call. Count the nodes for time. Measure the height for stack space.Lesson 32 →
subsetSubset
A choice of items from a set, any amount, including none. A set of n items has 2ⁿ subsets.Lesson 33 →

Linked lists

cycleCycle
A loop in a linked list: some node points back to an earlier node, so walking never reaches null.Lesson 36 →
doubly linked listDoubly linked list
A linked list whose nodes also keep a prev reference. You can walk both ways and remove a node you already hold in O(1).Lesson 35 →
dummy nodeDummy node
A throwaway node put in front of the real head, so every real node, even the head, has a node before it. You need no special case for changing the head. The answer is dummy.next.Lesson 35 →
Floyd's algorithmFloyd's cycle detection
Slow and fast pointers in a cycle: fast gains one step per round on slow, so they must meet. A second phase from the head finds where the cycle starts. It needs O(1) memory.Lesson 36 →
linked listLinked list
A chain of nodes. Each node holds a value and a reference to the next node. You reach items by following the references, so finding a position takes O(n).Lesson 35 →
nodeNode
One link in a linked list (or one item in a tree). It holds a value and the references to its neighbours.Lesson 35 →
slow and fast pointersSlow and fast pointers
Two pointers that move at different speeds, usually 1 and 2 steps. They find the middle of a list in one pass and detect cycles.Lesson 36 →

Stacks and queues

amortisedAmortised cost
The average cost per operation over a whole series. One call may be costly, but many cheap calls pay for it, so the average stays low.Lesson 39 →
dequeDeque
A double-ended queue: you can add and remove items at both the front and the back.Lesson 39 →
FIFOFirst in, first out
The queue rule: the item that waited longest leaves first.Lesson 39 →
LIFOLast in, first out
The stack rule: the most recently added item is the first to be removed.Lesson 38 →
monotonic stackMonotonic stack
A stack kept in sorted order (always going up or always going down) by popping items that no longer matter. It solves next greater element and similar questions in O(n).Lesson 40 →
queueQueue
A line where items are added at the back and removed from the front: first in, first out.Lesson 39 →
stackStack
A pile where you add and remove only at the top: last in, first out. An array with push and pop is a stack. So is the call stack of function calls.Lesson 38 →

Trees

binary search treeBinary search tree
A binary tree where, at every node, all values in the left subtree are smaller and all values in the right subtree are larger. Search, insert and delete take O(height).Lesson 44 →
binary treeBinary tree
A structure of nodes. Each node has at most a left and a right child, and there are no loops. The top node is the root.Lesson 41 →
height-balancedHeight-balanced
A tree where, at every node, the heights of the left and right subtrees differ by at most 1.Lesson 43 →
inorderInorder
A depth-first order: left subtree, then the node, then the right subtree. On a binary search tree it gives sorted order.Lesson 41 →
inorder successorInorder successor
The next larger value in a BST: the smallest node in the right subtree. It replaces a deleted node that has two children.Lesson 44 →
level orderLevel order
Visit a tree one row at a time from the top, using a queue.Lesson 42 →
lowest common ancestorLowest common ancestor
The deepest node that has both given nodes below it (a node counts as below itself).Lesson 45 →
postorderPostorder
A depth-first order that visits both subtrees before the node itself.Lesson 41 →
preorderPreorder
A depth-first order that visits a node before its left and right subtrees.Lesson 41 →
serialiseSerialise
Turn a tree into a string you can store or send, and build the tree again from that string. Null markers make the string clear.Lesson 45 →
subtreeSubtree
Any node together with everything below it. A subtree is itself a tree, which is why recursion fits trees so well.Lesson 41 →

Heaps, greedy and intervals

exchange argumentExchange argument
A way to prove a greedy choice is right: take any best answer and show that swapping in the greedy choice does not make it worse.Lesson 47 →
greedy algorithmGreedy algorithm
Build an answer step by step. Always take the option that looks best right now and never undo it. It works only when the problem has the greedy-choice property.Lesson 47 →
heapHeap
A complete binary tree stored in an array. Every parent comes before its children in order, so the best item is always at index 0. Push and pop cost O(log n).Lesson 46 →
heapifyHeapify
Turn any array into a heap in O(n). Sift down every non-leaf node, from the last one back to the root.Lesson 46 →
min-heapMin-heap
A heap whose top is the smallest item (min-heap) or the largest (max-heap).Lesson 46 →
priority queuePriority queue
A structure where you add items and always remove the best one next. It is usually built with a heap. JavaScript has no built-in one.Lesson 46 →
sift upSift up
Move one item along a single path, swapping with its parent (sift up) or its smaller child (sift down), until the heap rule holds again.Lesson 46 →
sweep lineSweep line
Sort the starts and ends (the events) and scan once, while you track how many intervals are active.Lesson 48 →

Graphs

adjacency listAdjacency list
For each vertex, the list of its neighbours. It uses O(V + E) space and is the usual way to store a graph.Lesson 49 →
adjacency matrixAdjacency matrix
A V × V table where cell [a][b] says if an edge from a to b exists. O(V²) space, O(1) to test an edge.Lesson 49 →
breadth-first searchBreadth-first search
Explore outward from a start, one distance at a time, using a queue. It finds the path with the fewest edges in unweighted graphs.Lesson 50 →
connected componentConnected component
The biggest possible group of vertices that can all reach each other.Lesson 49 →
depth-first searchDepth-first search
Go as deep as you can along one path, then back up. Use recursion or a stack.Lesson 50 →
directed graphDirected graph
Directed edges go one way only (A to B does not mean B to A). Undirected edges go both ways. Weighted edges carry a number, like distance or cost.Lesson 49 →
edge listEdge list
The input form [[a, b], …]. You usually turn it into an adjacency list before you start.Lesson 49 →
flood fillFlood fill
Repaint a connected region of same-coloured cells by moving outwards from one cell.Lesson 50 →
graphGraph
Vertices joined by edges. Linked lists and trees are special graphs. General graphs may have loops and many routes.Lesson 49 →
vertexVertex
One point (node) in a graph.Lesson 49 →
visited setVisited set
A record of the vertices you have already seen, so the search does not loop forever on cycles.Lesson 50 →

Graph algorithms

Bellman–FordBellman–Ford
Relaxes every edge for up to V − 1 rounds. It handles negative weights and 'at most k edges' limits.Lesson 52 →
DAGDAG
A directed graph with no cycle.Lesson 51 →
Dijkstra's algorithmDijkstra's algorithm
Shortest paths from one start when all edge weights are zero or more. It always expands the closest unfinished vertex, using a priority queue.Lesson 52 →
in-degreeIn-degree
The number of arrows that point into a vertex. For prerequisites: how many are still waiting.Lesson 51 →
Kahn's algorithmKahn's algorithm
A topological sort that keeps removing vertices with in-degree 0 and lowers their neighbours' in-degrees.Lesson 51 →
Kruskal's algorithmKruskal's algorithm
Builds a minimum spanning tree by taking edges from the cheapest up. Skip any edge that joins two vertices that are already connected.Lesson 53 →
lazy deletionLazy deletion
Leave old entries in a heap and skip them when they are popped, instead of searching for them and removing them.Lesson 52 →
minimum spanning treeMinimum spanning tree
A set of n − 1 edges that joins all n vertices, with no cycle and the smallest total weight.Lesson 53 →
negative cycleNegative cycle
A loop whose total weight is below zero, so shortest distances keep getting smaller forever.Lesson 52 →
path compressionPath compression
During find, point every element on the path straight at the root, so later finds are short.Lesson 53 →
Prim's algorithmPrim's algorithm
Builds a minimum spanning tree by growing one tree outwards. It always adds the cheapest edge to a new vertex.Lesson 53 →
relaxationRelaxation
Update a neighbour's best-known distance when the route through the current vertex is cheaper.Lesson 52 →
topological sortTopological sort
A line-up of a directed graph's vertices where every arrow points forward. It is only possible when the graph has no cycle.Lesson 51 →
union by sizeUnion by size
When you join two groups, hang the smaller one under the root of the larger one, so the trees stay low.Lesson 53 →
union-findUnion-find
Tracks which elements are in the same group. find gives the leader of a group. union joins two groups.Lesson 53 →

Dynamic programming

dynamic programmingDynamic programming
Solve a problem by combining the answers to smaller subproblems that repeat. Solve each one only once.Lesson 54 →
edit distanceEdit distance
The fewest insert, delete or replace steps needed to turn one string into another.Lesson 57 →
interval DPInterval DP
DP where dp[i][j] answers a question about the slice from i to j.Lesson 57 →
knapsackKnapsack
Choose items with weights and values under a size limit to get the most value. Each item is used once (0/1) or any number of times (unbounded).Lesson 56 →
longest common subsequenceLongest common subsequence
The longest sequence of characters that appears in order in both strings. The characters do not need to be next to each other.Lesson 57 →
optimal substructureOptimal substructure
The best answer to a problem is built from the best answers to its smaller subproblems.Lesson 54 →
overlapping subproblemsOverlapping subproblems
The same small question comes up many times in a recursion, so saving its answer helps.Lesson 54 →
recurrence relationRecurrence relation
The formula that works out one DP entry from entries you already know.Lesson 55 →
rolling arrayRolling array
Reuse one row of a DP table, because each row only reads the one before it.Lesson 56 →
tabulationTabulation
Fill a table from the smallest cases upwards, instead of using recursion.Lesson 54 →

Tries, bits and the interview

array holeArray hole
A slot that does not exist at all, like in new Array(3). map and forEach skip holes.Lesson 59 →
BigIntBigInt
JavaScript's exact whole-number type for numbers beyond 2^53 − 1. Write it with an n at the end, like 10n.Lesson 59 →
bitmaskBitmask
A number built so that AND, OR or XOR changes only the bits you choose.Lesson 58 →
mistake logMistake log
A short note about each problem you failed: its pattern, the kind of mistake and the fix. Use it to decide what to review.Lesson 60 →
set bitSet bit
A bit whose value is 1.Lesson 58 →
shallow copyShallow copy
A copy of only the outer array or object, so inner arrays are shared. structuredClone makes a deep copy.Lesson 59 →
spaced repetitionSpaced repetition
Solve a problem again after longer and longer gaps (1, 3, 7, 21 days), so it moves into long-term memory.Lesson 60 →
trieTrie
A tree where each edge is a character, so words with the same start share a path.Lesson 58 →
two's complementTwo's complement
The usual way to store negative whole numbers. The top bit is the sign.Lesson 58 →
XORXOR
A bit operator that gives 1 where the two bits differ. Equal pairs cancel out, so x ^ x = 0.Lesson 58 →