All Algorithm & Data Structure Visualizations

Visualizations

88 visualizations

array

6
beginner

Delete from Given Index

Remove the element at a given index by shifting all subsequent elements one position to the left.

array
beginner

Deletion in Array

Remove the last element from the array, decreasing its size by one.

array
beginner

Insert at given index

Insert a new element at a given index by shifting all subsequent elements one position to the right.

array
beginner

Insertion

Add a new element at the end of the array, increasing its size by one.

array
beginner

Reverse an array

Reverse the order of all elements in the array using the two-pointer technique, swapping from both ends inward.

array
beginner

Traversal in Array

Visit each element of the array one by one from start to end, accessing every index exactly once.

array

two-pointers

6
intermediate

Two Pointers

Uses left and right indices moving toward each other to solve pair-sum and partitioning problems in O(n).

two-pointers
intermediate

Two Sum II

Finds two indices in a sorted array that sum to a target using opposite-end two pointers; O(n) time, O(1) space.

two-pointers
intermediate

3 Sum

Finds all unique triplets summing to zero by sorting and applying two pointers for each fixed element; O(n²).

two-pointers
intermediate

Sort Colors

Sorts an array of 0s, 1s, and 2s in one pass using Dijkstra's Dutch National Flag three-pointer algorithm.

two-pointers
intermediate

Container With Most Water

Finds two lines forming the largest water container using two pointers that always move the shorter line inward.

two-pointers
beginner

Move Zeroes to End

Moves all zeros to the end while preserving relative order of non-zero elements in-place; O(n) time, O(1) space.

two-pointers

sliding-window

4
intermediate

Max Sum Subarray of Size K

Finds the maximum sum of any k consecutive elements using a fixed-size sliding window in O(n).

sliding-window
intermediate

Sliding Window

Maintains a moving subarray window and slides it to avoid recomputing overlapping regions; O(n).

sliding-window
beginner

Max Consecutive Bit

Counts the longest run of consecutive 1s in a binary array by resetting a counter on each 0; O(n).

sliding-window
intermediate

Maximize Number of 1's

Finds the maximum consecutive 1s achievable by flipping at most k zeros using a variable sliding window; O(n).

sliding-window

prefix-sum

3
beginner

Prefix Sum

Preprocesses cumulative sums so any range sum query can be answered in O(1) after O(n) build time.

prefix-sum
intermediate

Subarray Sum Equals K

Counts subarrays with sum exactly equal to k using prefix sums and a HashMap; O(n) time and space.

prefix-sum
intermediate

Matrix Block Sum (2D Prefix Sum)

Computes block sums for every cell in a matrix using 2D prefix sums and the inclusion-exclusion formula; O(m×n).

prefix-sum

kadane-s-algorithm

3
intermediate

Kadane's Algorithm

Finds the maximum sum contiguous subarray in O(n) by deciding at each step whether to extend or restart.

kadane-s-algorithm
intermediate

Max Circular Subarray Sum

You are given a circular array arr[] of integers, find the maximum possible sum of a non-empty subarray. In a circular array, the subarray can start at the end and wrap around to the beginning. Return the maximum non-empty subarray sum, considering both non-wrapping and wrapping cases.

kadane-s-algorithm
intermediate

Maximum Product Subarray

Finds the maximum product subarray by tracking both max and min products to handle negative flips; O(n).

kadane-s-algorithm

strings

1
beginner

String Basic Operations

Covers core string primitives — access, concat, substring, search, and split — with their complexity tradeoffs.

strings

two-pointers-palindrom

5
beginner

Reverse a String

Swaps characters from both ends toward the middle using two pointers; O(n) time, O(1) space.

two-pointers-palindrom
beginner

Valid Palindrome

Verifies a string reads the same forwards and backwards using the two-pointer technique.

two-pointers-palindrom
beginner

Valid Palindrome II

Checks if a string is a palindrome while skipping spaces using two pointers.

two-pointers-palindrom
intermediate

Length of the longest substring

Finds the longest substring with no repeating characters using a sliding window and hash set; O(n).

two-pointers-palindrom
intermediate

Palindrome Substrings

Counts all palindromic substrings by expanding around each center; O(n²) time, O(1) space.

