Consider a single linked list where F and L are pointers to the first and last…

2014

Consider a single linked list where F and L are pointers to the first and last elements respectively of the linked list. The time for performing which of the given operations depends on the length of the linked list?

F->1->2->3->L

  1. A.

    Delete the first element of the list

  2. B.

    Interchange the first two elements of the list

  3. C.

    Delete the last element of the list

  4. D.

    Add an element at the end of the list

Attempted by 442 students.

Show answer & explanation

Correct answer: C

Deleting the last element in a singly linked list requires traversing from the head to find the second-to-last node. This traversal depends on the list length (O(n)). Other operations like deleting from the front or adding to the end use pointers directly and are O(1).

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro