Answers 100% Correct A+ Graded
What is a node? - Answer- A building block of a linked list that contains data and a link
(pointer to next node).
What two fields are inside a node? - Answer- Data and link (pointer to next node).
What does the head pointer store? - Answer- The address of the first node in the linked
list.
What does head_ptr == nullptr mean? - Answer- The linked list is empty.
What is a cursor pointer? - Answer- A temporary pointer used to walk through the list
without losing head_ptr.
What is the traversal pattern for linked lists? - Answer- node* cursor = head_ptr;
while(cursor != nullptr) { cursor = cursor->link; }
Why do we use cursor instead of head_ptr? - Answer- Moving head_ptr would lose
access to the start of the list.
What is the runtime of traversing a linked list? - Answer- O(n), as you must visit every
node.
What does list_length() do? - Answer- Counts the number of nodes in a linked list.
What is the runtime of list_length? - Answer- O(n).
What are the steps for inserting at head? - Answer- 1. Create node 2. Set data 3. Link to
old head 4. Move head pointer.
What is the insert head pointer pattern? - Answer- new_node->link = head_ptr; head_ptr
= new_node.
What is the runtime of inserting at head? - Answer- O(1), constant time.
What pointers are needed to insert in the middle? - Answer- Previous and current.
What is the insert after pointer pattern? - Answer- new_node->link = previous->link;
previous->link = new_node.
What are the steps to delete the head node? - Answer- 1. Save head 2. Move head
forward 3. Delete old node.