Upload
danae
View
40
Download
0
Tags:
Embed Size (px)
DESCRIPTION
CPSC 171 Introduction to Computer Science. Algorithm Discovery and Design. Lab Hours, Colton 106. Sunday: Matt Young Monday: Will Mooney Tuesday: Cody Depew Wednesday: Christian Ebinger Thursday: Stefan Maurer Lab will be open 8-10pm starting Monday night, Sept. 7. Reading Assignment. - PowerPoint PPT Presentation
Citation preview
CPSC 171 Introduction to Computer Science
Algorithm Discovery and Design
Lab Hours, Colton 106
Sunday: Matt YoungMonday: Will MooneyTuesday: Cody DepewWednesday: Christian EbingerThursday: Stefan Maurer
Lab will be open 8-10pm starting Monday night, Sept. 7
Reading Assignment
Chapter 1 in Textbook
Homework Assignmentpage 34 of TextbookProblems 5,7,8,9,13Due Sept 4 at beginning of class
Problem 3 Page 34
Read problem in bookFollow along on board
An Algorithm is
A well-ordered collection ofUnambiguous andEffectively computable operations
that, when executedProduces a result andHalts in a finite amount of time
Textbook definition
Representing Algorithms
How do we represent algorithms?EnglishProgramming LanguageWe will start with pseudocode and later will look at various programming languages.
Pseudocode
Set of English Constructs designed to resemble statements in programming languagesSteps presented in structured mannerSimple, Highly readable
Constructs We Will Use
Sequential operations to carry out
computation, input, and output.Conditional operations.Iterative operations.
Sequential Operationscomputation
Set the value of X to 3. Assign X a value of A + B. X=2 - C. Set the value of Name to the first person's name.
input Get a value for X, Y, and Z. Input values for A1, A2, ..., Am. Read X, Y, and Carry.
output Output the value of X. Print values for X, Y, and Carry. Print the message, "Error".
Example Algorithm (Sequential)
Figure 2.3Algorithm for Computing Average Miles per Gallon
Practice
Write an algorithm in pseudocode to:
Get the radius of a circle as input and output the circumference and area of the circle
Conditional Operation
If “a true/false condition” is true then
first set of algorithmic operations
Elsesecond set of algorithm
operationsNotice the indentation
Example Algorithm (conditionals)
Figure 2.5Second Version of the Average Miles per Gallon Algorithm
Practice
Modify your algorithm to print “large circle” if the circumference is greater than 100 and “small circle” if it is equal to or less than 100.
Conditional Operation Picture
true-falsestatement
true false
operation
operation
operation
operation
false branch
true
branch
Note: either branch can be missing
true-falsestatement
true false
operation
operation
operation
operation
false branch
true
branch
Note: either branch can be missing
Conditional Operation Picture
true-falsestatement
true false
operation
operation
operation
operation
false branch
true
branch
Note: either branch can be missing
Conditional Operation Picture
Iterative OperationsSet count to 5While count < 4
Add 1 to countPrint count
stop
Set count to 5Do
Add 1 to countPrint count
While count < 4stop
Notice when the continuation condition is checked
Pretest loop Posttest loop
Infinite Loops
Set count to 0While count >= 0
Add 1 to countPrint count
stop
Iteration Operation Picture
true-falsestatement
true-falsestatement
false
true
true
operation
operation
false
operation
operation
while loop Do/while loop
Figure 2.7
Third Version of the Average Miles per Gallon Algorithm
Example Algorithm (iteration)
Practice
Write an algorithm that gets as input a single data value, x, and outputs the three values x2, sin x, 1/x. This process should repeat until the input value for x is equal to 99.
Summary of Operation Typesfor Algorithms
Sequential operations to carry out
computation, input, and output.Conditional operations.Iterative operations.
There is a theorem in theoretical computer science that proves that these operations are sufficient to represent ANY algorithm!
Algorithms are used to do everything you see on a computer!
Do word processing.Fly NASA probes to the planets.Run the international telephone switching system.Create CAT scan images.Process your pay checks.Run computer games.Etc.