1,290 views
1 1 vote

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 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
Position:
Show:

Related questions

1 1 vote
1 1 answer
787
787 views
srestha asked Aug 4, 2016
787 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)
0 0 votes
0 0 answers
541
541 views
srestha asked Jan 11, 2017
541 views
1)Consider the AVL tree with n nodes. The best upper bound on the time required to insert n more elements in given AVL tree is O(na logb n). Then the value of a + 50b is ...