What is the time complexity for inserting an element at the beginning of a singly linked list?

  • O(1)
  • O(log n)
  • O(n)
  • O(n^2)
The time complexity for inserting an element at the beginning of a singly linked list is O(1) or constant time. This is because only the head pointer needs to be updated to point to the new node, and the new node points to the current head. No traversal of the entire list is required.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *