edited by
3,544 views
1 votes
1 votes

You're entrusted with the task of deleting a node in a singly linkedlist, whose data field is 'x'. Note that, the node which is to be deleted can be at any arbitrary position in the linked list. Consider the following scenarios.

S1.  You're only provided with a pointer to the node which is to be deleted in the linked list.

S2. You're only provided with a pointer to the starling node of the linked list.

Which of the following options is correct? 

 How deletion possible with S2? 

edited by

1 Answer

0 votes
0 votes
The problem will arise only when you are given a pointer to the last node and you have to delete that node in that case you first have to find the address of the second last node by traversing the whole list. In all the other cases, deletion can be done in O(1) time.

Related questions

1 votes
1 votes
1 answer
1
Pradip Nichite asked Jan 22, 2016
695 views
Here, what will be the Head->Next , I am confused is it first element 50 or second element 29.
0 votes
0 votes
2 answers
2
Sandeep Singh asked Dec 27, 2015
583 views
Delete the duplicate nodeDelete the alternate duplicate nodeDelete the adjacent nodeNone of these