WBJECA 2025 Computer PYQ — What is the best case time complexity of deleting a node in a Sin… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
WBJECA 2025 — Computer PYQ
WBJECA | Computer | 2025
What is the best case time complexity of deleting a node in a Singly Linked List?
Choose the correct answer:
A.
O(n)
B.
O(logn)
C.
O(nlogn)
D.
O(1)
(Correct Answer)
Correct Answer:
O(1)
Explanation
Correct Option: (D) O(1)
Explanation
In a singly linked list, the time complexity of deleting a node depends on which node is being deleted.
Best Case (O(1)): The best case occurs when you want to delete the head node of the linked list. Since you already have a direct pointer (or reference) to the head of the list, you can simply update the head pointer to point to the second node in the list:
Headnew=Headold→next
This operation takes constant time, as no traversal is required.
Worst Case (O(n)): The worst case occurs when you need to delete a node at the end of the list or a specific node by its value. Because a singly linked list only has forward pointers, you must traverse the list from the beginning to find the node and its previous node, leading to a linear time complexity:
Time≈O(n)
Explanation
Correct Option: (D) O(1)
Explanation
In a singly linked list, the time complexity of deleting a node depends on which node is being deleted.
Best Case (O(1)): The best case occurs when you want to delete the head node of the linked list. Since you already have a direct pointer (or reference) to the head of the list, you can simply update the head pointer to point to the second node in the list:
Headnew=Headold→next
This operation takes constant time, as no traversal is required.
Worst Case (O(n)): The worst case occurs when you need to delete a node at the end of the list or a specific node by its value. Because a singly linked list only has forward pointers, you must traverse the list from the beginning to find the node and its previous node, leading to a linear time complexity: