Exam Multiple Choice Questions Exam Style
Contains all 46 questions from Doctor Revision + 26 comprehensive lecture concept questions.
Coding Challenges
12 ProblemsRearrange the scrambled lines of C++ code into the valid logical sequence and click Run Code.
Challenge Title
How the Doctor Thinks in CSC204
Based on the exact 46 questions from doctor revision.pdf, the instructor does NOT test simple rote memorization. Every exam question tests one of 7 distinct algorithmic and C++ mechanics traps. Master these 7 archetypes and you will ace the exam.
The Trap: Believing that private variables can only be accessed by the specific instance itself.
The Reality: In C++, access control is per class! Method richer(const Wallet& w) can directly read w.cash without errors.
The Trap: Writing loc->next = added; added->next = loc->next;.
The Reality: Since loc->next is now added, added->next points to itself, cutting off and leaking the rest of the list! Always link downstream first!
The Trap: Thinking dynamic objects (new) automatically destruct when the pointer goes out of scope.
The Reality: Destructor for heap objects runs ONLY when delete ptr; executes! Stack objects destruct in exact reverse order (LIFO) at closing brace }.
The Trap: In void add(int c) { c += 1; }, expecting the member variable to increment.
The Reality: The parameter name shadows this->c! The local parameter increments while the member variable is completely untouched.
The Trap: Getting confused when queueRear < queueFront.
The Reality: Count formula: (rear - front + capacity) % capacity + 1. Without a count variable, full and empty formulas collide!
The Trap: Forgetting to reset queueRear = nullptr when the last remaining node is dequeued.
The Reality: If queueFront becomes nullptr, leaving queueRear dangling causes memory corruption on the next enqueue.
CSC204 Quick Reference & Complexity Matrix
Authoritative Big-O comparisons and pointer mechanics summary for instant exam review.
| Operation | Static Array | Singly Linked List | Doubly Linked List | Array Stack / Queue | Linked Stack / Queue |
|---|---|---|---|---|---|
| Access $i$-th element | O(1) | O(n) | O(n) | N/A (restricted) | N/A (restricted) |
| Insert at Head / Front | O(n) (shifting) | O(1) | O(1) | O(1) (push/enqueue) | O(1) (push/enqueue) |
| Delete at Head / Front | O(n) (shifting) | O(1) | O(1) | O(1) (pop/dequeue) | O(1) (pop/dequeue) |
| Insert at Tail / Rear (with tail ptr) | O(1) | O(1) | O(1) | O(1) | O(1) |
| Delete at Tail (with tail ptr) | O(1) | O(n) (predecessor search) | O(1) (via tail->prev) | O(1) | O(1) |
| Search (unsorted) | O(n) | O(n) | O(n) | N/A | N/A |
Pointer Golden Rule #1: Order of Updates
When inserting node newNode into any linked sequence, you must connect the new node to the downstream list FIRST:
// CORRECT: newNode->next = loc->next; loc->next = newNode; // WRONG (Cyclic leak): loc->next = newNode; newNode->next = loc->next; // makes newNode point to itself!
Pointer Golden Rule #2: Deletion Cleanup
Never delete a node before advancing your tracking pointers:
// CORRECT (Safe): Node* victim = head; head = head->next; delete victim; // WRONG (Dangling pointer / use-after-free): delete head; head = head->next; // Reading memory after release!