Linked Lists

Problem shape

Beginner
7
->
11
->
18
->
24
Core idea

Point the new node to the old head, then move head to the new node.

Step 1 / 5
Problem shape
Current lesson

Insert at Linked List Head Lab

Linked Lists Beginner

Insert at Linked List Head

Welcome to the Insert at Linked List Head algorithm lab. Point the new node to the old head, then move head to the new node. Use it when: Use for fast front insertion. The time complexity is O(1), and the space complexity is O(1). The pseudocode is: newNode.next = head head = newNode return head As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(1)

Space

O(1)

Pseudocode

newNode.next = head
head = newNode
return head
Open deeper structure lesson
1.0x