1.

In special case, the time complexity of inserting/deleting elements at the end of dynamic array is __________(a) O (n)(b) O (n^1/2)(c) O (log n)(d) O (1)Question is taken from Dynamic Array topic in division Arrays Types of Data Structures & Algorithms II have been asked this question during an interview.

Answer»

Correct CHOICE is (a) O (n)

To explain: In general, the time complexity of INSERTING or deleting elements at the end of dynamic array is O (1). Elements are added at reserved space of dynamic array. If this reserved space is EXCEEDED, then the physical size of the dynamic array is reallocated and every element is copied from ORIGINAL array. This will take O(n) time to add NEW element at the end of the array.



Discussion

No Comment Found

Related InterviewSolutions