Correct But Too Loose

A pull request description says: "binarySearch runs in O(n)O(n)." A reviewer replies: "That is wrong, it is O(log⁡n)O(\log n)." Who is right?

A

Neither. The right statement is Θ(n)\Theta(n) for the indexing plus Θ(log⁡n)\Theta(\log n) for the comparisons.

B

Both statements are true. OO is an upper bound and log⁡n≤n\log n \le n, so O(n)O(n) holds; the reviewer's is the tighter one and the one worth writing down.

C

The reviewer. An algorithm has exactly one big-O class, so naming a different one is an error.

D

The author. O(n)O(n) is right because binary search can inspect up to nn elements when the array has duplicates.