Standard Algorithms 3 & 4

So these two find the highest number in a list or the lowest number in a list.  The way they work is this:  look at the first item in the list and make it the maximum, then look at every other item and see if it is more.  Quite simple when you think of it like that.

Here is the pseudocode for finding max:

1.1  set the first item to be the maximum

 

1.2  for each item (starting with the second)

 

1.3  if the current item is more than the maximum

 

1.4  set the current item to be the maximum

 

1.5  end if

 

1.6  end loop

 

1.7 print out the maximum

 

 Finding the minimum is exactly the same only change more than to read less than (and every maximum to minimum).

 

Powerpoint:

 finding-max-min.jpg

 

 

 

 

Advertisements

Tags:

2 Responses to “Standard Algorithms 3 & 4”

  1. Abby Says:

    Please no more xmas music 😦
    so do standard algorithms 1 and 2 go together and 3 and 4 go together?

  2. mrwhiteside Says:

    Hi Abby, perhaps we can find some music to program to that everyone wants to hear but is not particularly christmassy? I will let you come up with some suggestions!

    I think algorithm 1 and 2 go together as the code is pretty much the same for each of them except that in conuting occurrences you keep a count and in linear search you store the position. 3 and 4 are obviously very similar in the way they work.

    All of these however, could come up in any form in the exam and are quite often changed to fit a random example. Hope this helps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: