Download presentation
Presentation is loading. Please wait.
Published byDarren Dale Marshall Modified over 8 years ago
1
CPSC 171 Introduction to Computer Science Algorithm Discovery and Design
2
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
3
Reading Assignment Chapter 1 in Textbook Homework Assignment page 34 of Textbook Problems 5,7,8,9,13 Due Sept 4 at beginning of class
4
Problem 3 Page 34 Read problem in book Follow along on board
5
An Algorithm is A well-ordered collection of Unambiguous and Effectively computable operations that, when executed Produces a result and Halts in a finite amount of time Textbook definition
6
Representing Algorithms How do we represent algorithms? English Programming Language We will start with pseudocode and later will look at various programming languages.
7
Pseudocode Set of English Constructs designed to resemble statements in programming languages Steps presented in structured manner Simple, Highly readable
8
Constructs We Will Use Sequential operations to carry out computation, input, and output. Conditional operations. Iterative operations.
9
Sequential Operations computation 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".
10
Example Algorithm (Sequential) Figure 2.3 Algorithm for Computing Average Miles per Gallon
11
Practice Write an algorithm in pseudocode to: Get the radius of a circle as input and output the circumference and area of the circle
12
Conditional Operation If “a true/false condition” is true then first set of algorithmic operations Else second set of algorithm operations Notice the indentation
13
Example Algorithm (conditionals) Figure 2.5 Second Version of the Average Miles per Gallon Algorithm
14
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.
15
Conditional Operation Picture true-false statement truefalse operation false branch true branch Note: either branch can be missing
16
true-false statement truefalse operation false branch true branch Note: either branch can be missing Conditional Operation Picture
17
true-false statement truefalse operation false branch true branch Note: either branch can be missing Conditional Operation Picture
18
Iterative Operations Set count to 5 While count < 4 Add 1 to count Print count stop Set count to 5 Do Add 1 to count Print count While count < 4 stop Notice when the continuation condition is checked Pretest loopPosttest loop
19
Infinite Loops Set count to 0 While count >= 0 Add 1 to count Print count stop
20
Iteration Operation Picture true-false statement true-false statement false true operation false operation while loop Do/while loop
21
Figure 2.7 Third Version of the Average Miles per Gallon Algorithm Example Algorithm (iteration)
22
Practice Write an algorithm that gets as input a single data value, x, and outputs the three values x 2, sin x, 1/x. This process should repeat until the input value for x is equal to 99.
23
Summary of Operation Types for Algorithms Sequential operations to carry out computation, input, and output. Conditional operations. Iterative operations.
24
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.