The cost table, and what generics buy you here
Every structure in this module is a generic class: Stack<T>, Queue<T>, LinkedList<T>. The type parameter T means one class definition works for a stack of numbers, a stack of strings, or a stack of a project's own Order type — and the compiler still knows exactly what .pop() returns for each one, instead of everything being any. At runtime none of this exists: generics are erased along with every other type annotation, so a Stack<number> and a Stack<string> are the identical JavaScript class once compiled.
You should see
7 seven
42 hiBox<T> method map<U>(fn: (value: T) => U): Box<U> that returns a new box holding the transformed value. Notice the method introduces its own type parameter, separate from the class's.| Structure | Access | Search | Insert | Delete |
|---|---|---|---|---|
Array<T> | O(1) | O(n) | O(1) at end / O(n) at front | O(1) at end / O(n) at front |
Stack<T> | O(1) top only | O(n) | O(1) | O(1) |
Queue<T> | O(1) front only | O(n) | O(1) | O(1) |
LinkedList<T> | O(n) | O(n) | O(1) at a known node | O(1) at a known node |
Map<K, V> / Set<T> | — | O(1) average | O(1) average | O(1) average |
BinarySearchTree<T> | — | O(log n) balanced, O(n) worst | O(log n) balanced | O(log n) balanced |
MinHeap<T> (priority queue) | O(1) minimum only | O(n) | O(log n) | O(log n) |
| Graph (adjacency list) | — | O(V + E) with BFS/DFS | O(1) add an edge | O(E) remove an edge |
Ts to prove it is not hard-coded to one type, then asks one interview question tied to that structure. All sixty interview questions for the exam are collected in Module 15; these are just the ones the structure itself explains best.