5.6k views

In a doubly linked list the number of pointers affected for an insertion operation will be

1. 4
2. 0
3. 1
4. Depends on the nodes of doubly linked list
in DS | 5.6k views
0
Is option A correct??
+4
According to me (D) should be the correct ans. Bcz it is not given that where are we going to insert the node in linked list. If we insert in middle then only 4 pointers will be affected.
+1
Ya agreed ,option D is most likely to be correct
+1
@Arjun Sir,

Is the given option d is correct?

I mean it depends on the nodes of doubly linked list or the location we are inserting.a node.
+1
yes, I do not know what the question setter meant.
0

sir, Do we need to consider "Depends on the nodes of doubly linked list" same as "Depends on the NUMBER OF nodes of doubly linked list" ....

0
It should be " depend on position of  node( where to insert) ".

case 1: If insertion in beginning (assume starting node's pointer name is start)

newnode->next=start;

newnode->prev=null;

start->prev=newnode;

start=newnode;

total change 4

case 2:insertion in middle(assume after some node x)

newnode->next=x->next;

newnode->prev=x;

x->next->prev=newnode;

x->next=newnode;

total change 4

case 3: insertion at the end (end node be x)

newnode->next=null;

newnode->prev=x;

x->next=newnode

total change 3
by Active (4.1k points)
option D will be more correct because they are not giving number of nodes in doubly linked list.

Since if Number of nodes in DLL is more than 2 nodes and if we want to insert node in begining of DLL then it may affect 3 pointers.

if th number of nodes in DLL is one , then it mayaffect 2 pointers.

So ultimately it depends on number of nodes in DLL.........
by Boss (41.9k points)
+2
@akash
yes it is D which is correct option .

In this question , nothing is mention where to insert so it depends on the nodes of doubly linked list .. the node where to insert .

hence D is the only correct option :)
+4
I do not think the question has any meaning :O
0
Sir why do you think the question doesn't contain any meaning.

Answer should be 'D' until they tell it explicitly where we are inserting.
0
If the number of nodes in DLL is one , then it may affect 3 pointers- (I)- Next pointer of old node. (II)- Prev pointer of new node. (III)- Next pointer of new node- It will point to Null.

Suggest me where am I wrong.
Option D..It depends whether to insert at 1st,middle or at last.
by Active (2.7k points)
 For insertions in the middle of the list, to splice in a new node as follows: A --- B ^^ splice M in here A.next = M M.prev = A B.prev = M M.next = B  Hence four pointer assignments take place. However, if the insertion be at the head or tail, then only two pointer assignments would be needed: TAIL (insert M afterward) TAIL.next = M M.prev = TAIL

Ans: D

by Loyal (7.2k points)