CHAPTER 11: ABSTRACT DATA TYPES
11.1 STACKS
11.1.1 Characteristics
- LIFO: Last In, First Out
- Add and remove from only one end (top)
11.1.2 Operations
Push (Add):
<PSEUDOCODE>
Pop (Remove):
<PSEUDOCODE>
11.1.3 Python Implementation
<PYTHON>
11.1.4 Uses
- Interrupt handling
- Evaluating RPN expressions
- Procedure call stack
- Undo mechanisms
11.2 QUEUES
11.2.1 Characteristics
- FIFO: First In, First Out
- Add to rear, remove from front
- Can be circular
11.2.2 Operations
Enqueue (Add):
<PSEUDOCODE>
Dequeue (Remove):
<PSEUDOCODE>
11.2.3 Python Implementation
<PYTHON>
11.2.4 Uses
- Print queues
- Task scheduling
- Breadth-first search
11.3 LINKED LISTS
11.3.1 Characteristics
- Dynamic data structure
- Nodes contain data and pointer to next node
- Can grow/shrink easily
11.3.2 Node Structure
<PYTHON>
11.3.3 Linked List Operations
Insert:
<PYTHON>
Delete:
<PYTHON>
Search:
<PYTHON>
11.3.4 Uses
- Dynamic memory allocation
- Implementation of other ADTs
- Symbol tables
11.4 BINARY TREES
11.4.1 Characteristics
- Hierarchical structure
- Each node has at most two children
- Left child < parent, Right child > parent (in ordered tree)
11.4.2 Node Structure
<PYTHON>
11.4.3 Operations
Insert:
- Start at root
- Compare with current node
- Go left if smaller, right if larger
- Repeat until empty position found
Search:
- Start at root
- Compare with current node
- If match, found
- If target < current, go left; else go right
- Repeat until found or null pointer
Traverse (In-order):
<PYTHON>