INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

CS107 Introduction to Computer Science Lecture 2.
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
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.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the five essential properties of an algorithm.
CMPUT101 Introduction to Computing(c) Yngvi Bjornsson & Jia You1 Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem.
Introduction to Analysis of Algorithms
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third Edition.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
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
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
Chapter 2 The Algorithmic Foundations of Computer Science
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Designing Algorithms Csci 107 Lecture 3. Administrativia Lab access –Searles 128: daily until 4pm unless class in progress –Searles 117: 6-10pm, Sat-Sun.
Chapter 2: Design of Algorithms
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 2: Algorithm Discovery and Design
Chapter 1 Program Design
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Adapted from slides by Marie desJardins
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.
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
计算机科学概述 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.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
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.
CPSC 171 Introduction to Computer Science Algorithm Discovery and Design.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 10 Algorithmic Thinking. Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Chapter 3: User-Defined Functions I
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science.
COMP Loop Statements Yi Hong May 21, 2015.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
Invitation to Computer Science, C++ Version, Fourth Edition
Chapter 5: Control Structures II
Invitation to Computer Science, Java Version, Third Edition
Objective of This Course
Algorithm Discovery and Design
Algorithm Discovery and Design
ICT Gaming Lesson 2.
Discovery and Design of Algorithms
Presentation transcript:

INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science

2 Objectives After studying this chapter, students will be able to: Explain the benefits of pseudocode over natural language or a programming language Represent algorithms using pseudocode Identify algorithm statements as sequential, conditional, or iterative Define abstraction and top-down design, and explain their use in breaking down complex problems Invitation to Computer Science, 6th Edition2

3 Objectives (continued) After studying this chapter, students will be able to: Illustrate the operation of sample algorithms –multiplication by repeated addition –sequential search of a collection of values –finding the maximum element in a collection –finding a pattern string in a larger piece of text Invitation to Computer Science, 6th Edition3

4 Introduction Algorithms for everyday may not be suitable for computers to perform (as in Chapter 1) Algorithmic problem solving focuses on algorithms suitable for computers Pseudocode is a tool for designing algorithms This chapter will use a set of problems to illustrate algorithmic problem solving Invitation to Computer Science, 6th Edition4

5 Representing Algorithms Pseudocode is used to design algorithms Natural language is: –expressive, easy to use –verbose, unstructured, and ambiguous Programming languages are: –structured, designed for computers –grammatically fussy, cryptic Pseudocode lies somewhere between these two Invitation to Computer Science, 6th Edition5

6 6

7 7

8 Representing Algorithms (continued) Sequential operations perform a single task –Computation: a single numeric calculation –Input: gets data values from outside the algorithm –Output: sends data values to the outside world A variable is a named location to hold a value A sequential algorithm is made up only of sequential operations Example: computing average miles per gallon Invitation to Computer Science, 6th Edition8

9 9

10 Representing Algorithms (continued) Control operation: changes the normal flow of control Conditional statement: asks a question and selects among alternative options 1. Evaluate the true/false condition 2. If the condition is true, then do the first set of operations and skip the second set 3. If the condition is false, skip the first set of operations and do the second set Example: check for good or bad gas mileage Invitation to Computer Science, 6th Edition10

11

12 Invitation to Computer Science, 6th Edition12

13 Representing Algorithms (continued) Iteration: an operation that causes looping, repeating a block of instructions While statement repeats while a condition remains true –continuation condition: a test to see if while loop should continue –loop body: instructions to perform repeatedly Example: repeated mileage calculations Invitation to Computer Science, 6th Edition13

14

15 Invitation to Computer Science, 6th Edition15

16 Representing Algorithms (continued) Do/while, alternate iterative operation –continuation condition appears at the end –loop body always performed at least onc Primitive operations: sequential, conditional, and iterative are all that is needed Invitation to Computer Science, 6th Edition16

17

18

