Lesson 2 of 3
Trade-offs that decide which to reach for.
Arrays give O(1) random access but O(n) inserts in the middle. Linked lists flip that.
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
const head = new Node(1);
head.next = new Node(2);Choose based on whether you index more, or insert/remove more.