19,321 views
4 4 votes

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

4 Answers

16 16 votes
Answer D)

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
5 5 votes
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.........
0 0 votes
 

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

Answer:
Position:
Show:

Related questions

8 8 votes
4 4 answers
16.1k
16.1k views
sh!va asked May 7, 2017
16,051 views
Given two statementsInsertion of an element should be done at the last node of the circular listDeletion of an element should be done at the last node of the circular lis...
8 8 votes
1 answers 1 answer
7.4k
7.4k views
sh!va asked May 7, 2017
7,382 views
Estimation at software development effort for organic software in basic COCOMO is:E = 2.0 (KLOC) 1.05 PME = 3.4 (KLOC) 1.06 PME = 2.4 (KLOC) 1.05 PME = 2.4 (KLOC) 1.07...
5 5 votes
3 3 answers
14.4k
14.4k views
sh!va asked May 7, 2017
14,375 views
Advantage of synchronous sequential circuits over asynchronous one is :Lower hardware requirementBetter noise immunityFaster operationAll of the above
9 9 votes
5 answers 5 answers
8.9k
8.9k views
go_editor asked Sep 28, 2014
8,859 views
In the context of modular software design, which one of the following combinations is desirable?High cohesion and high couplingHigh cohesion and low couplingLow cohesion ...