19 Examples of Algorithmic Problem Solving Example 1: Go Forth and Multiply “Given two nonnegative integer values, a ≥ 0, b ≥ 0, compute and output the product (a × b) using the technique of repeated addition. That is, determine the value of the sum a + a + a a (b times).” Invitation to Computer Science, 6th Edition19

20 Examples of Algorithmic Problem Solving Example 1: Go Forth and Multiply (continued) Get input values –Get values for a and b Compute the answer –Loop b times, adding each time* Output the result –Print the final value* * steps need elaboration Invitation to Computer Science, 6th Edition20

21 Examples of Algorithmic Problem Solving Example 1: Go Forth and Multiply (continued) Loop b times, adding each time –Set the value of count to 0 –While (count < b) do … the rest of the loop* Set the value of count to count + 1 –End of loop * steps need elaboration Invitation to Computer Science, 6th Edition21

22 Examples of Algorithmic Problem Solving Loop b times, adding each time –Set the value of count to 0 –Set the value of product to 0 –While (count < b) do Set the value of product to (product + a) Set the value of count to count + 1 –End of loop Output the result –Print the value of product Invitation to Computer Science, 6th Edition22

23 Invitation to Computer Science, 6th Edition23

24 Examples of Algorithmic Problem Solving Example 2: Looking, Looking, Looking “Assume that we have a list of 10,000 names that we define as N 1, N 2, N 3,..., N 10,000, along with the 10,000 telephone numbers of those individuals, denoted as T 1, T 2, T 3,..., T 10,000. To simplify the problem, we initially assume that all names in the book are unique and that the names need not be in alphabetical order.” Invitation to Computer Science, 6th Edition24

25 Examples of Algorithmic Problem Solving Example 2: Looking, Looking, Looking (continued) Three versions here illustrate algorithm discovery, working toward a correct, efficient solution –A sequential algorithm (no loops or conditionals) –An incomplete iterative algorithm –A correct algorithm Invitation to Computer Science, 6th Edition25

26 Invitation to Computer Science, 6th Edition26

27 Invitation to Computer Science, 6th Edition27

28 Invitation to Computer Science, 6th Edition28

29 Examples of Algorithmic Problem Solving Example 3: Big, Bigger, Biggest A “building-block” algorithm used in many libraries Library: A collection of pre-defined useful algorithms “Given a value n ≥ 1 and a list containing exactly n unique numbers called A 1, A 2,..., A n, find and print out both the largest value in the list and the position in the list where that largest value occurred.” Invitation to Computer Science, 6th Edition29

30 Invitation to Computer Science, 6th Edition30

31 Examples of Algorithmic Problem Solving Example 4: Meeting Your Match Pattern-matching: common across many applications –word processor search, web search, image analysis, human genome project “You will be given some text composed of n characters that will be referred to as T 1 T 2... T n. You will also be given a pattern of m characters, m ≤ n, that will be represented as P 1 P 2... P m. The algorithm must locate every occurrence of the given pattern within the text. The output of the algorithm is the location in the text where each match occurred.” Invitation to Computer Science, 6th Edition31

32 Examples of Algorithmic Problem Solving Example 4: Meeting Your Match (continued) Algorithm has two parts: 1. Sliding the pattern along the text, aligning it with each position in turn 2. Given a particular alignment, determine if there is a match at that location Solve parts separately and use –Abstraction, focus on high level, not details –Top-down design, start with big picture, gradually elaborate parts Invitation to Computer Science, 6th Edition32

33 Invitation to Computer Science, 6th Edition33

34 Invitation to Computer Science, 6th Edition34

35 Summary Pseudocode is used for algorithm design: structured like code, but allows English and math phrasing and notation Pseudocode is made up of: sequential, conditional, and iterative operations Algorithmic problem solving involves: –Step-by-step development of algorithm pieces –Use of abstraction, and top-down design Invitation to Computer Science, 6th Edition35