789 views
1 votes
1 votes

An array of size n. Find the time complexity to insert a new value before an element e in the array?

a)O(n)

b)O(log n)

c)O(1)

d)O(n^2)

2 Answers

Best answer
5 votes
5 votes
Since array may be unsorted here finding perticular elemnt itself take O(n) time . but array property is continuous  memory allotment means no gap present between so to insert ans element may require shifting of n-1 element . so total O(n) +O(n)= O(n)
selected by

Related questions

1 votes
1 votes
1 answer
1
srestha asked Aug 4, 2016
469 views
Consider a stack is implemented using an array. What is the worst case time complexity of push operation?(A) O(N)(B) O(log N)(C) O(N log N)(D) O(1)