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?
- A. 3
- B. 2
- C. 0
- 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
- Records with a name and a score are stored in an array and sorted with a comparator that compares the names with strcmp. Which field…
- Sorting 2 x 10^6 structs with qsort in C takes about how many comparisons?
- A list of records must be kept sorted while new records arrive one at a time. Which structure gives the best total cost for 10^5 inserts…
- Which sort is stable and runs in O(n log n) worst case, suitable for struct arrays that must keep equal-key order?
- How many records remain after a struct array of 7 records is filtered to drop those with a key equal to the previous key, when the array…
- Rotating the 2 x 2 matrix [[1, 2], [3, 4]] by 90 degrees counter-clockwise gives which first row?