1 / 24

CPSC 171 Introduction to Computer Science

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.

danae
Télécharger la présentation

CPSC 171 Introduction to Computer Science

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Figure 2.3 Algorithm for Computing Average Miles per Gallon Example Algorithm (Sequential)

  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. Figure 2.5 Second Version of the Average Miles per Gallon Algorithm Example Algorithm (conditionals)

  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 true-false statement false true branch false branch operation operation operation Note: either branch can be missing operation

  16. Conditional Operation Picture true true-false statement false true branch false branch operation operation operation Note: either branch can be missing operation

  17. Conditional Operation Picture true true-false statement false true branch false branch operation operation operation Note: either branch can be missing operation

  18. Iterative Operations Set count to 5 Do Add 1 to count Print count While count < 4 stop Set count to 5 While count < 4 Add 1 to count Print count stop Pretest loop Posttest loop Notice when the continuation condition is checked

  19. Infinite Loops Set count to 0 While count >= 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.

More Related