retagged by
21,021 views
1 votes
1 votes
What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?
(a) O(1)      

(b) O(n)

(c) θ (n)

(d) θ (1)

 

Confused between option (b) and (c) .
retagged by

1 Answer

Best answer
4 votes
4 votes
option (c) because in the best case you will have to traverse the entire linked list  and in the worst case you will have to traverse the entire linked list to reach at the last node and adding the new element in constant time so theta(n) is best option.
selected by

Related questions

5 votes
5 votes
1 answer
2
hacker16 asked Nov 14, 2017
3,458 views
What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?O(n)O(1)θ(n2)θ...