Practice Flashcards
What does an abstract data type define?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All Flashcards in Topic 8.1
Below are all 30 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.
8.1.15 cards
What does an abstract data type define?
The **operations** available and what they mean — not how the data is stored.
ADT or data structure: a stack?
**ADT.** It promises push, pop, peek and last-in-first-out order. An array or a linked list is how you build one.
Why hide an ADT's implementation?
So it can be **replaced** without changing any calling code, because callers only ever depended on the operations.
Which ADT enforces uniqueness?
A **set** — duplicates cannot be stored, so the structure guarantees it rather than the programmer remembering to check.
How should an ADT choice be justified in an exam?
By the operation the program performs **most**, with its complexity — and what the alternative would cost.
8.1.25 cards
What does each node in a singly linked list hold?
A **value** and a **reference to the next node**. Nothing else, and no node needs to sit beside another in memory.
Why is reaching the nth element of a linked list O(n)?
There is no calculation that locates a node — you must start at the head and **follow every reference** in turn.
Singly, doubly, circular — what is the difference?
**Singly** points forwards only. **Doubly** points both ways, at the cost of a second reference per node. **Circular** links the last node back to the first, so there is no null end.
What is the linked-list trade-off?
It gives up **direct access** (O(n) to reach position n) and gains **cheap insertion and deletion** (O(1) once in position), plus a size that grows and shrinks.
Why can an array beat a linked list even when complexity says otherwise?
Array elements are **contiguous**, so reading one pulls its neighbours into cache. Linked-list nodes are scattered, so each hop risks a cache miss.
8.1.35 cards
What two things define a linked list?
A **Node** holding a value and a reference to the next, and a **head** reference pointing at the first node.
In what order are the two references assigned when inserting?
**Point the new node forwards first** (new.next ← prev.next), then repoint the previous node (prev.next ← new). The other order overwrites the only reference to the rest of the list.
How is a node deleted from a singly linked list?
By **routing around it**: prev.next ← target.next. Nothing is erased — the node simply becomes unreachable.
Why is deleting the head a special case?
There is no previous node to reroute, so the head itself moves: head = head.next.
How does a traversal of a circular list stop?
When current returns to the **head**. There is no None to test for.
8.1.45 cards
What is the binary search tree ordering rule?
For **every** node, all values in its left subtree are smaller and all in its right subtree are larger — every descendant, not just the children.
Why is a BST search fast?
Each comparison says which side the value must be on, so an **entire subtree** is discarded without being examined. About log₂ n comparisons when balanced.
What does an in-order traversal give you?
Every value in **ascending order** — left subtree, node, right subtree — with no sorting step.
What does sorted input do to a BST?
Every value goes the same direction, so the tree **degenerates into a line**: height n, search O(n), exactly like a linked list.
How is a node with two children deleted?
It is replaced by its **in-order successor** — the smallest value in its right subtree — which preserves the ordering rule.
8.1.55 cards
What two guarantees does a set make?
**No duplicates** and **no order** — both enforced by the structure rather than by the programmer.
Union, intersection, difference — what are they?
**Union** everything in either · **intersection** only what is in both · **difference** in the first and not the second.
Is a − b the same as b − a?
**No.** With a = {1,2,3} and b = {3,4}: a − b = {1,2} but b − a = {4}. Difference is the one operation whose order matters.
Why is set membership O(1) on average?
The value itself computes where it would be stored, so nothing is searched for. A list must compare against every element — O(n).
When is a set the wrong choice?
When the program needs **position or order** — a set has neither, and no index to ask with.
8.1.65 cards
How does a hash table locate a value?
It runs the key through a **hash function**, takes the result **modulo the table size**, and goes straight to that bucket. The address is computed, not searched for.
What three properties must a hash function have?
**Deterministic** (same key, same bucket, always), **fast** (it runs on every operation) and **uniform** (keys spread evenly).
Why are collisions inevitable?
There are more possible keys than buckets, so two keys must eventually map to the same one. It is a counting argument, not a defect.
Chaining or open addressing — what is the difference?
**Chaining** stores colliding keys in a list inside the bucket. **Open addressing** puts them in the next free bucket, so the table can never hold more items than buckets.
What is a hash table's complexity?
**O(1) on average, O(n) in the worst case** — the worst case being a hash function that clusters every key into one bucket.
Topic 8.1 study notes
Full notes & explanations for Fundamentals of ADTs
Computer Science exam skills
Paper structures, command terms & tips
Want smart review reminders?
Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.
Start Free