What does 'Delete Node at Beginning' mean in a linked list?
It means removing the first node of the linked list, so the second node becomes the new head.
Click to reveal answer
beginner
What happens to the head pointer when you delete the first node in a linked list?
The head pointer moves to the next node after the deleted node.
Click to reveal answer
beginner
Why do we need to check if the linked list is empty before deleting the first node?
Because if the list is empty (head is null), there is no node to delete, and trying to delete will cause errors.
Click to reveal answer
beginner
What is the time complexity of deleting the first node in a singly linked list?
O(1) because we only change the head pointer to the next node without traversing the list.
Click to reveal answer
beginner
Show the JavaScript code snippet to delete the first node of a singly linked list.
if (head !== null) {
head = head.next;
}
Click to reveal answer
What should you do first before deleting the first node in a linked list?
ATraverse to the last node
BReverse the list
CCreate a new node
DCheck if the list is empty
✗ Incorrect
Always check if the list is empty (head is null) before deleting to avoid errors.
After deleting the first node, what does the head pointer point to?
ANull always
BThe second node
CThe last node
DThe deleted node
✗ Incorrect
The head pointer moves to the second node, which becomes the new first node.
What is the time complexity of deleting the first node in a singly linked list?
AO(1)
BO(n)
CO(log n)
DO(n^2)
✗ Incorrect
Deleting the first node is O(1) because it only involves changing the head pointer.
If the linked list has only one node and you delete it, what will the head be?
APoint to the same node
BUndefined
CNull
DPoint to a new node
✗ Incorrect
After deleting the only node, the list becomes empty, so head is null.
Which of these is the correct JavaScript code to delete the first node?
Ahead = head.next;
Bhead.next = head;
Chead = null.next;
Dhead = head.prev;
✗ Incorrect
Assigning head to head.next removes the first node from the list.
Explain step-by-step how to delete the first node in a singly linked list.
Think about what happens to the head pointer.
You got /3 concepts.
Write a simple JavaScript function to delete the first node of a linked list and return the new head.
Focus on handling empty list and returning the updated head.
You got /3 concepts.
Practice
(1/5)
1. What happens to the head pointer when you delete the first node in a singly linked list?
easy
A. It moves to the next node in the list
B. It becomes null immediately
C. It points to the last node
D. It remains unchanged
Solution
Step 1: Understand the head pointer role
The head pointer points to the first node in the list.
Step 2: Effect of deleting the first node
Deleting the first node means the head must now point to the second node, which becomes the new first node.
Final Answer:
It moves to the next node in the list -> Option A
Quick Check:
Head points to next node after deletion [OK]
Hint: Head always moves to next node when deleting first [OK]
Common Mistakes:
Assuming head becomes null even if list has more nodes
Thinking head points to last node after deletion
Not updating head pointer at all
2. Which of the following is the correct syntax to delete the first node in a singly linked list in JavaScript?
easy
A. delete head;
B. head.next = head;
C. head = head.next;
D. head = null.next;
Solution
Step 1: Understand how to move head pointer
To delete the first node, assign head to head.next to skip the first node.
Step 2: Check each option
head = head.next; correctly assigns head to head.next. head.next = head; reverses pointers incorrectly. delete head; deletes the variable but not the node. head = null.next; is invalid syntax.
Final Answer:
head = head.next; -> Option C
Quick Check:
Assign head to head.next to delete first node [OK]
Hint: Use head = head.next to remove first node [OK]
Common Mistakes:
Using delete keyword incorrectly
Assigning head.next to head instead of head to head.next
Using invalid syntax like null.next
3. Consider the following linked list code in JavaScript:
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
let head = new Node(10);
head.next = new Node(20);
head.next.next = new Node(30);
// Delete first node
head = head.next;
// Print list
let current = head;
let result = [];
while(current) {
result.push(current.data);
current = current.next;
}
console.log(result);
What will be printed?
medium
A. []
B. [10, 20, 30]
C. [30]
D. [20, 30]
Solution
Step 1: Initial linked list nodes
The list has nodes with data 10 -> 20 -> 30.
Step 2: Deleting first node by head = head.next
Head moves from node 10 to node 20, so node 10 is removed.
Step 3: Printing remaining nodes
Starting from new head (20), the list is 20 -> 30, so result array is [20, 30].
Final Answer:
[20, 30] -> Option D
Quick Check:
After deletion, list starts at 20 [OK]
Hint: Deleting first node skips first data in output [OK]
Common Mistakes:
Printing original list without deletion
Confusing head.next with head
Forgetting to update head pointer
4. The following code attempts to delete the first node of a linked list but causes an error:
head.next = head.next.next;
What is the problem with this code if head points to the first node?
medium
A. It deletes the second node instead of the first node
B. It causes a runtime error if head.next is null
C. It correctly deletes the first node
D. It sets head to null incorrectly
Solution
Step 1: Analyze what head.next = head.next.next does
This changes the next pointer of the first node to skip the second node, effectively deleting the second node.
Step 2: Check if first node is deleted
The head pointer still points to the first node, so the first node is not deleted.
Final Answer:
It deletes the second node instead of the first node -> Option A
Quick Check:
head.next changes second node, not head itself [OK]
Hint: Changing head.next skips second node, not first [OK]
Common Mistakes:
Thinking this deletes the first node
Ignoring possible null pointer if list has one node
Confusing head and head.next pointers
5. You have a singly linked list with nodes: 5 -> 10 -> 15 -> 20. Write a function in JavaScript to delete the first node and return the new head. What will be the list after deletion?
hard
A. 20
B. 10 -> 15 -> 20
C. 15 -> 20
D. 5 -> 10 -> 15 -> 20
Solution
Step 1: Write function to delete first node
Function returns head.next to skip first node: function deleteFirstNode(head) { return head ? head.next : null; }
Step 2: Apply function to list 5 -> 10 -> 15 -> 20
New head points to node with data 10, so list becomes 10 -> 15 -> 20.
Final Answer:
10 -> 15 -> 20 -> Option B
Quick Check:
Deleting first node moves head to second node [OK]
Hint: Return head.next to delete first node [OK]
Common Mistakes:
Returning head instead of head.next
Not handling empty list (null head)
Deleting wrong node by changing next pointers incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.