Find average of array using only average of 2 members at a time
algorithm, average, c, java, recursion
Solution
Seems like you could use mergesort-esque logic here...
If you have cups 1,2,3,4,5,6,7,8...
First do equals(1,2), equals(3,4), equals(5,6), equals(7,8). At this point cups 1 & 2 have the same amount, cups 3 & 4 have the same amount and so on.
Next do equals(1,3), equals(2,4), equals(5,7), equals(6,8). Now cups 1,2,3,4 have the same amount, and cups 5,6,7,8 have the same amount.
Last do equals (1,5), equals(2,6), equals(3,7), equals(4,8). Note, you could also do equals(1,4), equals(1,5), etc because 1,2,3,4 all have the same amount. After this step, all cups have the same amount!
If you need help coding this in java, just ask.
Problem
You are given an array of 8 cups of water, each cup filled with a different amount of water you must get equal amounts of water in all cups, and can only use this function ``` public void equals(double[] arr, int i, int j) { arr[i] = arr[j] = (arr[i] + arr[j]) / 2; } ``` Perhaps recursively? Any ideas?