A singly linked list is a chain of nodes where each node holds data and a reference 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 pointer (reference) 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 is a singly linked list different from an array?
A singly linked list stores elements in nodes connected by pointers, allowing easy insertion and deletion without shifting elements, unlike arrays which store elements in contiguous memory.
Click to reveal answer
intermediate
What is the time complexity to access the nth element in a singly linked list?
Accessing the nth element requires traversing from the head node through n nodes, so the time complexity is O(n).
Click to reveal answer
What does the 'next' pointer in a singly linked list node point to?
AThe next node in the list
BThe previous node in the list
CThe head node
DThe last node in the list
✗ Incorrect
In a singly linked list, each node's 'next' pointer points to the next node in the sequence.
What value does the 'next' pointer of the last node in a singly linked list hold?
AIt points to a random node
BIt points to itself
CIt points to the head node
DIt is null (or None)
✗ Incorrect
The last node's 'next' pointer is null, indicating the end of the list.
Which operation is easiest to perform in a singly linked list compared to an array?
AInserting a node at the beginning
BAccessing the middle element
CAccessing an element by index
DSorting the elements
✗ Incorrect
Inserting at the beginning is easy because you just change the head pointer to the new node.
What is the first step to create a singly linked list from scratch?
ACreate an array to hold nodes
BSort the data
CDefine a node structure with data and next pointer
DInitialize the tail pointer
✗ Incorrect
You start by defining the node structure that holds data and a pointer to the next node.
If you want to traverse a singly linked list, where do you start?
AFrom the middle node
BFrom the head node
CFrom the tail node
DFrom any random node
✗ Incorrect
Traversal always starts from the head node and moves through each next pointer.
Explain how to create a singly linked list from scratch and add a node to it.
Think about how nodes connect and how the head pointer changes.
You got /5 concepts.
Describe the difference between a singly linked list and an array in terms of memory and operations.
Consider how data is stored and accessed in both.
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 sequence where each element points to the next one
B. To store elements with keys and values for fast lookup
C. To store elements in a sorted array for quick access
D. To store elements in a tree-like hierarchy
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 in the sequence.
Step 2: Compare with other data structures
Unlike key-value stores or trees, singly linked lists maintain a simple linear chain of elements.
Final Answer:
To store elements in a sequence where each element points to the next one -> Option A
Quick Check:
Singly Linked List = sequence with next pointers [OK]
Hint: Remember: singly linked list nodes point only forward [OK]
Common Mistakes:
Confusing linked lists with arrays
Thinking linked lists store key-value pairs
Assuming linked lists are hierarchical like trees
2. Which of the following is the correct TypeScript syntax to define a node class for a singly linked list?
Hint: Append adds at end; print shows sequence [OK]
Common Mistakes:
Assuming append adds at head instead of tail
Forgetting to add 'null' at the end
Printing values in reverse order
4. Identify the error in this TypeScript code snippet that tries to append a node to a singly linked list:
class Node {
value: number;
next: Node | null;
constructor(value: number) {
this.value = value;
this.next = null;
}
}
class LinkedList {
head: Node | null = null;
append(value: number) {
const newNode = new Node(value);
if (this.head === null) {
this.head = newNode;
} else {
let current = this.head;
while (current.next !== null) {
current = current.next;
}
current.next = newNode;
}
}
}
const list = new LinkedList();
list.append(5);
list.append(10);
console.log(list.head.next.value);
medium
A. Error: head is undefined
B. Error: Cannot read property 'value' of null
C. No error; output will be 10
D. Error: next property is missing in Node
Solution
Step 1: Check append logic
The append method correctly adds the first node as head and subsequent nodes at the end.
Step 2: Verify output of console.log
After appending 5 and 10, head.next points to the node with value 10, so accessing value is valid.
Final Answer:
No error; output will be 10 -> Option C
Quick Check:
Proper append and access = 10 [OK]
Hint: Check if head and next are properly assigned before access [OK]
Common Mistakes:
Forgetting to return after setting head in append
Accessing next.value when next is null
Not initializing next to null in Node
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 links between nodes?
hard
A. Create a new list and append nodes from the original list in reverse order
B. Iterate through the list, for each node set its next to the previous node, updating previous and current pointers
C. Swap the values of the first and last nodes repeatedly until the middle is reached
D. Remove all nodes and re-insert them at the head one by one
Solution
Step 1: Understand in-place reversal
Reversing links means changing each node's next pointer to point to the previous node, not creating new nodes.
Step 2: Identify correct method
Iterating with previous and current pointers and updating next links reverses the list efficiently in place.
Final Answer:
Iterate through the list, for each node set its next to the previous node, updating previous and current pointers -> Option B
Quick Check:
In-place reversal = update next pointers backward [OK]
Hint: Reverse by redirecting next pointers, not swapping values [OK]
Common Mistakes:
Swapping node values instead of links
Creating a new list instead of reversing in place
Removing and re-adding nodes unnecessarily
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.