A singly linked list is a chain of nodes where each node holds data and a link to the next node. It starts at a head node and ends when a node points to null.
Click to reveal answer
beginner
What does each node in a singly linked list contain?
Each node contains two parts: the data (value) and a reference (pointer) to the next node in the list.
Click to reveal answer
intermediate
How do you add a new node at the end of a singly linked list?
To add a node at the end, create the new node, then find the last node (which points to null), and update its next pointer to the new node.
Click to reveal answer
beginner
Why does a singly linked list have a head pointer?
The head pointer keeps track of the first node in the list. Without it, you cannot access the list because nodes only link forward.
Click to reveal answer
beginner
What happens if you try to traverse a singly linked list starting from a null head?
If the head is null, it means the list is empty, so there are no nodes to visit or print.
Click to reveal answer
What does the 'next' pointer in a singly linked list node point to?
AThe head node
BThe next node in the list
CThe previous node in the list
DThe last node in the list
✗ Incorrect
In a singly linked list, each node points only to the next node, not the previous one.
What is the first step to create a singly linked list from scratch?
ADefine a node class with data and next pointer
BCreate a head pointer pointing to null
CAdd nodes to the list
DTraverse the list
✗ Incorrect
You start by defining the node structure that holds data and a pointer to the next node.
If a singly linked list has only one node, what does its next pointer hold?
ANull
BReference to itself
CReference to head
DReference to the second node
✗ Incorrect
The next pointer of the last node in the list is null, indicating the end of the list.
How do you know when you have reached the end of a singly linked list during traversal?
AWhen the current node's data is null
BWhen the current node points to the head
CWhen the head pointer is null
DWhen the current node's next pointer is null
✗ Incorrect
Traversal ends when the next pointer of the current node is null, meaning no more nodes.
Which of these is NOT true about singly linked lists?
AThey use a head pointer to start traversal
BThey allow easy insertion at the beginning
CThey have pointers to both next and previous nodes
DThey can be empty if head is null
✗ Incorrect
Singly linked lists only have a pointer to the next node, not the previous one.
Explain how to create a singly linked list from scratch and add nodes to it.
Think about how each node connects to the next and how the list starts.
You got /5 concepts.
Describe how to traverse a singly linked list and print all its elements.
Imagine walking through a chain, stopping at each link to look at it.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a Singly Linked List in data structures?
easy
A. To store elements in a linear order where each element points to the next
B. To store elements in a tree-like hierarchical structure
C. To store elements with direct access by index like an array
D. To store elements in a key-value pair format
Solution
Step 1: Understand the structure of a singly linked list
A singly linked list stores elements in nodes where each node points to the next node, forming a chain.
Step 2: Compare with other data structures
Unlike trees or arrays, singly linked lists do not have hierarchical or direct index access but maintain a linear sequence through pointers.
Final Answer:
To store elements in a linear order where each element points to the next -> Option A
Quick Check:
Singly Linked List = linear chain of nodes [OK]
Hint: Remember: singly linked list nodes point only forward [OK]
Common Mistakes:
Confusing linked lists with arrays having direct index access
Thinking linked lists store key-value pairs
Assuming linked lists have hierarchical structure like trees
2. Which of the following is the correct way to declare a node class for a singly linked list in C#?
easy
A. public class Node { public int data; public Node previous; }
B. public class Node { int data; int next; }
C. public class Node { public int data; public int next; }
D. public class Node { public int data; public Node next; }
Solution
Step 1: Identify the correct node structure for singly linked list
A node must store data and a reference to the next node, so the next pointer type should be Node.
Step 2: Check each option's correctness
public class Node { public int data; public Node next; } correctly declares data as int and next as Node. Options B and C incorrectly use int for next. public class Node { public int data; public Node previous; } uses previous which is for doubly linked lists.
Final Answer:
public class Node { public int data; public Node next; } -> Option D
Quick Check:
Node next pointer type = Node [OK]
Hint: Next pointer must be Node type, not int [OK]
Common Mistakes:
Using int type for next pointer instead of Node
Confusing singly linked list with doubly linked list (previous pointer)
Omitting access modifiers making members inaccessible
3. What will be the output of the following C# code that creates a singly linked list with nodes 10, 20, 30 and prints the list?
public class Node {
public int data;
public Node next;
public Node(int d) { data = d; next = null; }
}
public class LinkedList {
public Node head;
public void Add(int data) {
Node newNode = new Node(data);
if (head == null) {
head = newNode;
} else {
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = newNode;
}
}
public void PrintList() {
Node temp = head;
while (temp != null) {
Console.Write(temp.data + " -> ");
temp = temp.next;
}
Console.WriteLine("null");
}
}
class Program {
static void Main() {
LinkedList list = new LinkedList();
list.Add(10);
list.Add(20);
list.Add(30);
list.PrintList();
}
}
medium
A. null
B. 10 -> 20 -> 30 -> null
C. 10 -> 20 -> null
D. 30 -> 20 -> 10 -> null
Solution
Step 1: Trace the Add method calls
Adding 10 sets head to node with data 10. Adding 20 appends node with data 20 at end. Adding 30 appends node with data 30 at end.
Step 2: Trace the PrintList method
PrintList starts at head and prints each node's data followed by ' -> ' until null is reached, printing "10 -> 20 -> 30 -> null".
Final Answer:
10 -> 20 -> 30 -> null -> Option B
Quick Check:
Nodes added in order = printed in order [OK]
Hint: Add appends at end; print shows nodes in insertion order [OK]
Common Mistakes:
Assuming Add inserts at head instead of tail
Forgetting to print 'null' at end
Printing nodes in reverse order
4. Identify the error in the following C# code snippet for adding a node to a singly linked list:
public void Add(int data) {
Node newNode = new Node(data);
if (head == null) {
head = newNode;
} else {
Node temp = head;
while (temp != null) {
temp = temp.next;
}
temp.next = newNode;
}
}
medium
A. The while loop condition should be 'temp.next != null' instead of 'temp != null'
B. The newNode should be created outside the method
C. The head should be set to null inside the else block
D. The method should return the newNode
Solution
Step 1: Analyze the while loop condition
The loop currently runs while temp != null, so it stops when temp is null, meaning temp.next is not accessible.
Step 2: Correct the loop to stop at last node
The loop should run while temp.next != null to stop at the last node, so we can set temp.next = newNode safely.
Final Answer:
The while loop condition should be 'temp.next != null' instead of 'temp != null' -> Option A
Quick Check:
Traverse until last node (temp.next != null) [OK]
Hint: Loop until temp.next is null to find last node [OK]
Common Mistakes:
Looping until temp is null causes null reference error
Trying to assign next on null reference
Misplacing node creation outside method
5. You want to create a method Reverse() in your singly linked list class that reverses the list in place. Which approach correctly reverses the list?
hard
A. Swap data values between head and tail nodes repeatedly until the middle is reached.
B. Create a new list and copy nodes from the original list in reverse order.
C. Iterate through the list, for each node set its next pointer to the previous node, updating previous and current pointers until the end.
D. Set head to null and re-add nodes in reverse order using Add method.
Solution
Step 1: Understand in-place reversal logic
Reversing a singly linked list in place requires changing each node's next pointer to point to the previous node, not creating new nodes or swapping data.
Step 2: Evaluate options for correctness
Iterating through the list, for each node setting its next pointer to the previous node while updating previous and current pointers until the end correctly describes the standard in-place reversal. The other options involve extra memory or inefficient operations.
Final Answer:
Iterate through the list, for each node set its next pointer to the previous node, updating previous and current pointers until the end. -> Option C
Quick Check:
Reverse by redirecting next pointers in place [OK]
Hint: Reverse by changing next pointers, not data or new nodes [OK]
Common Mistakes:
Creating new lists instead of reversing in place
Swapping data instead of pointers
Resetting head to null losing the list
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.