Linked structures
1.[2p] Why is indexing a singly linked list rather than ?
Why is indexing a singly linked list rather than ?
The answer is: The address of node is stored inside node , so it can only be found by following pointers
The answer is: The address of node is stored inside node , so it can only be found by following pointers
The answer is: The address of node is stored inside node , so it can only be found by following pointers
2.[2p] A structure holds 10,000 elements. Inserting at position 100, how many elements does a dynamic array have to shift?
A structure holds 10,000 elements. Inserting at position 100, how many elements does a dynamic array have to shift?
3.[2p] A singly linked list can delete a node in constant time given only a pointer to that node.
A singly linked list can delete a node in constant time given only a pointer to that node.
The answer is: False
4.[2p] A ring buffer has capacity 8, head at slot 6, and holds 5 elements. Which slot will the next enqueue write to?
A ring buffer has capacity 8, head at slot 6, and holds 5 elements. Which slot will the next enqueue write to?
5.[2p] Match each structure to the discipline it enforces.
Match each structure to the discipline it enforces.
Stack
Queue
Deque
last in, first out
insertion and removal at both ends
first in, first out
Show the answer
Stack: last in, first out Queue: first in, first out Deque: insertion and removal at both ends
6.[3p] Which are genuine reasons to choose a doubly linked list over a dynamic array?
Which are genuine reasons to choose a doubly linked list over a dynamic array?
Select all that apply
The answer is: Unlinking a node you already hold a reference to, in constant time, Splicing a whole sublist into another list in constant time, Needing a hard worst-case bound with no reallocation pause
7.[3p] Scanning a million 8-byte elements is roughly eight times faster in an array than in a linked list because
Scanning a million 8-byte elements is roughly eight times faster in an array than in a linked list because
The answer is: a 64-byte cache line delivers eight array elements per memory fetch, while scattered nodes need one fetch each
The answer is: a 64-byte cache line delivers eight array elements per memory fetch, while scattered nodes need one fetch each
The answer is: a 64-byte cache line delivers eight array elements per memory fetch, while scattered nodes need one fetch each
8.[2p] An LRU cache uses a doubly linked list rather than an array because
An LRU cache uses a doubly linked list rather than an array because
The answer is: a hash table hands it the node directly, and moving a held node to the front is then constant time
The answer is: a hash table hands it the node directly, and moving a held node to the front is then constant time
The answer is: a hash table hands it the node directly, and moving a held node to the front is then constant time
9.[2p] To find an element whose position is unknown, both an array and a linked list cost in the worst case.
To find an element whose position is unknown, both an array and a linked list cost in the worst case.
The answer is: True