V

Algorithm Visualizer

ZHEN
Share on WeiboShare on XGitHub repositoryAuthor website
Learning ToolsAlgorithm Complexity ReferenceAlgorithm Learning Paths
Data StructuresArrayLinked ListStackQueue and DequeBinary Search TreeBinary HeapHash TableGraphTrieDisjoint Set UnionLRU CacheSkip ListSegment TreeB+ TreeBloom FilterFenwick Tree
SortingBubble SortCocktail Shaker SortBitonic SortSelection SortInsertion SortBinary Insertion SortShell SortMerge SortTop-Down Merge SortQuick SortThree-Way Quick SortDual-Pivot Quick SortHeap SortCounting SortRadix SortBucket Sort
Graph AlgorithmsDijkstra's Shortest PathKruskal's Minimum Spanning TreePrim's Minimum Spanning TreeBellman-Ford Shortest PathsTopological SortFloyd-WarshallStrongly Connected Components2-SATMaximum FlowBipartite MatchingLowest Common AncestorEulerian Path
Dynamic ProgrammingEdit Distance0/1 KnapsackUnbounded KnapsackLongest Common SubsequenceLongest Increasing SubsequenceCoin ChangeStone MergingTraveling Salesperson DPTree Dynamic ProgrammingDigit DPRerooting DP
Backtracking and SearchN-QueensSubsetsPermutationsCombination SumMaze Solving with DFSNumber of IslandsWord SearchSudoku SolverA* Search
StringsKMP String MatchingRabin-Karp String MatchingBoyer-Moore String MatchingManacher's Longest Palindromic SubstringSuffix ArrayLCP ArrayAho-Corasick AutomatonZ Function
Math and Number TheorySieve of EratosthenesLinear SieveEuclidean AlgorithmBinary ExponentiationExtended Euclidean AlgorithmChinese Remainder TheoremEuler's Totient FunctionMiller-Rabin Primality TestFast Fourier TransformPollard's Rho Factorization
Computational GeometryConvex HullRotating CalipersClosest Pair of PointsLine Segment IntersectionBentley-Ottmann Sweep Line
SearchingBinary SearchLower and Upper BoundSearch in a Rotated Sorted ArrayBinary Search on the AnswerTernary Search

Array

Contiguous storage with constant-time indexed access

Positions are addresses

An array stores same-shaped elements next to one another. Because every element has the same size, index i can be converted directly into an address. Reading or replacing an element therefore takes O(1) time, no matter how long the array is.

Contiguity makes insertion and deletion more expensive. Inserting in the middle shifts the suffix one position right; deleting shifts it left to close the gap. Select an index below, then compare access, insertion, deletion, and appending.

Try it
1
2
3
4
↑0
↑1
↑2
↑3

Select a cell by index, then use an operation above.

Dynamic arrays trade rare copies for fast appends

Languages usually expose a resizable array. When its backing storage is full, it allocates a larger block, copies the existing values, and appends into the new space. One growth costs O(n), but doubling capacity makes growth progressively rarer.

Try it
1
2
3

Length 3 / capacity 4

append 0 times · total copies 0 · amortized 0.0 operations/append (about O(1))

What happens when capacity is full? Keep pressing append.

Across a long sequence of appends, each old value is copied only a small number of times. Charging those occasional copies to all successful appends gives an amortized cost of O(1) per append.

Use an array when: indexed reads, compact storage, and cache-friendly traversal matter more than frequent insertion or deletion in the middle.

Next, compare this contiguous layout with a linked list, where nodes can move independently but indexed access is no longer constant time.