Recall & Review
beginner
What does the 'push' operation do in a linked list?
It adds a new node at the beginning (head) of the linked list, making it the new first element.
Click to reveal answer
beginner
In C, what is the typical structure used to represent a node in a singly linked list?
A struct with at least two members: one for data (e.g., int data) and one pointer to the next node (e.g., struct Node* next).
Click to reveal answer
intermediate
Why do we pass the head pointer by reference (pointer to pointer) when pushing a new node in C?
Because the head pointer itself may change to point to the new node, so we need to modify the original pointer outside the function.
Click to reveal answer
beginner
What is the time complexity of the push operation in a singly linked list?
O(1) — It takes constant time because we only change a few pointers without traversing the list.
Click to reveal answer
beginner
Show the basic steps to push a new node with value 'x' onto a linked list in C.
1. Create a new node using malloc.
2. Set new node's data to x.
3. Set new node's next to current head.
4. Update head to new node.
Click to reveal answer
What pointer type should be passed to a push function to update the head of a linked list in C?
✗ Incorrect
To update the head pointer itself, the function needs a pointer to the head pointer, which is Node**.
What happens to the old head node when a new node is pushed onto the linked list?
✗ Incorrect
The old head node is linked after the new node, becoming the second node.
Which of these is NOT a step in pushing a node onto a linked list?
✗ Incorrect
The new node's next should point to the old head, not always NULL.
What is the output linked list after pushing nodes with values 3, then 5, then 7 onto an empty list?
✗ Incorrect
Each new node is added at the front, so the last pushed (7) is the head.
What is the time complexity of pushing a node onto a singly linked list?
✗ Incorrect
Push operation takes constant time because it only changes pointers at the head.
Explain how the push operation works in a singly linked list using a linked list node in C.
Think about how the new node becomes the first element.
You got /4 concepts.
Describe why the head pointer must be passed as a pointer to pointer when implementing push in C.
Consider how C passes arguments by value.
You got /3 concepts.
