- Arrays: length/capacity, declaring, the GameEntry/Scoreboard example.
- Adding an entry at index i shifts n − i elements forward; removing shifts them back.
🎯 How this can come up · 1 question
Inserting at index 0 of an array holding n elements costs:
Correct: O(n).
- Singly linked list: nodes with element + next; head (and tail) references.
- Insert at head: new node → newest.next = head → head = newest. O(1).
Asked in a real exam
🎯 How this can come up · 1 question
Correct code to insert node N at the head of a doubly linked list:
Quiz 1.
- Insert at tail: O(1) with a tail reference.
- Remove at head: head = head.next. O(1). Remove at tail of a SINGLY linked list is NOT O(1): you must walk to the node before the tail.
Asked in a real exam
🎯 How this can come up · 1 question
Which singly-linked-list operation takes O(n) even with a tail pointer?
Correct: Removing the last node.
- Doubly linked list: prev and next; header and trailer sentinels simplify the edge cases.
- Insert between p and its successor: link the new node both ways (4 pointer updates). Delete p: p.prev.next = p.next; p.next.prev = p.prev.
Asked in a real exam
🎯 How this can come up · 2 questions
To unlink node X between Before and After in a DLL:
Quiz 1.
A doubly linked list beats a singly linked list for:
Quiz 1.
- Array list (java.util.List): get, set, add(i, e), remove(i); add/remove at i shift elements → O(n).
- Growable array: when full, copy into a bigger array.
- Incremental strategy (+c each time): n pushes cost O(n²) → amortized O(n) per push. Doubling: O(n) total → amortized O(1).
🎯 How this can come up · 1 question
With the doubling strategy, the amortized cost of a push is:
Correct: O(1).
- Positional list ADT: positions stay valid while other elements change.
- Iterator: hasNext(), next(). Iterable: iterator(). for-each uses them.
No slides match this filter.