/en-tutor-prep-ib-cs-abstract-data-types-linked-lists-bst-hash/
/en-tutor-prep-ib-cs-abstract-data-types-linked-lists-bst-hash/
General Inquiry: info@TutorZone.com.hk
Office Hours: Monday to Saturday - 9:00 AM to 6:00 PM
WhatsApp Monday to Sunday - 24 hours
Hotline: +852 6828 1809
Instant Support: +852 9061 3106

IB Computer Science: Abstract Data Types — Linked Lists, BSTs, Sets and Hash Tables (tutor lesson plan; 743 steps to node 743 by list, 10 by BST)

IB Computer Science: Abstract Data Types — Linked Lists, BSTs, Sets and Hash Tables (tutor lesson plan; 743 steps to node 743 by list, 10 by BST)

  • 2026-11-28

Students can say a linked list is a chain of nodes, but cannot count the steps to reach node 743, and cannot say why a BST needs tens of times fewer. ADTs are assessed by separating structure from operations, then comparing steps and bytes.

Objectives — the student can (1) state the two parts of an ADT, a high-level description of the data and its operations and an implementation, so one stack ADT with four operations (push, pop, peek, isEmpty) has two implementations and no change in the client; (2) compare a linked list with an array: reaching node 743 of 1,000 takes 743 steps by list and one by index, while an insert in the middle shifts 500 elements in an array and changes 2 pointers in a list; (3) count memory: 1,000 elements take 4,000 bytes in an array, 12,000 in a singly linked list (3.0 times) and 20,000 in a doubly linked list (5.0 times), the difference being pointers; (4) draw and trace a BST: 7 nodes give height 2 and at most 3 comparisons when balanced, but height 6 and 7 comparisons (2.3 times) when inserted in order, and 1,024 nodes balanced search in 10 comparisons against 743 steps by list, 74.3 times faster; (5) do set operations: A has five elements and B has three, giving a union of 6, an intersection of 2 and a difference of 3, with the intersection size deciding the subset test; (6) count a hash table: 7 keys in 5 slots give load 1.4, 4 collisions and a longest chain of 4, while 10 slots give load 0.7 and 2 collisions; (7) explain the lookup gain: 1,000 searches cost 500,000 comparisons on a list at 500 each against about one in a hash table, 500 times fewer.

01 Prerequisites (3-minute check)

If any of these fails, fix it before the lesson starts.

Skill Quick check Pass mark
Indices how is element 743 of an array reached? by index, in one step
Logarithms 2 to which power gives 1,024? 10
Sets A has five elements and B has three, what is the largest possible intersection? three

02 Lesson flow (60 minutes)

Time Stage Tutor does Student does
0-8 min Opening check how many steps to reach element 743? one number per structure
8-24 min ADTs and linked lists 1,000 nodes, 743 steps, 3.0 times memory draw three nodes and an insert
24-40 min BST structure and operations 7 nodes, height 2 against 6 draw the tree and walks
40-50 min Set operations A has 5, B has 3 write union, intersection, difference
50-57 min Hash tables and load 7 keys in 5 slots, 4 collisions count load and collisions
57-60 min Exit check three questions marked on the spot work alone

03 Teaching script (read it out)

Scene 1: ADTs and linked lists — structure and operations apart

Start with a stack as an ADT. The description is four operations, push, pop, peek and isEmpty; the implementation behind them may be an array or a linked list, and the client sees no change when it is swapped. Ask for the line an ADT is the manual and the implementation is the engine, which is enough for B4.1.1.
Then compare a linked list with an array. Reaching node 743 of 1,000: an array holds contiguous memory so an index reaches it in one step, while a list holds only a head pointer and must follow next 743 times, which is what no random access means. Insertion in the middle is the mirror image: an array shifts the 500 elements after the gap, a list changes 2 pointers once the position is found, so the insert is constant time and the search for the position is the cost. Ask for the full sentence, a list inserts quickly but finds slowly, because half of it is the answer.
Count memory next: 4 bytes of data and 8 bytes per pointer. 1,000 elements are 4,000 bytes in an array, 12,000 in a singly linked list with one next pointer, 3.0 times, and 20,000 in a doubly linked list with prev and next, 5.0 times. Ask what the extra bytes buy: no shifting on insert or delete in the middle.
Cover the three shapes: singly linked moves forward only, doubly linked has prev and next so a node can be removed without its predecessor, and circular links the last node back to the first, so a traversal needs a stop condition or it never ends. Ask for the trap in a circular list: remember the head and stop on return to it.

