840 views
0 0 votes

Please explain how to approach this problem?

2 Answers

1 1 vote

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 1 vote

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
Position:
Show:

Related questions

0 0 votes
2 2 answers
2.3k
2.3k views
4 4 votes
1 answers 1 answer
24.5k
24.5k views
hacker16 asked Nov 14, 2017
24,460 views
In circular singly linked list, insertion of node requires modification of how many pointers?1 pointers2 pointers3 pointers 4 pointers
1 1 vote
0 0 answers
839
839 views
Parshu gate asked Nov 6, 2017
839 views
0 0 votes
4 4 answers
3.0k
3.0k views
Kapil asked Feb 3, 2017
2,993 views
struct node{ int num; struct node *next; } void print(struct node *ptr) { if(ptr) { printf("%d",ptr->data); do{ printf("%d",ptr->data); } while(ptr->next); } }What is the...