HackerRank 10 days of statistics
: Day 1 note taking
Quartile(4๋ถ์์): The quartiles of an ordered data set at the 3 points that split the data set into 4 equal groups.
- the odd number of elements
|
median of lower half from median = first quartile |
|
median(์ค์๊ฐ) = second quartile = 50 percentile |
|
median of upper half median = third quartile |
|
- the even number of elements
|
|
|
|
|
|
|
|
|
|
|
average of these two elements = median = second quartile |
|
|
|
|
|
|
|
|
|
|
|
|
|
an average of these two elements = a median of the lower half of median = first quartile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
an average of these two elements = a median of the upper half of median = third quartile |
|
def median(arr): n = len(arr) if n%2==0: return (arr[int(n/2)-1]+arr[int(n/2)])//2 else: return arr[int(n/2)] def quartile(arr, N): first = median(arr[:N//2]) second = median(arr) if N%2 == 0: third = median(arr[N//2:]) else: third = median(arr[N//2+1:]) return first, second, third N = int(input()) arr = sorted(map(int,input().split())) Q1, Q2, Q3 = quartile(arr, N)
quartile |
|
Q1 |
Q1 >= 25% of the data |
Q2 |
Q2 >= 50% of the data |
Q3 |
Q3 >= 75% of the data |