What is the time complexity of inserting a new node at the head of a singly linked list?
- A O(1)
- B O(n)
- C O(log n)
- D O(n^2)
Explanation
Inserting at the head only requires updating the new node's pointer and the head pointer, so it takes O(1) time.
What is the time complexity of inserting a new node at the head of a singly linked list?
Inserting at the head only requires updating the new node's pointer and the head pointer, so it takes O(1) time.