13,457 views
4 votes
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

12 votes
12 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
3 votes
3 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 votes
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:

Related questions

6 votes
6 votes
3 answers
1
sh!va asked May 7, 2017
10,480 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...
4 votes
4 votes
3 answers
2
sh!va asked May 7, 2017
10,623 views
Advantage of synchronous sequential circuits over asynchronous one is :Lower hardware requirementBetter noise immunityFaster operationAll of the above
9 votes
9 votes
3 answers
3
sh!va asked May 7, 2017
12,992 views
Choose the equivalent prefix form of the following expression(a+(b-c))*((d-e)/(f+g-h))*+a-bc/-de-+fgh*+a-bc-/de-+fgh*+a-bc/-ed-+fgh*+ab-c/-de-+fgh
6 votes
6 votes
1 answer
4
sh!va asked May 7, 2017
18,574 views
The best data structure to check whether an arithmetic expression has balanced parenthesis is a:QueueStackTreeList