Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider an unordered list of \(N\) distinct integers.

What is the minimum number of element comparisons required to find an integer in the list that is NOT the largest in the list?

  • A.1
  • B.\(N - 1\)
  • C.\(N\)
  • D.\(2N - 1\)

Answer: A

One comparison is enough: 1.

Pick any two elements and compare them. Since all elements are distinct, one is strictly smaller than the other, and the smaller one cannot be the largest element of the list. So it is an answer, found with a single comparison. Zero comparisons cannot work, because without comparing anything no element is known not to be the maximum.

N - 1 is the number of comparisons needed to find the largest element itself, which the question does not ask for. N and 2N - 1 are more than even that.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.