Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best-known algorithm to delete the node x form the list?
A
O(logn)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
O(n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
O(1)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
O(log2n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is BO(n)
To delete node x, we should find out the previous node to the x. To find the previous nodes to the x will take O(n).
Therefore it takes O(n).