zhughes3 / algorithms

Creating a library of generic data structures and algorithms learned during Spring 2017's "Algorithms & Analysis" class at UNC-CH.
1 stars 0 forks source link

minMax function in Selection isn't working #1

Open zhughes3 opened 7 years ago

zhughes3 commented 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

zhughes3 commented 7 years ago

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/