Practical Data Structures

  1. A Stack and Last-In, First-Out Order

    A stack exposes the newest retained element. Push adds to the top, and pop removes that element.

    Undergraduate
  2. A Queue and First-In, First-Out Order

    A FIFO queue exposes the oldest retained element. New items enter behind all pending items.

    Undergraduate
  3. Using Both Ends of a Deque

    A double-ended queue supports insertion and removal at the front and back. A useful interface can restrict that flexibility to express a policy.

    Undergraduate
  4. Checking Matched Delimiters with a Stack

    A delimiter stack records which opener needs to be closed next, so it checks order as well as counts.

    Undergraduate
  5. A Priority Queue and Its Tie Rule

    A priority queue selects an item by its ordering key. Its interface should specify what to expect when keys tie.

    Undergraduate
  6. Reading a Binary Heap by Hand

    A binary min-heap keeps each parent no greater than its children. This places a minimum at the root and permits disorder between siblings.

    Undergraduate
  7. A Linked List as Linked Nodes

    A singly linked list represents order through references from one node to the next. Reading an offset generally requires following that many links.

    Undergraduate
  8. Two Neighbor Links in a List

    A doubly linked list records a previous and next reference for each node. An edit should preserve their agreement.

    Undergraduate
  9. A Ring Buffer by Indices

    A ring buffer uses fixed storage and wraps logical positions back to the beginning of its physical array.

    Undergraduate
  10. Choosing a Policy for a Full Queue

    A bounded queue needs a documented outcome when an insertion reaches capacity, including which entries are affected.

    Undergraduate
  11. The Ordering Rule of a Binary Search Tree

    A binary search tree places items on sides of a node according to a comparison rule. The rule must hold across the entire corresponding subtree.

    Undergraduate
  12. Inorder Traversal of a Binary Search Tree

    Inorder traversal visits the left subtree, then the node, then the right subtree. Under the search-tree rule, keys appear in sorted order.

    Undergraduate
  13. Ordered Maps and Insertion-Ordered Maps

    An ordered map can support queries by key order. A dictionary preserving insertion order can replay the history of insertions.

    Undergraduate
  14. Selecting a Range from Ordered Records

    A range query uses ordered keys to find its start and then returns only the items before its stop boundary.

    Undergraduate
  15. Following Prefixes in a Trie

    A trie shares initial parts of keys. The presence of a path for a prefix and the presence of a complete key have separate flags.

    Undergraduate
  16. Two Keys in One Hash Bucket

    A hash table can map distinct keys to the same bucket. Its collision-handling rule preserves the ability to distinguish them.

    Undergraduate
  17. Load Factor of a Hash Table

    A load factor compares stored entries with table slots or buckets according to the table's design.

    Undergraduate
  18. Tracing Linear Probing in a Hash Table

    Linear probing visits successive slots after a collision, wrapping according to the table's capacity.

    Undergraduate
  19. Why Growing a Hash Table Repositions Keys

    A common table indexing rule depends on capacity. Growing that capacity can change a key's home slot even when its hash stays constant.

    Undergraduate
  20. Parent Pointers in Disjoint Sets

    A disjoint-set structure represents each group through parent pointers leading to a representative root.

    Undergraduate
  21. Tracking Recency with a Map and a List

    A recency cache can combine a map for locating entries with an ordering structure for moving and evicting them.

    Undergraduate
  22. Representing Intervals as Pairs

    An interval record holds endpoints and an agreed convention about whether each is included.

    Undergraduate
  23. Merging Ordered Intervals

    An interval union routine sorts by start and keeps the furthest active end while consecutive ranges overlap.

    Undergraduate
  24. Adjacency Lists as Neighbor Records

    An adjacency list stores each vertex with the edges or neighbors that can be reached in one step.

    Undergraduate
  25. Edge Lists and Adjacency Matrices

    An edge list represents actual connections as records. An adjacency matrix assigns a position to each possible ordered pair of vertices.

    Undergraduate
  26. Storing a Sparse Vector

    A sparse vector can store its dimension and only the positions whose values differ from the default zero.

    Undergraduate
  27. Using Prefix Totals for Range Sums

    An array of accumulated totals can answer an unchanged sequence's range sums using two array reads and a subtraction.

    Undergraduate
  28. A Sentinel Node at a List Boundary

    A sentinel node represents a structural boundary, so ordinary nodes can use a more uniform neighbor rule at the ends.

    Undergraduate
  29. Maintaining a Sorted Sequence under Insertion

    A sorted sequence can accept new items by locating their insertion position and then moving storage as needed.

    Undergraduate
  30. Maintaining a Separate Queue for Each Key

    A map of queues preserves arrival order for each key while allowing the application to choose which key to service next.

    Undergraduate