513 views
0 votes
0 votes

Please explain how to approach this problem?

2 Answers

1 votes
1 votes

Thus inserting when only 1 node is present is best case while when there are n nodes then to connect last pointer to start of new node we need time O(n) hence average case is $\Theta(n)$

1 votes
1 votes

If you have pointer to the first node

Insertion at beginning: O(n)

Insertion at the end: O(n) // As you have to traverse till the end. 

If you have pointer to the last node

Insertion at beginning: O(1)

Insertion at end: O(1)

In GATE question they will most likely clearly mention to which nodes we have the pointer to. 

Check this: https://gateoverflow.in/1033/gate2004-36

edited by

Related questions

0 votes
0 votes
2 answers
1
3 votes
3 votes
1 answer
2
hacker16 asked Nov 14, 2017
21,372 views
In circular singly linked list, insertion of node requires modification of how many pointers?1 pointers2 pointers3 pointers 4 pointers
1 votes
1 votes
0 answers
3
Parshu gate asked Nov 6, 2017
468 views