Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

CS107 Introduction to Computer Science Lecture 2.
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, Java Version, Third Edition.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Designing Algorithms Csci 107 Lecture 4. Outline Last time Computing 1+2+…+n Adding 2 n-digit numbers Today: More algorithms Sequential search Variations.
8 Algorithms Foundations of Computer Science ã Cengage Learning.
CMPUT101 Introduction to Computing(c) Yngvi Bjornsson & Jia You1 Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
Designing Algorithms February 2nd. Administrativia Lab assignments will be due every Monday Lab access –Searles 128: daily until 4pm unless class in progress.
CS107 Introduction to Computer Science Lecture 2.
Program Design and Development
Chapter 2 The Algorithmic Foundations of Computer Science
CHAPTER 2 CS
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Chapter 2: Design of Algorithms
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Fourth Edition.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 3: The Efficiency of Algorithms
Designing Algorithms Csci 107 Lecture 4.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
Chapter 2: Algorithm Discovery and Design
Pseudocode.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Pseudocode.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
CPSC 171 Introduction to Computer Science 3 Levels of Understanding Algorithms More Algorithm Discovery and Design.
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science 6th Edition
Invitation to Computer Science, Java Version, Second Edition.
Chapter 5 Algorithms Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas Faculty of Information Technology.
Introduction to Algorithms. What is Computer Science? Computer Science is the study of computers (??) This leaves aside the theoretical work in CS, which.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
ALGORITHM CHAPTER 8. Chapter Outlines and Objectives  Define an algorithm and relate it to problem solving.  Define three construct and describe their.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
CPSC 171 Introduction to Computer Science Algorithm Discovery and Design.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Chapter 2: General Problem Solving Concepts
Repetition Control Structures Simple Program Design Third Edition A Step-by-Step Approach 5.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Chapter 5 Algorithms © 2007 Pearson Addison-Wesley. All rights reserved.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Programming Logic and Design Fifth Edition, Comprehensive
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Program design Program Design Process has 2 phases:
Objective of This Course
Chapter 3: The Efficiency of Algorithms
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
Algorithm Discovery and Design
Algorithm Discovery and Design
Chapter 8: More on the Repetition Structure
Chapter 3: The Efficiency of Algorithms
Discovery and Design of Algorithms
Computer Science: An Overview Tenth Edition
Presentation transcript:

Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science

Invitation to Computer Science, 5th Edition Objectives In this chapter, you will learn about: Representing algorithms Examples of algorithmic problem solving 2

Invitation to Computer Science, 5th Edition Introduction Chapter 1 –Introduced algorithms and algorithmic problem solving This chapter –Develops more fully the notions of algorithm and algorithmic problem solving 3

Invitation to Computer Science, 5th Edition Representing Algorithms Pseudocode –Natural language: used to express algorithms –Problems using natural language to represent algorithms Natural language can be extremely verbose Lack of structure makes it difficult to locate specific sections of the algorithm Natural language is too “rich” in interpretation and meaning 4

Invitation to Computer Science, 5th Edition Figure 2.1 The Addition Algorithm of Figure 1.2 Expressed in Natural Language 5

Invitation to Computer Science, 5th Edition Pseudocode (continued) Natural languages –Not sufficiently precise to represent algorithms Pseudocode –Used to design and represent algorithms –A compromise between the two extremes of natural and formal languages 6

Invitation to Computer Science, 5th Edition Figure 2.2 The Beginning of the Addition Algorithm of Figure 1.2 Expressed in a High-Level Programming Language 7

Invitation to Computer Science, 5th Edition Sequential Operations Basic sequential operations –Computation, input, and output Instruction for performing a computation and saving the result –Set the value of “variable” to “arithmetic expression” Variable –Storage location that can hold a data value 8

Invitation to Computer Science, 5th Edition Sequential Operations (continued) Pseudocode –Not a precise set of notational rules to be memorized and rigidly followed Input operations –Submit to the computing agent data values from the outside world that it may then use in later instructions Output operations –Send results from the computing agent to the outside world 9

Invitation to Computer Science, 5th Edition Figure 2.3 Algorithm for Computing Average Miles per Gallon 10

Invitation to Computer Science, 5th Edition Conditional and Iterative Operations Sequential algorithm –Sometimes called a straight-line algorithm Control operations –Conditional and iterative –Allow us to alter the normal sequential flow of control in an algorithm Conditional statements –The “question-asking” operations of an algorithm – If/then/else 11

Invitation to Computer Science, 5th Edition Figure 2.4 The If/Then/Else Pseudocode Statement 12

Invitation to Computer Science, 5th Edition Figure 2.5 Second Version of the Average Miles per Gallon Algorithm 13

