Mean, Median, and Mode

Problem #2

Tags: statistics instructional

Who solved this?

Previous:Addition Next:Mean, Median, and Mode II


When starting to learn about Statistics, many begin with learning three core concepts: Mean, Median, and Mode.

The Mean of a set of values is the average value of the set. We can calculate this by adding up all the values in the set, then dividing by the quantity of values in the set. For example, the Mean of the set {4, -6, 8} is (-6 + 4 + 8) / 3 = 2.

The Median of a set of values is the middle value when the set is ordered. If there is an even quantity of values in the set, then the Median is the average of the two middle values. For example, the Median of the set {4, -6, 8} is 4, and the Median of the set {4, -6, 8, 8} is (4 + 8) / 2 = 6.

The Mode of a set is the value that appears the most frequently. If multiple values are "tied" for the most=frequent, all those tied are considered Modes of the set. For example, the Mode of the set {4, -6, 8, 8} is 8, and the Modes of the set {4, -6, 8} are -6, 4, and 8.

Given a set of data, you will be asked to calculate its Mean, Median, and Mode(s).

Problem Statement

Input Data
The first line will be Q the quantity of datapoints.
Q lines will then follow, each with an integer value corresponding to the value of a datapoint in the set.

Answer
Should consist of the Mean, the Median, and then any Modes.
If multiple modes exist, list them in ascending order.
All values should be separated by a single space.
Your answers should differ from the actual answers by no more than 0.000001.
You are allowed to provide more precision, if you wish.

Example

input data:
6
4
-3
1
4
7
-3

answer:
1.666667 2.5 -3 4

The above example dataset contains 6 values: 4, -3, 1, 4, 7, and -3.
The mean value is 1.666667, the median value is 2.5, and the two values which appear the most are -3 and 4.

You need to login to get test data and submit solution.