In: Computer Science
The mode of a set of numbers is the number that occurs most frequently in the set. For example, the set {4, 3, 6, 4, 3, 4, 1} has mode 4.
(a) (10%) Give an efficient, in-place algorithm to compute the mode of a set. Give the running time of your algorithm as a function of number of elements in the set, n. Show all work!
(b) (10%) Now suppose we know that there exists an element that occurs at least (n/2) + 1 times in the set, where n is the number of elements in the set. Give an O(n) algorithm to find the mode of this set.