Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Insert at Linked List Head Lab
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
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 1.0x