ProgrammingHard

In the keys 3, 1, 3, 2, 1, the mode (most frequent key) is needed. With ties, the smallest key wins. Which is the mode?

  1. A. 3
  2. B. 2
  3. C. 0
  4. D. 1

Correct answer: D. 1

Count each key: 1 appears twice, 3 appears twice and 2 once. The tie between 1 and 3 goes to the smaller key, so the mode is 1; 3 is the tempting answer if you take the first key to reach a count of two.

More C Programming questions

Exams that ask this topic