Find Min - Parallel Arrays

Purpose

The purpose of the Find Minimum algorithm are to look through a list of items and find the minimum value or position. It uses a variable to hold the current minimum value or position.

If a value is found that is lower than the current lowest value or position, then that new item is set to the new lowest value or position. The course covers using this algorithm on parallel arrays and also records.

Find Min Pseudocode (Minimum Value)

Lowest = array[0]

FOR counter FROM 1 to length(array)

IF array[counter] < lowest

SET Lowest = array [counter]

END IF

END FOR

You will notice that we iterate from the second item in the list (index 1) as we have already used element 0 to initialise the Lowest variable.

Find Min  (Minimum Value) Parallel Arrays- Python

In this example we have initialised the minimum value as the first item in the array. 

We only overwrite this value if we find a new item that is smaller.

You will notice that we iterate from the second item in the list (index 1) as we have already used element 0 to initialise the minimum variable.

Find Min Pseudocode (Position)

Sometimes (particularly when writing functions) it is useful to store the position of the smallest value as opposed to the value itself. That way regardless of if we are using parallel arrays or records we can use it to then retrieve other pieces of data.

Parallel Arrays

minpos = 0

FOR counter FROM 1 to length(array)

IF array[counter] < array[minpos] 

minpos = counter

END IF

END FOR

You will notice that we iterate from the second item in the list (index 1) as we have already used element 0 to initialise the minpos variable.

Find Min  (Minimum Position) Parallel Arrays- Python

This time we have set the minposition as 0 in the variable minpos then only overwrite it with the counter variable when we find a new smaller value.  You will notice that we iterate from the second item in the list (index 1) as we have already used element 0 to initialise the minpos variable.

This is then returned and can be used outside of the function to find other associated values (in other arrays/records)

Find Max Pseudocode with Extra Criteria

Sometimes it will not be possible to set your minimum value as the first item or position as there may be extra criteria. For example you may be looking for the smallest mark from a pupil who is in S1. But what if we look at the data we may see that the first item doesn't fit the criteria we are looking for.

For example in the data below if we initialise our minimum position as 0 it will be initialise the minimum value for an S1 as 45 but that values belongs to an S4 pupil. 

If we used the value 50 as our minimum mark for an S1 pupil it will never find the correct initial value of 45.

Find Min/Max Tutorial Video

4 - Find MinMax.mp4