Give a recursive algorithm for finding a mode of a list of integers. (A mode is an element in the list that occurs at least as often as every other element.)
The recursive algorithm is,
The objective is to write the recursive algorithm for finding a mode of a list of integers.
Call the algorithm "mod" and the input is a list of integers.
When the list contains only 1 integer, then the mode is the remaining integer.
If the list contains more than 1 value, then check, if the last value in the list is repeated somewhere in the list. Remove this value along with all other repetitions of the value form the list, while represents the number of values that were deleted. If , then all elements in the list were deleted and therefore, there should be return of . Otherwise, apply the algorithm to determine the mode of the reduced list,
which occurs times. If k > m , then is the mode. If k < m, then the mode is the mode of the reduced list.else
By combining all the steps, the required algorithm will be as follows.
Therefore, the recursive algorithm is shown above.
Suppose you begin with a pile of n stones and split this pile into n piles of one stone each by successively splitting a pile of stones into two smaller piles. Each time you split a pile of stones into two smaller piles. Each time you split a pile you multiply the number of stones in each of the two smaller piles you form, so that if piles have r and s stones in them, respectively, you compute rs. Show that no matter how you split the piles, the sum of the products computed at each step equals .
94% of StudySmarter users get better grades.Sign up for free