Invitation to Computer Science, 5th Edition Conditional and Iterative Operations (continued) Loop –The repetition of a block of instructions –While statement Continuation condition –Determines if statement is true or false Infinite loop –Continuation condition never becomes false 14

Invitation to Computer Science, 5th Edition Figure 2.5 Second Version of the Average Miles per Gallon Algorithm 15

Invitation to Computer Science, 5th Edition Figure 2.6 Execution of the While Loop 16

Invitation to Computer Science, 5th Edition Conditional and Iterative Operations (continued) Loop example Step Operation 1 Set the value of count to 1 2 While (count ≤ 100) do step 3 to step 5 3 Set square to (count x count) 4 Print the values of count and square 5 Add 1 to count 17

Invitation to Computer Science, 5th Edition Conditional and Iterative Operations (continued) Pretest loop –Continuation condition is tested at the beginning of each pass through the loop Posttest loop –Continuation condition is tested at the end of the loop body, not the beginning Primitives –Instructions that computing agent understands and is capable of executing without further explanation 18

Invitation to Computer Science, 5th Edition Figure 2.7 Third Version of the Average Miles per Gallon Algorithm 19

Invitation to Computer Science, 5th Edition Figure 2.8 Execution of the Do/While Posttest Loop 20

Invitation to Computer Science, 5th Edition Figure 2.9 Summary of Pseudocode Language Instructions 21

Invitation to Computer Science, 5th Edition Examples of Algorithmic Problem Solving Example 1: Go Forth and Multiply Given 2 nonnegative integer values, a ≥ 0, b ≥ 0, compute and output the product (a 3 b) using the technique of repeated addition. That is, determine the value of the sum a + a + a a (b times) 22

Invitation to Computer Science, 5th Edition Figure 2.10 Algorithm for Multiplication of Nonnegative Values via Repeated Addition 23

Invitation to Computer Science, 5th Edition Example 2: Looking, Looking, Looking Algorithm discovery –Finding a solution to a given problem Sequential search –Standard algorithm for searching an unordered list of values 24

Invitation to Computer Science, 5th Edition Figure 2.11 First Attempt at Designing a Sequential Search Algorithm 25

Invitation to Computer Science, 5th Edition Figure 2.12 Second Attempt at Designing a Sequential Search Algorithm 26

Invitation to Computer Science, 5th Edition Figure 2.13 The Sequential Search Algorithm 27

Invitation to Computer Science, 5th Edition Example 3: Big, Bigger, Biggest Library –Collection of useful algorithms Problem Given a value n ≥ 1 and a list containing exactly n unique numbers called A1, A2,..., An, find and print out both the largest value in the list and the position in the list where that largest value occurred 28

Invitation to Computer Science, 5th Edition Figure 2.14 Algorithm to Find the Largest Value in a List 29

Invitation to Computer Science, 5th Edition Example 4: Meeting Your Match Pattern matching –Process of searching for a special pattern of symbols within a larger collection of information –Is assisting microbiologists and geneticists studying and mapping the human genome 30

Invitation to Computer Science, 5th Edition Example 4: Meeting Your Match (continued) Pattern-matching problem You will be given some text composed of n characters that will be referred to as T1 T2... Tn. You will also be given a pattern of m characters, m ≤ n, that will be represented as P1 P2... Pm. The algorithm must locate every occurrence of the pattern within the text. The output of the algorithm is the location in the text where each match occurred. For this problem, the location of a match is defined to be the index position in the text where the match begins 31

Invitation to Computer Science, 5th Edition Example 4: Meeting Your Match (continued) STEP 1 –The matching process: T1 T2 T3 T4 T5 … P1 P2 P3 STEP 2 –The slide forward: T1 T2 T3 T4 T5 … –1-character slide -> P1 P2 P3 32

Invitation to Computer Science, 5th Edition Figure 2.15 First Draft of the Pattern-Matching Algorithm 33

Invitation to Computer Science, 5th Edition Example 4: Meeting Your Match (continued) Examples of higher-level constructs –Sort the entire list into ascending order –Attempt to match the entire pattern against the text –Find a root of the equation Abstraction –Use of high-level instructions during the design process Top-down design –Viewing an operation at a high level of abstraction 34

Invitation to Computer Science, 5th Edition Figure 2.16 Final Draft of the Pattern-Matching Algorithm 35

Invitation to Computer Science, 5th Edition Summary Algorithm design –A first step in developing an algorithm Algorithm design must: –Ensure the algorithm is correct –Ensure the algorithm is sufficiently efficient Pseudocode –Used to design and represent algorithms 36

Invitation to Computer Science, 5th Edition Summary (continued) Pseudocode –Readable, unambiguous, and able to be analyzed Algorithm design –Uses multiple drafts and top-down design to develop the best solution Abstraction –A key tool for good design 37