UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

An Example of an Algorithm

Suppose you are given an unsorted list of numbers and want to find the largest number in this list.

Here's an informally described algorithm:

  1. When you begin, the first number is the largest number in the list you've seen so far.
  2. Look at the next number, and compare it with the largest number you've seen so far.
  3. If this next number is larger, then make that the new largest number you've seen so far.
  4. Repeat steps 2 and 3 until you have gone through the whole list.
And here is a more formal coding of the algorithm in a pseudocode that is similar to most programming languages
Given: a list of numbers "list" 

largest = list[1]
counter = 2
while counter <= length(list)
    if list[counter] > largest
        largest = list[counter]
    counter = counter + 1
print largest

Are their other algorithms for solving this general problem?

It's easy to prove that:


CSEE | 201 | 201 F'06 | lectures | news | help

last modified on Tuesday, 22-Aug-2006 07:14:15 EDT