Student task: draw a three-node singly linked list, insert a node in the middle, write which 2 pointers change, and state how many elements an array would shift.

Scene 2: BSTs — why balance is worth tens of times

Fix the BST property first: every node in the left subtree is smaller and every node in the right subtree is larger. Inserting 50, 30, 70, 20, 40, 60 and 80 gives 7 nodes at height 2 and at most 3 comparisons to find any of them. Ask for the in-order walk, left then self then right, which always prints ascending order and is the reason a BST can sort.
Now degenerate it: inserting 10, 20, 30, 40, 50, 60 and 70 in order puts every node on the right, so the tree becomes one diagonal of height 6 and 7 comparisons, 2.3 times worse. Ask for the cause: the shape depends on the insertion order, not on the number of nodes. That question appears almost every year and the answer must contain insertion order.
Scale it up: 1,024 nodes balanced have height 10, since 2 to the tenth is 1,024, so a search costs at most 10 comparisons, while a list of 1,000 records reaching node 743 costs 743 steps, a factor of 74.3. Degenerate the BST and the same 1,024 nodes become a chain of 1,024 levels and the advantage disappears, which is why real implementations use balanced trees.
Deletion has three cases: a leaf is removed, a node with one child is replaced by that child, and a node with two children is replaced by the smallest node in the right subtree, the in-order successor, which is then deleted. Ask why the successor: it is larger than every node on the left and smaller than the rest of the right subtree, so the BST property still holds.

Student task: insert 50, 30, 70, 20, 40, 60 and 80 into a tree, write the height and the worst comparison count, then state how many levels an in-order insertion produces.

Scene 3: Sets and hash tables — load factor sets the collisions

Do the set operations first. A has five elements and B has three with two in common, so the union holds 6, the intersection 2 and the difference A minus B 3. Ask for the size checks: an intersection cannot exceed the smaller set (2 is not more than 3) and a union cannot exceed the two sizes added (6 is not more than 8). The subset test uses one line: B is a subset of A exactly when the intersection size equals the size of B, and here 2 against 3 fails, the missing element being 12.
Turn to the hash table. 7 keys in 5 slots by remainder after division: 12, 17, 22 and 7 all land in slot 2, 19 and 4 land in slot 4 and 31 lands in slot 1, giving 4 collisions, a longest chain of 4 and a load factor of 1.4. Open 10 slots and the keys spread into four groups, so collisions fall to 2 and the load to 0.7. Ask for the sentence the load factor is keys over slots, and a higher load means more collisions and slower lookup, then for the two resolutions: chaining keeps a list per slot, open addressing such as linear probing tries the next slot when one is taken.
Finish with the cost: 1,000 searches on an unsorted list compare 500 records on average for 500,000 comparisons in all, while a hash table reaches the record in about one, 500 times fewer. Ask for the price: a hash table keeps no order, needs extra space and degrades to a single chain when every key collides. Java HashMap and HashSet and Python dict and set are this structure with average constant lookup, and the guide names that mapping, so say it out loud.

Student task: write the union, intersection, difference and subset answers for A and B, then place the 7 keys by remainder in 5 slots and mark the collision count and the longest chain.

04 Question types and worked steps

