Data Structures Fundamentals
About this knowledge base
Data structures ask, “How should data be organized so the operations we need are clear, correct, and affordable?” This is not an algorithm-interview question bank. It builds decision-making ability from ADTs, invariants, and complexity through structural composition, using Agent-engineering concerns such as message history, tool registries, task queues, deduplication, priorities, and dependency graphs.
The course uses the Python 3 standard library. Python syntax is a prerequisite; this course explains why to choose list, deque, dict, set, bisect, heapq, and adjacency lists, along with their capacity, mutability, determinism, and failure boundaries.
Sources and versions
Dynamic Python behavior was checked against the official Python 3.14.6 documentation on 2026-07-14. Course code avoids 3.14-only APIs for Python 3.11+ compatibility. Local verification used Python 3.11.9; that does not prove time or memory characteristics are the same across every interpreter implementation and version.
Where this fits in the overall route
This course belongs to the Engineering and Mathematics Foundations domain of the AI Agent Engineer learning route. Before starting, complete the zero-background prerequisite gate and acquire local function/container ability in Python Fundamentals; you need not complete the whole Python course first. Then apply structure choices to API/JSON data, RAG, workflows, and Agent-state code.
This course covers only the minimum DFS/BFS, binary search, and topological progression required to choose structures. It does not expand into sorting proofs, shortest paths, dynamic programming, red-black or B-tree implementations, or competitive-programming algorithms.
Learning objectives
- Distinguish ADTs, concrete representations, and algorithms; write preconditions, postconditions, and invariants for state.
- Explain time/space complexity, average/worst/amortized cost, and validate trends with measurement.
- Choose linear, hash, priority, and relational structures from their operations.
- Handle mutability, shallow copies, iterator exhaustion, ordering, and determinism.
- Use
bisect,deque,Counter,heapq, and adjacency lists for small engineering problems. - Combine
dict + set + graph + heapinto a testable dependency-task scheduler. - Identify the boundary between in-memory containers and production persistence, concurrency, idempotency, and recovery.
Prerequisites
- You can run
.pyfiles andunittestin Windows 11 and PowerShell 7. - You know variables,
if,for, functions, exceptions, list/dict/set, and basic type hints. - If you cannot write a function that filters a list and counts frequencies without notes, return to Python Fundamentals.
- The examples run offline and use no network, third-party packages, or secrets.
Course structure and recommended order
1. Foundation models
- Data Structures, Abstract Data Types, and Invariants: define operations, ownership, and rules that must always hold.
- Complexity, Resource Costs, and Measurement: compare growth trends and collect evidence with
timeit/tracemalloc.
2. Linear structures
- Contiguous, Linked, and Binary Search: understand list tradeoffs, linked-structure preconditions, and
bisectboundaries. - Mutability, Copying, and Iteration: avoid accidental shared state and exhausted generators.
- Stacks, Queues, and Deques: express LIFO, FIFO, and bounded-window ordering policies.
3. Indexing and priority
- Hash Tables, Dictionaries, Sets, and Counting: master mapping, membership, frequency, order, and deduplication/idempotency boundaries.
- Heaps and Stable Priority Queues: choose the next item only from the ready set, defining ties and starvation policy.
4. Relational structures
- Trees and Hierarchical Traversal: use DFS/BFS for hierarchies and cap depth and node count.
- Graphs, Dependencies, and Topological Order: make edge direction, indegree, DAGs, cycles, and blocked nodes explicit.
5. Engineering decisions
- Composed Structures, Capacity Boundaries, and Performance Diagnostics: establish sources of truth, derived indexes, limits, and a measurement loop.
6. Project and self-assessment
- Project: Dependency Task Scheduler: use adjacency lists, indegrees, and a heap to produce a deterministic order.
- Course-Wide Self-Check and Mastery: closed-book questions, live tasks, and transfer design.
Hands-on practice and project entry point
Supporting code is located at:
data-structures/examples/
├── task_scheduler.py
└── test_task_scheduler.pyFrom the vault root, run:
python -B '.\docs-EN\data-structures\examples\task_scheduler.py'
python -B -m unittest discover `
-s '.\docs-EN\data-structures\examples' `
-p 'test_*.py' `
-vThe current implementation has 24 offline tests covering valid graphs, ties, malformed input, rejection of one-shot iterators, cycles, input immutability, and determinism. Implement it yourself first, then compare the solution; simply running tests is not evidence that you can explain the structure choice.
Mastery standard
- I can choose a structure from primary operations, scale, and ordering requirements instead of merely saying “dictionaries are fast.”
- I can distinguish worst, average, and amortized complexity and account for space cost.
- I can draw alias/shallow-copy reference diagrams and correctly handle one-shot iterator consumption.
- I can explain why
insortis overallO(n)and why a heap is not a fully sorted list. - I can distinguish dict insertion order, sorting, and the lack of a stable-order guarantee for sets.
- I can write DFS/BFS and Kahn topological progression and accurately explain cycles and blocked nodes.
- I can define one source of truth, derived indexes, and invariants for multiple structures.
- All 24 scheduler tests pass, and I can calculate complexity and tie rules by hand.
- I do not mistake an in-memory queue, set-based deduplication, or scheduling order for production reliability semantics.
Relationships with other knowledge bases
| Knowledge base | Boundary with this course |
|---|---|
| Python Fundamentals | Provides syntax, functions, types, exceptions, and tests; this course covers operation cost and structural choice. |
| JSON | Parsed JSON commonly maps to list/dict; encoding, schema, and compatibility are outside this course. |
| Vector Fundamentals and Vector Databases | Vectors and specialized indexes have their own mathematics, retrieval, persistence, and sharding semantics. |
| RAG | General containers can hold chunks and candidates; chunking, retrieval, citations, and evaluation belong to the RAG route. |
| Workflow Automation and Agent Core | This course supplies queue/graph/heap intuition; execution, authorization, stopping, retry, and recovery are in later courses. |
| Runtime Monitoring | This course explains windows and counting structures; monitoring systems govern metrics, alerts, and retention. |
Verification record
- No public replicated material required freezing before the directory reorganization; valuable original content was preserved by concept.
- Under Python 3.11.9, the examples and 24
unittesttests passed. A further 500 random DAGs verified every dependency precedes its successor and input permutations of the same task set do not change output. - All 39 Python code blocks in the 12 course notes were parsed as AST syntax; all 50 full-path wikilinks pointed to existing files.
- Python 3.14, PyPy, production task systems, and real concurrency environments were not run. Complexity tables are models, not fixed performance promises across implementations.
Primary references
Retrieved on 2026-07-14.