ProgrammingHard
A hash chain delete on a singly linked bucket list is written with a pointer-to-pointer. Which description is the advantage?
- A. It makes deletion O(1) without any search
- B. It removes all matches in one step
- C. It removes the first match whether it is the head or not, with one code path and no special case
- D. It avoids the need for malloc on insertion
Correct answer: C. It removes the first match whether it is the head or not, with one code path and no special case
Walking with a pointer to the link you may change handles both the head and inner nodes with the same statement. It still searches the chain, so deletion is O(length).
More C Programming questions
- Building a list from n values by inserting each new node at the head is O(1) per insert. What is the order of the values when read from…
- Which C statement is correct for a node with an int field v and a next pointer, allocated and initialised to v = 7 with no next node?
- A doubly linked list stores prev pointers. How many pointer fields must change to insert a new node between two adjacent nodes A and B?
- A singly linked list of N = 10^6 nodes must answer 10^6 queries for the value at position k. Which approach is correct and fast enough?
- A function frees an entire list and then sets head = NULL. Why is setting head to NULL useful?
- Which kind of list makes it O(1) to delete a node given only a pointer to that node?