AlgoScope

Insert at Position

Walk to the node before the gap, then relink it and the new node in order.

Linked list algorithms, algorithm, beginner
New node 9 created. Its next points to 4.51942headprev
New node 9 created. Its next points to 4.51942headprev

Singly Linked List: Insert at index 2

Step, step 3 of 5

Create 9 and point its next at 4 first, so nothing is lost.

How singly linked list works

Cost

Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(1)

Taught by the same lesson

Singly Linked List covers these too, in the same run.