Let's see, how it might work.

You just remember the largest value you have seen so far,

starting with the beginning of the list,

and then consider each subsequent number.

End of this figure,

you'd update the largest value so far.

For example, given the following list of numbers which are

the similarities from the working dog center,

you'd start by saying that the first,

52.3 is the largest seen so far, and remember it.

We'll call this the variable max, for short.

We're going to use the convention,

the black numbers represent those that remain to be looked

at and green represents the max.

Comparing max in green,

with the next number 81.2,

shown in red, you'd update the max to 81.2.

Since it is larger than the current largest of 52.3.

Comparing with the next 33.6,

you wouldn't update the max,

you'll stay with the current value of 81.

2. Note that we're graying out the values that have already been compared,

and keeping those that remained to be compared in black.

The same would happen for the next two numbers on the list,

17.3 and 25.1, since,

they are both smaller than the current max,

shown in green, which is 81.2.

However, the next number on the list,

90.4, is larger than 81.2.

So, 90.4, would become the max.

Comparing with the last two numbers 28.2 and 43.1,

would not change the max, since,

they are both smaller than 90.4.

We're done with the list,

there are no numbers remaining to be compared.

So, the final result is 90.4,

shown here in green.

Now, that we figured out,

how to find the max by comparing only two numbers,

how would we communicate that algorithm to someone else?

More specifically, how could we communicate it to a computer?

We will answer the second question later in the course,

but for now, let's just write it out in English.

At first, the max is the first value on the list.

Then we look at each value in the list.

If it is greater than the current max,

then that value becomes the max,

otherwise, the max remains the same.

After going through the entire list,

the current max, is the maximum of the value in the list.

We can express this,

using the following flowchart.

First, we get the input list.

If it is empty,

then there is no max value.

So, we output N/A,

for not appropriate, and we stop.

Otherwise, we read the first item in the list,

and store it as max.

We now enter a repeated behavior,

where we test an item against max,

and update max, depending on whether or not it is larger.

The first time the item is max, so,

the test fails, and we just read the next item in the list.

If a subsequent item is larger than the current max,

then we would also update max.

When there is no next item,

we output the max, and stop.

Otherwise, we continue through the list.

Now let's say we want to find the minimum value in a collection.

Well, the algorithm is almost the same.

Here's the algorithm, again expressed as a flowchart for finding the minimum value.

Note that the algorithm is almost the same,

except that we will remember the minimum found so far.

We will also check,

if each successive element is smaller than the current minimum.

Again, when we get to the end of the list,

we're done and output min.

In this lesson, we've looked at a common computational problem.

Finding the maximum or minimum value,

in a list or collection.

This often arises as a component of the larger problem.

Although, humans can look at a collection of

numbers and somehow process them all at once.

A computer can only perform operations that take two numbers at a time.

These are called binary operations.

So, we came up with a solution,

that the computer could use.

Remember the current largest value in the collection,

we call this max,

and compare against the next untested value.

The result is the value in max,

when all items in the collection have been tested.

We showed how this algorithm could be represented as

a flowchart and notice that a minor change to it,

remembering the smallest value seen so far,

instead of the largest,

could be used as a solution for finding the minimum value in a collection.

In the next lesson,

we'll look at another closely related and common problem,

searching a collection for a value.

Previously, we talked about,

how pattern recognition is one of the pillars of computational thinking.

Finding the maximum value,

has the same pattern as finding the minimum value,

it is just slightly different.

It doesn't matter, whether we're comparing numbers, or words,

or even dogs, the algorithm to find the maximum element is the same.

This is important in computational thinking, and in programming.

You'll be able to solve lots of problems using similar algorithms,

once you're able to recognize the patterns.