The Gateway to Computer Science Excellence
0 votes

I was referring to this question :

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

in Programming by | 62 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
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).
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
Oh yes I forgot about a pointer already being available. You're right.

But is that what inverting is?
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
52,345 questions
60,522 answers
95,372 users