3.3 Core Data Structures
Key Takeaways
- Arrays give indexed access in constant time but costly middle inserts/deletes; linked lists trade random access for flexible node inserts
- Stacks are LIFO (call frames, undo); queues are FIFO (job scheduling, buffering)
- Trees organize hierarchical data; binary search trees support ordered lookup when balanced
- Hash tables aim for average-case constant-time key lookup using a hash function into buckets
- Big-O on the Cyber Test is comparative intuition—how cost scales—not formal proof writing
3.3 Core Data Structures
Quick Answer: Choose structures by access pattern: arrays for indexed lookup, linked lists for frequent insert/delete at known nodes, stacks for LIFO, queues for FIFO, trees for hierarchy/ordered search, and hash tables for fast key-based retrieval. Big-O describes how time or space grows as input size grows—compare trends, do not write graduate proofs.
Software is not only algorithms; it is algorithms operating on data structures—organized ways to store and access information. The Cyber Test sits at aptitude depth: know what each common structure is good for, what operations it supports well or poorly, and how to talk about performance with simple big-O intuition.
Why Data Structures Matter
The same logical data can be stored many ways. The wrong structure turns a quick check into a slow scan; the right structure makes security tools, parsers, and network services responsive. When a question describes a workload ("always process the oldest request first," "need fast lookup by username," "nested file folders"), map the description to a structure.
Arrays
An array stores elements in a contiguous block, each reachable by an integer index.
Strengths:
- Access by index is typically O(1) — jump straight to position
i - Excellent spatial locality (friendly to caches)
- Simple and space-efficient for fixed or carefully managed lengths
Tradeoffs:
- Inserting or deleting in the middle usually requires shifting elements — often O(n)
- Fixed-size arrays may need reallocation/copy to grow; dynamic arrays amortize growth but still pay occasional resize costs
Use arrays when you need random access, store homogeneous records, or implement buffers of known bounds.
Linked Lists
A linked list stores elements in nodes, each holding a value and a pointer/reference to the next node (doubly linked lists also point backward).
Strengths:
- Insert or delete at a known node position can be O(1) pointer rewiring (once you are there)
- Grows naturally without contiguous reallocation
Tradeoffs:
- Access by index is O(n) — you walk from the head
- Extra pointer memory and weaker cache locality than arrays
Use linked lists when middle insertions/deletions dominate and random indexing is rare. Many language "list" types are dynamic arrays underneath—exam questions mean the conceptual linked structure unless they specify otherwise.
Stacks (LIFO)
A stack follows Last-In, First-Out. Primary operations:
- Push — place an item on top
- Pop — remove the top item
- Peek/top — read the top without removing
Classic uses: function call frames, expression evaluation, undo history, depth-first traversal bookkeeping, matching nested delimiters (parentheses, HTML/XML tags). If a problem says the most recently added item must be handled next, think stack.
Push/pop at the top are O(1) for a well-implemented stack.
Queues (FIFO)
A queue follows First-In, First-Out. Primary operations:
- Enqueue — add at the back
- Dequeue — remove from the front
Classic uses: print/job scheduling, request buffers, breadth-first search, packet/event processing when fairness by arrival order matters. If the oldest waiting item should run next, think queue.
A priority queue variant serves highest-priority items first rather than strict arrival order—know that it exists; detailed heap internals are beyond typical Cyber Test depth.
Trees
A tree organizes nodes hierarchically: one root, edges to children, no cycles. Leaves have no children.
Important special case: a binary tree has at most two children per node. A binary search tree (BST) stores keys so left subtree keys are less and right subtree keys are greater (ordering convention). In a balanced BST, search/insert/delete trend toward O(log n); if the tree degenerates into a line, those operations fall back toward O(n).
Trees model file systems, org charts, decision processes, syntax trees, and hierarchical configurations. Cyber-relevant example: directory structures and certificate chains are tree-like hierarchies.
Hash Tables
A hash table (hash map/dictionary) stores key → value pairs. A hash function maps a key to a bucket index. Ideal average-case lookup, insert, and delete are O(1).
Caveats at exam depth:
- Collisions (two keys → same bucket) are handled by chaining or open addressing
- Poor hash functions or pathological inputs degrade toward O(n)
- Hash tables do not keep keys in sorted order (unless you add extra structures)
Use hash tables when you need fast membership tests or retrieval by key (user IDs, IP sets, configuration maps) and ordering is unimportant.
Operation Cheatsheet
| Structure | Access pattern | Typical strong operations | Watch-outs |
|---|---|---|---|
| Array | Index i | Get/set by index O(1) | Mid insert/delete O(n) |
| Linked list | Walk nodes | Insert/delete at known node | Index access O(n) |
| Stack | LIFO top | Push/pop O(1) | Wrong if FIFO needed |
| Queue | FIFO ends | Enqueue/dequeue O(1) | Wrong if LIFO needed |
| Tree / BST | Hierarchical / ordered | Balanced search ~ O(log n) | Skewed tree ~ O(n) |
| Hash table | Key lookup | Average get/put O(1) | Collisions; unordered keys |
Big-O Intuition (Exam Depth)
Big-O notation describes how resource cost grows as input size n grows—focusing on the dominant term and ignoring constants. You need comparative sense, not formal proofs.
Common Cyber Test-relevant classes:
| Class | Name | Intuition | Example |
|---|---|---|---|
| O(1) | Constant | Cost stays flat as n grows | Array index; good hash lookup |
| O(log n) | Logarithmic | Cost grows slowly; doubling n adds a little work | Balanced binary search |
| O(n) | Linear | Work scales with each additional element | Scan a list; walk a linked list to index i |
| O(n log n) | Linearithmic | Common efficient sort territory | Good comparison sorts |
| O(n²) | Quadratic | Nested pairwise work; painful for large n | Naive double loops over all pairs |
How to use this on questions:
- Prefer structures/algorithms whose growth matches the workload's scale
- "Must check every item" → at least linear time
- "Halves the search space each step" → logarithmic flavor
- Nested loops over the same n × n space → quadratic danger
Do not overfit tiny constant differences ("is this 2n or 3n?"). Big-O for this exam is about shape of growth and which structure fits which operation.
Choosing a Structure: Mini Scenarios
- Browser back button → stack (most recent page pops first)
- Help-desk tickets in arrival order → queue
- Find employee record by ID millions of times → hash table
- Store 10 integers and read position 7 repeatedly → array
- Folder within folder within folder → tree
- Insert frequently at the front of a sequence without shifting a huge array → linked list (conceptually)
Cyber Test Framing
Questions may appear under programming or computer fundamentals. They rarely demand implementing red-black tree rotations. They do demand that you recognize LIFO vs FIFO, indexed vs hashed vs hierarchical access, and rough cost classes. Tie each structure back to operations: what is cheap, what is expensive, and when you would pick it. That operational judgment—not vendor trivia—is what the Cyber Test is probing.
Which data structure best models a printer that should always process the oldest waiting job next?
What is the typical time complexity of reading element i from a contiguous array by index?
Function call frames and an undo history are most naturally implemented with which structure?
Average-case key lookup in a well-designed hash table is best described as: