Computer Science, asked by ne7elimasomy, 1 year ago

Choose the Correct Option Related to Singly Linked List
You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list? (A) Delete the first element (B) Insert a new element as a first element (C) Delete the last element of the list (D) Add a new element at the end of the list.

Answers

Answered by kvnmurty
2
C and D.

In a singly linked list there is only a forward link from the first element to 2nd element and then from there to 3rd element and so on.  So First element is accessed directly and so independent of the length.

C)  So in order to access the last element, the n-1 nodes are to be traversed.   This is dependent on the length.

D. In order to add an element at the end of a list, the last node of the list is to be accessed so that the new node could be attached to it.

Similar questions