657 views
0 votes
0 votes
Given a  pointer to a node to be deleted what is the time complexity to delete a node in the circular linked list :

i think answer is O(1).

Am i right?

1 Answer

0 votes
0 votes
If only a pointer to that node is given:

1. Single Circular Linked list: You have to traverse the whole list and come back to that node(so as to link previous and next node of the node to be deleted). So, in that case, O(n).

2. Doubly circular Linked list: Just link the next of previous node with the next node of the node to be deleted, and also link the previous node of the next node with node before the node to be deleted. This will take O(1).

P.S. The comments give the same answer too.

Related questions

0 votes
0 votes
1 answer
1
Hirak asked Jun 2, 2019
1,217 views
#include<iostream using namespace std; int i=0; void a() { i+=1; cout<<i<< ".hello"<<endl; a(); } int main() { a(); }For this above code the output is only upto → 6489...
0 votes
0 votes
0 answers
2
Raj Kumar 7 asked Jul 17, 2018
625 views
The number of different directed trees with 3 nodes areA) 3B) 4C) 5D) 6I think the answer is 5 but the answer is not.
0 votes
0 votes
2 answers
3
vijju532 asked Jul 5, 2018
729 views
i am getting 4,3,4,3,8,2 is it right?????
0 votes
0 votes
0 answers
4
gateexplore asked Oct 25, 2023
129 views
It is always true that Recursive code is easier to debug?? If yes then why?? please give full explanation.