ISRO Scientist/Engineer CSE 2018Data Structures › Linked Lists
ISRO Scientist/Engineer CSE 2018 PYQ: Consider a singly linked list of the form where $F$ is a pointer to the first element in the linked list and…
Consider a singly linked list of the form where $F$ is a pointer to the first element in the linked list and $L$ is the pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
- ADelete the last element of the listCorrect answer
- BDelete the first element of the list
- CAdd an element after the last element of the list
- DInterchange the first two elements of the list
Answer
(A) Delete the last element of the list
Approach
We have a singly linked list with pointers F (first) and L (last). For each operation, determine whether it requires traversing the list, which would make its time complexity depend on the list length n. Only operations that need to access a node other than the first or last (without a direct pointer) will be O(n).
Reviewed by ISRO IQ Editorial Team.