Type Example Steps Answer
Choose a data structure 1,000 records with frequent inserts in the middle three questions: random access wanted means an array, many inserts mean a list, ordered search means a BST insert changes 2 pointers; node 743 costs 743 steps
Traverse a linked list walk to node 743 three steps: start at the head, follow next each time, count until the target 743 steps against one index step
Draw and walk a BST 7 nodes inserted as 50, 30, 70, 20, 40, 60, 80 three steps: place each node left or right, mark the height, write the in-order walk height 2, at most 3 comparisons, in-order gives 20, 30, 40, 50, 60, 70, 80
Set operations A has 5, B has 3, overlapping in 2 four steps: list the elements, union with duplicates removed, intersection of the common ones, difference of A only; subset by intersection size union 6, intersection 2, difference 3; B is not a subset
Count load and collisions 7 keys, 5 slots, remainder hashing three steps: place each key by remainder, count collisions and the longest chain, divide keys by slots 4 collisions, longest chain 4, load 1.4; 10 slots give 2 and 0.7
Sanity check (teach this): five checks: (1) the step count never exceeds the node count, reaching node 743 takes at most 743 steps, and 1,000 means the head was not counted as the first; (2) the list bytes must be a simple multiple of the array, 12,000 over 4,000 is 3.0, and an odd figure means a pointer was missed; (3) a BST height is never below the logarithm of its node count, 7 nodes need at least 2 levels, and one level means the tree was drawn as a single node; (4) an intersection cannot exceed the smaller set (2 against 3) and a union cannot exceed the sizes added (6 against 8); (5) the load factor is keys over slots, 7 over 5 is 1.4, and collisions are always fewer than keys, 4 against 7, since a key can collide only once. The usual misjudgement is reading a fast insert as a fast structure: a list inserts in constant time but must first walk 743 steps, so the whole operation stays linear.

05 Independent practice (3 questions)

Question Answer What to watch
a linked list holds 1,000 nodes and a balanced BST holds 1,024. (a) how many steps to reach node 743 in the list? (b) how many comparisons in the BST? (c) what is the ratio? (a) 743; (b) 10; (c) 74.3 times a BST is counted by height, not by node count
A has five elements and B has three with 2 shared. (a) union size? (b) intersection size? (c) is B a subset of A? (a) 6; (b) 2; (c) no, the intersection of 2 does not equal the 3 of B the subset test compares the intersection with the other set size
7 keys go into 5 slots. (a) what is the load factor? (b) if the largest slot holds 4 keys, how many comparisons to find its last one? (c) how many collisions remain at 10 slots? (a) 1.4; (b) 4; (c) 2, at load 0.7 a load above one guarantees collisions

06 Common mistakes and what to say

Mistake Student writes Say this
Assuming list lookup is constant the answer says inserts are fast so lookups are fast too the insert changes 2 pointers but must first walk to the position, and node 743 is 743 steps away. A linked list has no random access.
Counting BST nodes instead of height the answer says 1,024 nodes need 1,024 comparisons a BST costs height, not node count: 10 when balanced and 1,024 only when degenerate. The insertion order fixes the shape.
Mixing up union and difference the answer gives a difference of 6 a union merges both sides without duplicates (6), a difference keeps what is only in A (3) and an intersection keeps what is in both (2). The three never swap.
Ignoring that load drives collisions the answer says one more slot changes nothing 7 keys in 5 slots give load 1.4 and 4 collisions; 10 slots cut the load to 0.7 and the collisions to 2. The slot count decides how far the keys spread.

07 Homework (paper, section and question numbers)

08 Exit check (last 5 minutes)

Question Answer Decision
Steps how many steps to node 743? one step means array was assumed
BST height of 7 balanced nodes? seven means node count was used
Hashing load of 7 keys in 5 slots? 7 means the division was skipped

09 Tutor FAQ

Is B4 SL or HL?

B4 abstract data types is HL. B3.2 multi-class OOP and the B4.1 linked lists, BSTs and hash tables all sit in HL, while SL stops at B3.1 single-class OOP and the B2 arrays and lists. Check the level the school entered before teaching Paper 2.

If a list inserts so fast, why not use it everywhere?

because finding the position is slow: node 743 of 1,000 takes 743 steps, and it uses more memory (3.0 times). Use it when inserts and deletes in the middle dominate and random access is not needed; use an array when indexing matters.

What is the worst case for a hash table?

every key lands in one slot, the table degenerates into a single chain and lookup goes from about one comparison to 7, the number of keys. That is why the load factor is capped, commonly at 0.75 before a resize and rehash.

Find a tutor — freeTutor Registration →

A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.

Join as a tutor or coach — academic, music, sports, arts, STEM. Free to register. See how it works →