All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · December 2018

Consider a singly linked list. What is the worst case time complexity of the best-known algorithm to delete the node a, pointer to this node is q, from the list?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: B. O(n)

Explanation

Copying the next node's data into q and unlinking the next node is O(1), but it fails when q is the last node; then the predecessor must be found by traversal, so the worst case is O(n).

More Data Structures and Algorithms questions