{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Chapter_0-2 - Let m=1210 let n=120 find the GCD Example 4...

This preview shows pages 1–10. Sign up to view the full content.

Algorithm A set of steps that defines how a task is performed A step by step procedure that gets us from problem statement to problem solution An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process. (page 205)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Fig 0.2 The Euclidean algorithm
Is this set of steps really an Algorithm? It has ordered steps The steps are unambiguous The steps are executable or “do-able” The process terminates or halts Yes, it is an algorithm!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 1: Step 1: let m=400, n=60 Step 2: 400/60 R = 40 Step 3: R is not 0 so m=60 and n=40 Step 2: 60/40 R = 20 Step 3: R is not 0 so m=40 and n=20 Step 2: 40/20 R = 0 Step 3: R is 0 so GCD = n = 20
Example 2: Step 1: let m=963, n=33 Step 2: 963/33 R = 6 Step 3: R is not 0 so m=33 and n=6 Step 2: 33/6 R = 3 Step 3: R is not 0 so m=6 and n=3 Step 2: 6/3 R = 0 Step 3: R is 0 so GCD = n = 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 3:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Let m=1210, let n=120, find the GCD Example 4: Let m=125, n=26, find the GCD. Notes about this algorithm It makes use of SEQUENCING (step 1, step 2, step 3) It makes use of SELECTION (if …. . Otherwise …. .) It makes use of REPETITION (return to step 2) What is Programming? Writing programs is called programming We write programs to implement algorithms The three fundamental features of computer programs are: SEQUENCING SELECTION REPETITION The Euclidean algorithm illustrates all three! Another algorithm: Selection Sort Assume we have an unordered list of numbers. Find the minimum value in the list Swap it with the value in the first position Repeat the steps above for the remainder of the list (starting at the second position and advancing each time) Reference: http://en.wikipedia.org/wiki/Selection_sort...
View Full Document

{[ snackBarMessage ]}

### Page1 / 10

Chapter_0-2 - Let m=1210 let n=120 find the GCD Example 4...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online