two-pointers-palindrom

sliding-window-strings

2
intermediate

Count Occurrences of Anagrams

Counts all anagram occurrences of a pattern in a string using a fixed-size sliding window; O(n).

sliding-window-strings
beginner

Longest Nice Substring

Finds the longest substring where every letter appears in both cases using divide-and-conquer.

sliding-window-strings

binary-search

6
beginner

Binary Search

Eliminates half the search space each step on a sorted array; O(log n).

binary-search
intermediate

Peak Element

Finds any element strictly greater than its neighbors using binary search; O(log n) even on unsorted arrays.

binary-search
beginner

Square Root (x)

Finds the integer floor of √n without built-in functions using binary search on the answer space.

binary-search
beginner

Search Insert Position

Returns the index where a target exists or should be inserted in a sorted array; the lower-bound binary search.

binary-search
intermediate

Search in a Rotated Sorted Array

Searches a rotated sorted array in O(log n) by determining which half is still sorted at each step.

binary-search
intermediate

Find Minimum in Rotated Sorted Array

Finds the minimum element in a rotated sorted array in O(log n) by comparing mid with the right boundary.

binary-search

lower-upper-bound

2
beginner

Ceil the Floor

Finds both floor and ceil of a target in a single binary search pass over a sorted array.

lower-upper-bound
beginner

Floor in a Sorted Array

Finds the largest element ≤ target in a sorted array using binary search with a "last valid" tracker.

lower-upper-bound

stack

1
beginner

Stack

Last-In-First-Out structure with O(1) push, pop, and peek; backbone of DFS, expression evaluation, and undo.

stack

monotonic-stack

6
intermediate

Asteroid Collision

Simulates asteroid collisions where larger survive, using a stack to process each asteroid in O(n).

monotonic-stack
intermediate

Daily Temperatures

Returns the number of days until a warmer temperature for each day using a monotonic decreasing stack; O(n).

monotonic-stack
advanced

Largest Rectangle in Histogram

Finds the maximum rectangle area in a histogram using a monotonic increasing stack; O(n) time.

monotonic-stack
intermediate

Next Greater Element

Finds the next greater element to the right for each array element using a monotonic decreasing stack; O(n).

monotonic-stack
intermediate

Next Greater Element II

Finds next greater elements in a circular array by iterating twice with modulo and a monotonic stack; O(n).

monotonic-stack
intermediate

Online Stock Span

Computes how many consecutive prior days had a price ≤ today using a monotonic stack with accumulated spans; O(1) amortized.

monotonic-stack

expression-evaluation

4
intermediate

Infix to Postfix

Converts infix expressions to Reverse Polish Notation using Dijkstra's Shunting-Yard algorithm; O(n).

expression-evaluation
intermediate

Infix to Prefix

Converts standard infix expressions to prefix (Polish) notation using reversal and the Shunting-Yard algorithm.

expression-evaluation
intermediate

Postfix to Infix

Converts postfix to infix by wrapping each operator application in parentheses using a stack; O(n).

expression-evaluation
intermediate

Postfix to Prefix

Converts postfix to prefix by pushing operands and combining on operators using a stack; O(n).

expression-evaluation

stack-simulation

2
beginner

Backspace String Compare

Simulates backspace characters and compares two strings using two pointers from the end; O(n) time, O(1) space.

stack-simulation
beginner

Remove Adjacent Duplicates

Removes all adjacent duplicate characters repeatedly using a stack; O(n) time and space.

stack-simulation

linked-list

1
beginner

Linked List

A chain of nodes each holding a value and a pointer to the next; O(1) head insert, O(n) search.

linked-list

fast-and-slow-pointers

4
beginner

Detect Loop in Linked List

Detects a cycle in a linked list using Floyd's fast-slow pointer algorithm; O(n) time, O(1) space.

fast-and-slow-pointers
intermediate

Linked L:ist cycle ||

Finds the node where a cycle begins by resetting one pointer to head after detection; O(n) time, O(1) space.

fast-and-slow-pointers
beginner

Middle of Linked List

Finds the middle node of a linked list in one pass using fast (×2) and slow (×1) pointers.

fast-and-slow-pointers
intermediate

Remove Nth Node From End

