The Gateway to Computer Science Excellence
0 votes
52 views

I was referring to this question :

https://gateoverflow.in/132053/self-doubt-in-linked-list

Although I agree with option A (deletion) being better that singly linked list, but what about C (inverting a node)? 

in Programming by Active (3.3k points) | 52 views

1 Answer

0 votes
considering that invert means interchanging two nodes

in both singly and doubly we use temp node to perform so basically its the same

difference comes in the way we reach that location

in singly wehave to traverse from the begining

and in doubly can be traversed backwards

therefore i feel in this case too doubly is more efficient

correct me if i am wrong
by Boss (10.2k points)
0
I'm really not sure what the statement means in the first place. Because invert generally means just changing the direction of the list.

If we consider your understanding of the statement then yes, both will be the same. And even Doubly will have to traverse to that location. Doubly, like singly has head at the beginning, right? So it just can't start traversing from backwards (can happen if it is circular).
0
but suppose u have used a pointer and traversed for some purpose to the far end of the list and the location to be inverted is near from  the last  then doubly can just traverse backwards while singly has to still move from the beginning

i think this was the logic behind doubly being more efficient in deleting node at a given location than singly linked list

thats what i understood
0
Oh yes I forgot about a pointer already being available. You're right.

But is that what inverting is?
0
am not sure .......what that means

but if assumed as interchanging ,my explanation would match
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,644 questions
56,507 answers
195,558 comments
101,061 users