What would be the asymptotic time complexity to insert an element at the front of the linked list (head is known)?

Ngọc Trâm

New member
What would be the asymptotic time complexity to insert an element at the front of the linked list (head is known)?
A. O(1)
B. O(n)
C. O(n$^{2}$)
D. O(n$^{3}$)
 
Answer: A
Explanation: To add an element at the front of the linked list, we will create a new node which holds the data to be added to the linked list and pointer which points to head position in the linked list. The entire thing happens within O (1) time. Thus the asymptotic time complexity is O (1).
 

Tìm kiếm

Back
Top