Removes the Nth node from the end of a linked list in one pass using a gap-of-N two-pointer technique.

fast-and-slow-pointers

reversal-pattern

4
beginner

Palindrome Linked List

Checks if a linked list is a palindrome by finding the middle, reversing the second half, and comparing.

reversal-pattern
beginner

Reverse Linked List

Reverses a singly linked list in-place by relinking pointers; O(n) time, O(1) space.

reversal-pattern
intermediate

Reverse Linked List II

Reverses only a sublist from position left to right in-place using the head-insertion trick; O(n).

reversal-pattern
intermediate

Rotate List

Rotates a linked list right by k places by making it circular and cutting at the new tail; O(n).

reversal-pattern

merge-sort

3
beginner

Merge Two Sorted Lists

Merges two sorted linked lists into one sorted list by comparing nodes with a dummy head; O(n+m).

merge-sort
beginner

Remove Duplicates from Sorted List

Removes consecutive duplicate nodes from a sorted linked list in-place; O(n) time, O(1) space.

merge-sort
intermediate

Sort List

Sorts a linked list using Merge Sort — find middle, split, sort halves, merge; O(n log n) time, O(log n) space.

merge-sort

doubly-linked-list

2
intermediate

LRU Cache

Evicts the least recently used item in O(1) using a HashMap combined with a doubly linked list.

doubly-linked-list
beginner

Reverse a Doubly Linked List

Reverses a doubly linked list by swapping prev and next pointers for every node; O(n) time, O(1) space.

doubly-linked-list

merge-sort-reorder

1
beginner

Flatten Multilevel Doubly Linked List

merge-sort-reorder

hashmap

2
beginner

Majority Element

hashmap
beginner

Top K Frequent Elements

Given a non-empty integer array arr[]. Your task is to find and return the top k elements which have the highest frequency in the array.

hashmap

divide-conquer

1
intermediate

Divide and Conquer

Splits a problem into halves, solves each recursively, and combines results — basis of Merge Sort and Binary Search.

divide-conquer

tree

3
beginner

Inorder Traversal

An inorder traversal first visits the left child (including its entire subtree), then visits the node, and finally visits the right child (including its entire subtree).

tree
beginner

Postorder Traversal

A postorder traversal first visits the left child (including its entire subtree), then visits the right child (including its entire subtree), and finally visits the node itself.

tree
beginner

Preorder Traversal

A preorder traversal first visits the node, then visits the left child (including its entire subtree), and finally visits the right child (including its entire subtree).

tree

bst

1
intermediate

Binary Search Tree (BST)

Ordered binary tree where left < node < right; O(log n) average search, insert, and delete.

bst

graph

2
intermediate

Breadth First Search

graph
intermediate

Depth First Search

graph

greedy

1
intermediate

Sorting Local Choice

Sort array or select elements to make locally optimal choice and achieve global optimum.

greedy

sorting

9
beginner

Bubble Sort

Repeatedly swaps adjacent elements until the array is sorted — simple, O(n²), good for teaching.

sorting
beginner

Selection Sort

Finds the minimum unsorted element and places it at the correct position; always O(n²) comparisons.

sorting
beginner

Insertion Sort

Builds a sorted array one element at a time by inserting each into its correct position; O(n) on nearly-sorted input.

sorting
intermediate

Merge Sort

Divides the array in half, sorts each half, then merges — guaranteed O(n log n) and stable.

sorting
intermediate

Quick Sort

Picks a pivot, partitions around it, and recursively sorts each side; O(n log n) average, in-place.

sorting
intermediate

Heap Sort

Sorting using binary heap data structure

sorting
intermediate

Counting Sort

Non-comparison sort using counting

sorting
advanced

Radix Sort

Sort by processing individual digits

sorting
advanced

Bucket Sort

Distribute elements into buckets and sort

sorting

search

1
beginner

Linear Search

Scans every element one by one; works on any array but O(n) in the worst case.

search

linear

2
beginner

Queue

First-In-First-Out structure with O(1) enqueue and dequeue; backbone of BFS and task scheduling.

linear
beginner

Doubly Linked List

Each node holds prev and next pointers enabling O(1) deletion at any known node and backward traversal.

linear