help me
i have hw , so i would like to get some sot of ideas
the hw is
Develop an a lgorithm for finding the median of a list of numbers using the couting method
123456789
4325618107
for this algorithm, assue that the numbers in the list are uniqe(no duplicates) and that the length of the list is an odd number. the median is the number such that half of the numbers in the list are below the median and half of the numbers in the list above the median number. for a list of unique numbers where the length of the list is an odd number there is exactly one such number.
[600 byte] By [
aljabria] at [2007-11-27 2:43:14]

# 3
uhm... If you graduated highschool/ever went to school. You'd know how to hand find a median... The method is to first SORT the set. Then, eliminate one component off each side of the array until you're left with 1 or a central 2 to average.
example (this is not code so dont copy paste like a robot!):
array = 6,3,4,1,2,5,7
sorted_array = 1,2,3,4,5,6,7
loop
{
step 1: eliminated_array = 2,3,4,5,6,7
step 2: eliminated_array = 2,3,4,5,6
step 3: eliminated_array = 3,4,5,6
step 4: eliminated_array = 3,4,5
step 5: eliminated_array = 4,5
step 6: eliminated_array = 4
CHECK: cannot eliminate 2 more without having set size of zero! exit loop...
}
if array.length = 1 then that is the median
if array.length = 2 then median is their avg
if anything else then your computer is broken!
-> this case will return 4.
good luck!
Message was edited by:
ArikArikArik