1.

What would be the asymptotic time complexity to insert an element at the second position in the linked list?(a) O(1)(b) O(n)(c) O(n^2)(d) O(n^3)My question is based upon Singly Linked List Operations topic in division Abstract Data Types of Data Structures & Algorithms IThis question was addressed to me in class test.

Answer»

Right OPTION is (a) O(1)

For explanation: A new node is created with the required ELEMENT. The pointer of the new node points the node to which the HEAD node of the linked list is also pointing. The head node pointer is changed and it points to the new node which we created earlier. The ENTIRE process completes in O (1) time. Thus the asymptotic time complexity to insert an element in the second position of the linked list is O (1).



Discussion

No Comment Found

Related InterviewSolutions