You are on page 1of 10

Computer Programming

What is an algorithm?

1
Algorithm

• An Algorithm is :
• a recipe
• a set of instructions
• directions
• rules of a game
• a computer program

2
An example

• How to compute the Greatest Common


Divisor (GCD).

• The GCD of X and Y is the largest number


that divides exactly into X and divides exactly
into Y

3
GCD Algorithm

• As long as X and Y are unequal subtract the


smaller number from the bigger one.

• When both X and Y are equal, that is the


GCD.

4
GCD Example

• Let:
• X = 148
• Y = 259

5
GCD Result

• X • Y

• 148 • 259

• 148 • 111

• 37 • 111

• 37 • 74

• 37 • 37

6
Example 2

• Let :
• X = 624392601
• Y = 564719532
• Work out answer.....

7
A Problem

• The last problem was a bit big for a person to


work out.

• It not impossible to do, but it will take a long


time.

• This is the ideal type of work for a computer


program to do

8
Algorithm is the same

• The algorithm for this problem performs the


same tasks no matter the language.

9
Key Point

• The skills we learn on this course can be used


for every program you write (for ever).

• When you know how to program, learning a


new language is just learning new syntax.

10

You might also like