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

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

View Full Document Right Arrow Icon
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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Fig 0.2 The Euclidean algorithm
Background image of page 2
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!
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example 3:
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
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

This note was uploaded on 12/19/2011 for the course CSCI 101 taught by Professor Dr.ambrose during the Spring '11 term at Community College of Baltimore County.

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 Right Arrow Icon
Ask a homework question - tutors are online