Min Value
Aug 27, 2021
Min Value algorithm finds the smallest value in the list. There are various methods to do this, and a few ways of finding the smallest element in the array is described here.
Find the min value in the array or slice #
Pseudocode for Min 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] Min = s[length - 1]
------ Execution ------ Slice (before): [3 1 4 2] Min Value = 1 Slice (after): [3 4 2 1]
Pseudocode for Min Value algorithm (save method)ITERATE over the list s SAVE s[0] as minVal IF minVal > s[i] THEN SAVE s[i] as a new minVal Min = minVal
------ Execution ------ Slice (before): [3 1 4 2] Min Value = 1 Slice (after): [3 1 4 2]