Max Value
Aug 27, 2021
Max Value algorithm finds the biggest value in the list. There are various methods to do this, and a few ways of finding the biggest element in the array is described here.
Find the max value in the array or slice #
Pseudocode for Max Value algorithm (bubble method)ITERATE over the list s UNTIL s[length - 1] IF s[i] > s[i+1] THEN swap s[i] with s[i+1] Max = s[length - 1]
------ Execution ------ Slice (before): [3 1 4 2] Max Value = 4 Slice (after): [1 3 2 4]
Pseudocode for Max Value algorithm (save method)ITERATE over the list s SAVE s[0] as maxVal IF maxVal < s[i] THEN SAVE s[i] as a new maxVal Max = maxVal
------ Execution ------ Slice (before): [3 1 4 2] Max Value = 4 Slice (after): [3 1 4 2]