A linked list is a chain of boxes where each box holds some data and a pointer to the next box. It helps store items in order without needing all boxes to be next to each other.
Click to reveal answer
beginner
Why do we use linked lists instead of arrays sometimes?
Linked lists let us add or remove items anywhere easily without moving other items. Arrays need shifting items, which can be slow.
Click to reveal answer
intermediate
What problem does a linked list solve that arrays struggle with?
Linked lists solve the problem of fixed size and costly insertions/deletions in arrays by allowing flexible size and quick changes anywhere in the list.
Click to reveal answer
beginner
How does a linked list store data differently from an array?
An array stores data in continuous memory spots, while a linked list stores data in separate spots connected by pointers.
Click to reveal answer
beginner
What is a real-life example to understand linked lists?
Think of a treasure hunt where each clue points to the next location. Each clue is like a node pointing to the next, just like a linked list.
Click to reveal answer
What is the main advantage of a linked list over an array?
AFaster access to elements by index
BStores data in continuous memory
CUses less memory always
DEasy insertion and deletion anywhere
✗ Incorrect
Linked lists allow easy insertion and deletion anywhere without shifting elements, unlike arrays.
Which of these is true about linked lists?
AEach element points to the next element
BThey do not use pointers
CThey have fixed size like arrays
DThey store elements in continuous memory
✗ Incorrect
Each node in a linked list contains data and a pointer to the next node.
Why might arrays be inefficient for frequent insertions?
ABecause elements need to be shifted
BBecause they are linked
CBecause they use pointers
DBecause they have no size limit
✗ Incorrect
In arrays, inserting elements in the middle requires shifting other elements, which is slow.
What problem does a linked list solve?
AHigh memory usage of arrays
BSlow access to elements by index
CFixed size and slow insert/delete in arrays
DLack of pointers in arrays
✗ Incorrect
Linked lists allow dynamic size and fast insertions/deletions, solving array limitations.
In a linked list, what does each node contain?
APointer only
BData and pointer to next node
CData only
DData and pointer to previous node only
✗ Incorrect
Each node stores data and a pointer to the next node in the list.
Explain why linked lists exist and what problem they solve compared to arrays.
Think about how adding or removing items works in arrays versus linked lists.
You got /4 concepts.
Describe how a linked list stores data differently from an array using a simple analogy.
Use a real-life example where each item points to the next.
You got /4 concepts.
Practice
(1/5)
1. Why do we use a linked list instead of an array in some cases?
easy
A. Because linked lists allow easy insertion and deletion without shifting elements
B. Because linked lists use less memory than arrays always
C. Because linked lists store elements in contiguous memory locations
D. Because linked lists are faster for accessing elements by index
Solution
Step 1: Understand array limitations
Arrays store elements in continuous memory, so inserting or deleting in the middle requires shifting many elements, which is slow.
Step 2: Understand linked list advantage
Linked lists store elements as nodes with pointers, so insertion or deletion only changes pointers without shifting elements.
Final Answer:
Because linked lists allow easy insertion and deletion without shifting elements -> Option A
Quick Check:
Linked list insertion/deletion = easy [OK]
Hint: Linked lists avoid shifting elements on insert/delete [OK]
Common Mistakes:
Thinking linked lists always use less memory
Believing linked lists store elements contiguously
Assuming linked lists have fast random access
2. Which of the following is the correct way to declare a node in a singly linked list in TypeScript?
Hint: Next pointer must allow null for last node [OK]
Common Mistakes:
Not allowing next to be null
Setting next to undefined instead of null
Using any type for next pointer
3. What will be the output of the following TypeScript code that uses a linked list?
class Node {
value: number;
next: Node | null;
constructor(value: number) {
this.value = value;
this.next = null;
}
}
const head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
let current = head;
const values: number[] = [];
while (current !== null) {
values.push(current.value);
current = current.next;
}
console.log(values);
medium
A. []
B. [3, 2, 1]
C. [1, 2]
D. [1, 2, 3]
Solution
Step 1: Build linked list nodes
Nodes created with values 1, 2, 3 linked in order: 1 -> 2 -> 3 -> null.
Step 2: Traverse linked list and collect values
Loop visits nodes in order: 1, then 2, then 3, pushing values into array.
Final Answer:
[1, 2, 3] -> Option D
Quick Check:
Traversal order = [1, 2, 3] [OK]
Hint: Traverse from head to null to get values in order [OK]
Common Mistakes:
Confusing order and reversing output
Stopping traversal too early
Not initializing next pointers correctly
4. The following TypeScript code tries to insert a new node with value 4 at the end of the linked list but has a bug. What is the bug?
class Node {
value: number;
next: Node | null;
constructor(value: number) {
this.value = value;
this.next = null;
}
}
const head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);
function insertAtEnd(head: Node, value: number) {
let current = head;
while (current.next !== null) {
current = current.next;
}
current = new Node(value);
}
insertAtEnd(head, 4);
let current = head;
const values: number[] = [];
while (current !== null) {
values.push(current.value);
current = current.next;
}
console.log(values);
medium
A. The function should return the new head node
B. The new node is not linked to the last node; assignment should be current.next = new Node(value)
C. The while loop condition should be current !== null
D. The new node value should be assigned before the loop
Solution
Step 1: Analyze insertion logic
The code moves current to last node, but then assigns current = new Node(value), which only changes local variable, not the list.
Step 2: Correct pointer assignment
To link new node, must assign current.next = new Node(value) so last node points to new node.
Final Answer:
The new node is not linked to the last node; assignment should be current.next = new Node(value) -> Option B
Quick Check:
Link new node with current.next = new Node(value) [OK]
Hint: Assign new node to current.next, not current [OK]
Common Mistakes:
Assigning new node to current variable only
Wrong loop condition causing null errors
Expecting function to return new head unnecessarily
5. You want to store a list of tasks where you often add or remove tasks from the middle. Which data structure is best and why?
A linked list or an array? Choose the best option.
hard
A. Array, because it uses less memory than linked lists
B. Array, because it allows fast random access to any task by index
C. Linked list, because it allows efficient insertion and deletion in the middle without shifting elements
D. Linked list, because it stores elements in contiguous memory for cache efficiency
Solution
Step 1: Understand operation needs
Adding/removing tasks often in the middle means many insertions and deletions not at the end.
Step 2: Compare array vs linked list for middle operations
Arrays require shifting elements on insert/delete in middle, which is slow. Linked lists only change pointers, so faster for these operations.
Final Answer:
Linked list, because it allows efficient insertion and deletion in the middle without shifting elements -> Option C
Quick Check:
Middle insert/delete = linked list best [OK]
Hint: For frequent middle changes, linked list is faster [OK]
Common Mistakes:
Choosing array for fast random access ignoring insert/delete cost
Thinking linked lists use less memory always
Believing linked lists store elements contiguously
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.