Log In
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 71 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

Related questions

0 votes
1 answer
The answer is 'd' will be printed. Can someone draw the linked list after the operations are performed. I think the second operation of the code doesn't bring in any change to the list. thanks in advance
asked Aug 23, 2018 in Programming Kalpataru Bose 113 views
0 votes
2 answers
What is the time complexity to insert a new Node in a singly circular linked list at Starting ? (Number of nodes in list = N) A. O(1) B. O(N)
asked Dec 10, 2017 in Programming Mr_22B 510 views
1 vote
1 answer
I am not getting that when head pointer has no information regarding the tail pointer then how is it that circular linked list will have a constant time for its concatenation with another circular linked list , wouldn't it take same time if we perform concatenation on a single or double linked list .
asked Jul 22, 2015 in Programming radha gogia 1k views
0 votes
2 answers
If I have two lists of length 2 then no of comparisons in the worst case would be 2 only , since If I have say 10,20 in list A and 5,7 in list B so then on merging 10 is compared with 5 then 20 is compared with 7 so finally in 2 comparisons I have merged both the lists , so then how to calculate the average no of comparisons here ?
asked Aug 1, 2015 in Algorithms radha gogia 5.9k views