+1 vote
in Data Structures & Algorithms I by (110k points)
What is the worst case time complexity of inserting an element into the sorted array?

(a) O(nlogn)

(b) O(logn)

(c) O(n)

(d) O(n^2)

My question is based upon Parallel Array in chapter Arrays Types of Data Structures & Algorithms I

The question was posed to me in an interview.

1 Answer

+1 vote
by (408k points)
selected by
Best answer
Right option is (c) O(n)

The explanation is: In the worst case, an element must added to the front of the array, which means that rest of the elements have to be shifted, hence the worst case time complexity becomes O(n).

Related questions

Welcome to TalkJarvis QnA, a question-answer community website for the people by the people. On TalkJarvis QnA you can ask your doubts, curiosity, questions and whatever going in your mind either related to studies or others. Experts and people from different fields will answer.