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

Discussion

_________ comparisons are necessary in the worst case to find both the maximum and minimum of n numbers.

  • A.\(2n - 2\)
  • B.\(n + \text{floor}(\lg n) - 2\)
  • C.\(\text{floor}\left(\dfrac{3n}{2}\right) - 2\)
  • D.\(2 \lg n - 2\)

Answer: C

The number of comparisons needed in the worst case to find both the maximum and the minimum of n numbers is about \(\lceil 3n/2 \rceil - 2\), and option C is the closest listed form. Pair the elements, compare each pair (n/2 comparisons), then find the maximum among the winners and the minimum among the losers (about n/2 - 1 each).

\(2n - 2\) is what the naive method needs, \(n + \lfloor \lg n \rfloor - 2\) is the bound for finding the two largest elements, and \(2 \lg n - 2\) is too small to be possible.

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

Post your comment

Please log in or register to post a comment.