Data Structures Algorithms
Designing the containers that hold and retrieve data. Learn the 7 topics below step by step with interactive visualizations.
A last-in-first-out (LIFO) structure where the last item in comes out first. Insertion and removal happen only at one end (the top), and it's the backbone of the call stack, undo, bracket matching, and DFS.
O(1) push/popA first-in-first-out (FIFO) structure where the first item in comes out first. You add at the rear and remove at the front, and it's the basis of BFS, task queues, and buffering.
O(1) enqueue/dequeueA double-ended queue that allows insertion and removal at both ends. It can mimic both a stack and a queue, making it useful for sliding windows, palindrome checks, and bidirectional search.
O(1) at both endsA structure where each node holds a value and a pointer to the next node. It needs no contiguous memory, so insertion and deletion are O(1), but random access is O(n) and must be traversed sequentially.
Insert O(1) · Search O(n)A binary tree that keeps the rule left child < parent < right child. Its sorted structure gives average O(log n) search, insert, and delete, but it degrades to O(n) if it becomes lopsided.
Avg O(log n)A complete binary tree where a parent is always smaller than its children (min-heap), implemented as an array. Because the root is always the minimum, it's the standard implementation of a priority queue and is central to Dijkstra and heap sort.
Insert/Delete O(log n)Maps keys to bucket indices with a hash function to store and look up in average O(1). When different keys collide into the same bucket, it resolves them with chaining (linked lists) or open addressing.
Avg O(1)