ProgrammingModerate

In a singly linked list, which operation takes O(1) time when a pointer to the head is given?

  1. A. Insert a new node after the last node
  2. B. Insert a new node at the head
  3. C. Find the length of the list
  4. D. Remove the last node

Correct answer: B. Insert a new node at the head

Only the head pointer needs to change, so insertion at the head is constant time. The other operations walk the list.

More C Programming questions

Exams that ask this topic