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:
December 7, 2007 at 10:08 am |
Please no more xmas music
so do standard algorithms 1 and 2 go together and 3 and 4 go together?
December 7, 2007 at 12:23 pm |
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!