What is the main purpose of traversing a linked list?
To visit each node in the linked list one by one, usually to read or process the data stored in each node.
Click to reveal answer
beginner
In a singly linked list, how do you move from one node to the next?
By following the 'next' pointer/reference in the current node to reach the next node.
Click to reveal answer
beginner
What condition tells you that you have reached the end of a linked list during traversal?
When the current node's 'next' pointer is null, it means there are no more nodes to visit.
Click to reveal answer
beginner
Why is it important to start traversal from the head node of a linked list?
Because the head node is the entry point to the list; without it, you cannot access the rest of the nodes.
Click to reveal answer
beginner
What is the output format when printing a linked list like 1 -> 2 -> 3 -> null?
It shows the sequence of node values connected by arrows, ending with 'null' to indicate the list's end.
Click to reveal answer
What does the 'next' pointer in a linked list node represent?
AThe address of the next node in the list
BThe data stored in the node
CThe previous node in the list
DThe size of the list
✗ Incorrect
The 'next' pointer holds the reference to the next node, allowing traversal through the list.
When traversing a linked list, which node do you start from?
AThe tail node
BThe middle node
CThe head node
DAny random node
✗ Incorrect
Traversal always starts from the head node because it is the first node in the list.
How do you know you have reached the end of a singly linked list?
AWhen the current node's next pointer is null
BWhen the current node's data is null
CWhen the list size is zero
DWhen the current node points to the head
✗ Incorrect
The end of the list is indicated by a null 'next' pointer in the last node.
What will be printed for an empty linked list?
A0
BError
CEmpty
Dnull
✗ Incorrect
An empty linked list is represented by 'null' since there are no nodes to print.
Which of these is the correct way to print a linked list with nodes 1, 2, 3?
A[1, 2, 3]
B1 -> 2 -> 3 -> null
C1, 2, 3
D1 2 3
✗ Incorrect
The arrow notation shows the links between nodes and ends with 'null' to indicate the list end.
Explain step-by-step how to traverse and print all elements of a singly linked list.
Think about how you move from one node to the next and when to stop.
You got /5 concepts.
Describe what happens if you try to traverse a linked list starting from a node other than the head.
Consider the linked list as a chain starting at the head.
You got /4 concepts.
Practice
(1/5)
1. What does traversing a linked list mean in simple terms?
easy
A. Reversing the order of nodes
B. Visiting each node one by one from start to end
C. Deleting the first node
D. Adding a new node at the end
Solution
Step 1: Understand traversal
Traversal means going through each node in the linked list starting from the first node.
Step 2: Identify what happens during traversal
We visit each node one by one until we reach the end (null).
Final Answer:
Visiting each node one by one from start to end -> Option B
Quick Check:
Traversal = Visit nodes sequentially [OK]
Hint: Traversal means visiting nodes one after another [OK]
Common Mistakes:
Confusing traversal with adding or deleting nodes
Thinking traversal changes the list order
Assuming traversal skips nodes
2. Which of the following is the correct C# syntax to start traversing a singly linked list named head?
easy
A. Node current => head;
B. Node current == head;
C. Node current = head;
D. Node current <- head;
Solution
Step 1: Check variable assignment syntax in C#
In C#, to assign a value, use a single equals sign (=), not double (==) or arrows.
Step 2: Identify correct assignment for traversal start
We assign the head node to a variable to start traversal: Node current = head;
Final Answer:
Node current = head; -> Option C
Quick Check:
Assignment uses =, not == or arrows [OK]
Hint: Use single = for assignment in C# [OK]
Common Mistakes:
Using == instead of = for assignment
Using arrow symbols which are invalid
Confusing assignment with comparison
3. What will be the output of the following C# code snippet?
class Node {
public int data;
public Node next;
public Node(int d) { data = d; next = null; }
}
Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
Node current = head;
while (current != null) {
Console.Write(current.data + " -> ");
current = current.next;
}
Console.WriteLine("null");
medium
A. 1 -> 2 -> 3 -> null
B. null -> 1 -> 2 -> 3
C. 3 -> 2 -> 1 -> null
D. 1 2 3 null
Solution
Step 1: Understand the linked list structure
The list has nodes with data 1, 2, and 3 linked in order.
Step 2: Trace the while loop output
The loop prints each node's data followed by ' -> ', then moves to next node until null.
Final Answer:
1 -> 2 -> 3 -> null -> Option A
Quick Check:
Print nodes in order with arrows and end with null [OK]
Hint: Print nodes in order, end with null [OK]
Common Mistakes:
Printing nodes in reverse order
Missing arrows or null in output
Printing null at start instead of end
4. Identify the error in this linked list traversal code snippet:
Node current = head;
while (current.next != null) {
Console.Write(current.data + " -> ");
current = current.next;
}
Console.WriteLine("null");
medium
A. It prints nodes in reverse order
B. It causes a null reference exception
C. It never enters the loop
D. It skips printing the last node's data
Solution
Step 1: Analyze the loop condition
The loop runs while current.next is not null, so it stops before the last node.
Step 2: Check what gets printed
Since the last node's data is printed only inside the loop, it is skipped.
Final Answer:
It skips printing the last node's data -> Option D
Quick Check:
Loop condition excludes last node [OK]
Hint: Use current != null to include last node [OK]
Common Mistakes:
Using current.next != null instead of current != null
Assuming last node prints automatically
Confusing loop condition with node data access
5. Given a singly linked list, how would you modify the traversal code to print the list in reverse order without changing the list structure?
hard
A. Use recursion to print nodes after recursive call returns
B. Traverse normally and print nodes immediately
C. Reverse the list first then print
D. Use a for loop with index to print backwards
Solution
Step 1: Understand the problem constraints
We cannot change the list structure, so reversing the list is not allowed.
Step 2: Use recursion to print in reverse
Recursion visits nodes forward, then prints after returning, effectively printing backwards.
Final Answer:
Use recursion to print nodes after recursive call returns -> Option A
Quick Check:
Recursion prints in reverse without modifying list [OK]
Hint: Recursion prints reverse by printing after calls return [OK]
Common Mistakes:
Trying to use index-based loops on linked list
Reversing list which changes structure
Printing nodes immediately during traversal
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.