CPSC 171 Introduction to Computer Science - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

CPSC 171 Introduction to Computer Science

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 ... – PowerPoint PPT presentation

Number of Views:291
Avg rating:3.0/5.0
Slides: 25
Provided by: LousL3
Category:

less

Transcript and Presenter's Notes

Title: CPSC 171 Introduction to Computer Science


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.
  • X2 - 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
true
false
true branch
false branch
operation
operation
operation
Note either branch can be missing
operation
16
Conditional Operation Picture
true-false statement
true
false
true branch
false branch
operation
operation
operation
Note either branch can be missing
operation
17
Conditional Operation Picture
true-false statement
true
false
true branch
false branch
operation
operation
operation
Note either branch can be missing
operation
18
Iterative Operations
  • Set count to 5
  • While count lt 4
  • Add 1 to count
  • Print count
  • stop

Set count to 5 Do Add 1 to count Print
count While count lt 4 stop
Pretest loop
Posttest loop
Notice when the continuation condition is checked
19
Infinite Loops
  • Set count to 0
  • While count gt 0
  • Add 1 to count
  • Print count
  • stop

20
Iteration Operation Picture

true-false statement
false
operation
true
operation
operation
operation
true-false statement
true
false
while loop
Do/while loop
21
Example Algorithm (iteration)
  • Figure 2.7
  • Third Version of the Average Miles per Gallon
    Algorithm

22
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.

23
Summary of Operation Typesfor 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.
Write a Comment
User Comments (0)
About PowerShow.com