Practice mode Data Structures

What is the time complexity of searching for a value in an unsorted array of n elements?

Correct answer D. O(n)

Explanation

Without any order to exploit, the only safe method is to examine elements one by one, and in the worst case the value is last or absent, requiring n comparisons. That is linear time, O(n). O(log n) needs a sorted array so binary search can discard half the range at each step; O(1) applies to index access, not to searching by value.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.