Independent reviewer · not a CSC or DICT publicationSign in to practice

Study notes · Data structures · DICT

Data Structures

Know what each structure is good at and what it costs. Exam items usually ask you to simulate operations (push/pop, enqueue/dequeue, insertions into a tree) or to choose the right structure.

2023 FAQ (copy)Scope: Arrays, stacks, queues, linked lists, trees, searching.

§1 Core structures

StructureOrder / shapeTypical costs
ArrayContiguous, indexedAccess O(1); insert in middle O(n)
Linked listNodes with next pointersInsert at head O(1); search O(n)
StackLIFOpush/pop O(1)
QueueFIFOenqueue/dequeue O(1)
Binary search treeLeft < node < rightSearch O(log n) if balanced, O(n) worst case
Hash tableKey → bucketAverage O(1) lookup

§2 Tree traversals

§3 Searching and sorting

§4 Worked examples

Example 1

Evaluate the postfix expression 6 2 / 3 +.

  1. Push 6, push 2.
  2. '/' pops 2 and 6 → 6 / 2 = 3; push 3.
  3. Push 3. '+' pops → 3 + 3 = 6.

Answer 6

! Common traps

  • Popping operands in the wrong order for − and /.
  • Running binary search on unsorted data.