Reductions on arrays

Getting the max and min

Getting the max and min

Reduction algorithm:

+ Take array. If array is length 0 throw problem

+ If array is length 1 return element

+ If array is length 2 do pairwise comparison on the pair (eg return bigger of two for max)

+ If array is length greater than 2, recursively call reduction on reduction of first two elements and the rest of the array.

Examples of reductions that can be done include:

+ Min

+ Max

+ Sum

+ Count if

+ Sum if