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

Queue and Deque

First-in, first-out processing and its two-ended extension

A queue preserves arrival order

A queue inserts at the rear and removes from the front. The oldest waiting item leaves first, which makes queues natural for scheduling, buffering, and breadth-first search. With a linked list or circular array, enqueue and dequeue both take O(1) time.

Try it
Queue is empty

Press enqueue to add an item at the rear.

A circular array reuses slots vacated at the front instead of shifting every remaining value. Head and tail indices wrap around the capacity while the logical order stays unchanged.

A deque opens both ends

A double-ended queue supports insertion and removal at both the front and rear. It can behave like either a queue or a stack, and it powers sliding-window algorithms that must discard old candidates from one side while adding new candidates on the other.

Try it
1
↑ front
↑ back
2
↑ front
↑ back
3
↑ front
↑ back

A deque accepts insertions and removals at both ends. Try all four operations.

Invariant: removal order follows the logical front-to-rear sequence, even when a circular backing array wraps across its physical boundary.

Queues traverse a tree level by level, while stacks traverse depth first.