With regard to linked list, which of the following statements is false?

2009

With regard to linked list, which of the following statements is false?

Answer: B. An algorithm for deleting the first element in a singly linked list requires O(n) operations in the worst case.A linked-list operation's cost depends on how the target node is reached. Unless a direct pointer to a node is already provided, standard complexity analysis…

  1. A.

    An algorithm to search for an element in a singly linked list requires O(n) operations in the worst case.

  2. B.

    An algorithm for deleting the first element in a singly linked list requires O(n) operations in the worst case.

  3. C.

    An algorithm for finding the maximum value in a circular linked list requires O(n) operations.

  4. D.

    An algorithm for deleting the middle node of a circular linked list requires O(n) operations.

Attempted by 104 students.

Show answer & explanation

Correct answer: B

A linked-list operation's cost depends on how the target node is reached. Unless a direct pointer to a node is already provided, standard complexity analysis assumes only a fixed entry reference is available for each list variant: the head pointer for a singly linked list, or any chosen node for a circular linked list. If the target node coincides with this entry reference, the operation touches a fixed number of nodes and completes in O(1) time. If the target node must instead be located by following links from that entry reference, the operation must visit nodes one by one, giving O(n) time in the worst case.

Applying this to each statement:

  1. Search in a singly linked list: the target may be anywhere, or absent, so every node up to the match, or all n nodes if it is absent, must be visited, giving O(n) and matching the statement.

  2. Deleting the first element of a singly linked list: the head pointer already references this node directly, so the operation is just re-pointing head to head.next and releasing the old node, a fixed number of steps, i.e. O(1), not the O(n) the statement claims.

  3. Finding the maximum value in a circular linked list: there is no way to know the maximum without comparing every value, so the traversal must cover all n nodes once around the ring, giving O(n) and matching the statement.

  4. Deleting the middle node of a circular linked list: the middle node is not reachable by any fixed pointer, so it must first be located by walking from a reference point, visiting on the order of n nodes, before it can be unlinked, giving O(n) overall and matching the statement.

Cross-check: three of the four statements (search, find-maximum, delete-middle) correctly describe operations that need a full or partial traversal and are genuinely O(n). Only the delete-first-element statement mismatches its own operation's actual cost, since accessing the first node needs no traversal at all.

Result: the false statement is "An algorithm for deleting the first element in a singly linked list requires O(n) operations in the worst case": this operation is O(1), not O(n).

Explore the full course: Coding For Placement

Loading lesson…