This chapter introduces the fundamental building blocks for representing dynamic sets using simple pointer-based data structures. It covers stacks, queues, linked lists, and rooted trees—the rudimentary structures upon which more complex data structures are built. The chapter also demonstrates how to synthesize objects and pointers from arrays, which is essential for languages or environments without native pointer support.
S[1..n] with a top attribute tracking the most recently inserted element. An empty stack has S.top = 0. Underflow occurs when popping an empty stack; overflow when the stack exceeds capacity.Q[1..n] with head and tail attributes that wrap around, enabling the queue to use all n − 1 available slots.key, next, and prev pointers in each node. Variations include singly linked, sorted/unsorted, and circular lists.L.nil) that simplify boundary-condition handling. A sentinel turns a regular doubly linked list into a circular doubly linked list, eliminating special cases for head/tail operations. Sentinels rarely improve asymptotic bounds but simplify code and may reduce constant factors.key[], next[], prev[]) where a common index represents one object.ALLOCATE-OBJECT pops from the free list; FREE-OBJECT pushes onto it. Both run in O(1) time.p, left, and right attributes. Trees with unbounded branching use the left-child, right-sibling representation, which stores only left-child and right-sibling pointers per node, achieving O(n) space for any n-node tree.S.top == 0.S.top and stores x at the new top position.S.top, and returns the element that was at the top.x at Q[Q.tail], then advances Q.tail circularly (wrapping from position n back to position 1).Q[Q.head], then advances Q.head circularly.