Open zhughes3 opened 7 years ago
Check out the output:
[ 21, 63, 48, 20, 31, 85, 86, 80, 86, 96, ] Max: 86, min: 20, comparisons: 9, 3n/2=15 [ 6, 15, 67, 70, 24, 60, 97, 69, 86, 98, ] Max: 97, min: 69, comparisons: 7, 3n/2=15 [ 26, 59, 9, 44, 20, 22, 34, 22, 95, 78, ] Max: 95, min: 22, comparisons: 9, 3n/2=15 [ 34, 10, 38, 42, 35, 21, 99, 79, 59, 97, ] Max: 99, min: 10, comparisons: 11, 3n/2=15 [ 5, 45, 14, 34, 57, 1, 4, 17, 33, 56, ] Max: 57, min: 1, comparisons: 7, 3n/2=15 [ 64, 73, 1, 81, 9, 13, 44, 78, 96, 39, ] Max: 96, min: 39, comparisons: 7, 3n/2=15 [ 32, 65, 35, 15, 49, 26, 49, 13, 64, 62, ] Max: 64, min: 13, comparisons: 13, 3n/2=15 [ 51, 54, 19, 58, 87, 50, 18, 18, 7, 70, ] Max: 87, min: 50, comparisons: 7, 3n/2=15 [ 97, 37, 96, 56, 21, 45, 45, 63, 78, 65, ] Max: 97, min: 37, comparisons: 11, 3n/2=15 [ 8, 39, 5, 60, 97, 26, 16, 66, 71, 1, ] Max: 97, min: 1, comparisons: 9, 3n/2=15
I think the problem has to do with whether the size of the array is even or odd. According to this, they have to be initialized differently http://www.geeksforgeeks.org/maximum-and-minimum-in-an-array/
Check out the output:
[ 21, 63, 48, 20, 31, 85, 86, 80, 86, 96, ] Max: 86, min: 20, comparisons: 9, 3n/2=15 [ 6, 15, 67, 70, 24, 60, 97, 69, 86, 98, ] Max: 97, min: 69, comparisons: 7, 3n/2=15 [ 26, 59, 9, 44, 20, 22, 34, 22, 95, 78, ] Max: 95, min: 22, comparisons: 9, 3n/2=15 [ 34, 10, 38, 42, 35, 21, 99, 79, 59, 97, ] Max: 99, min: 10, comparisons: 11, 3n/2=15 [ 5, 45, 14, 34, 57, 1, 4, 17, 33, 56, ] Max: 57, min: 1, comparisons: 7, 3n/2=15 [ 64, 73, 1, 81, 9, 13, 44, 78, 96, 39, ] Max: 96, min: 39, comparisons: 7, 3n/2=15 [ 32, 65, 35, 15, 49, 26, 49, 13, 64, 62, ] Max: 64, min: 13, comparisons: 13, 3n/2=15 [ 51, 54, 19, 58, 87, 50, 18, 18, 7, 70, ] Max: 87, min: 50, comparisons: 7, 3n/2=15 [ 97, 37, 96, 56, 21, 45, 45, 63, 78, 65, ] Max: 97, min: 37, comparisons: 11, 3n/2=15 [ 8, 39, 5, 60, 97, 26, 16, 66, 71, 1, ] Max: 97, min: 1, comparisons: 9, 3n/2=15