Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.

Slides:



Advertisements
Similar presentations
Algorithms.
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Chapter 5 Algorithms. 2 Chapter 5: Algorithms 5.1 The Concept of an Algorithm 5.2 Algorithm Representation 5.3 Algorithm Discovery 5.4 Iterative Structures.
Slide Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 2- 1.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 2: Algorithm Discovery and Design
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object, Object- Relational, and XML: Concepts, Models, Languages,
Chapter 2 The Algorithmic Foundations of Computer Science
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Computer Science, An Overview Brookshear © 2000 Addison Wesley Computer Science — An Overview J. Glenn Brookshear Chapter Zero, Figures 1-3 Introduction.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Part 1 Conditionals and Loops.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Eleventh Edition by J.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
February 24, 2015Applied Discrete Mathematics Week 4: Number Theory 1 Modular Arithmetic Let a be an integer and m be a positive integer. We denote by.
Introduction to Computer Systems
Copyright © 2015 Pearson Education, Inc. Chapter 5: Algorithms.
Introduction to Programming. What is a Program  Set of Instructions that tells the computer what to Do.  Driving force behind the computer  Without.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science 6th Edition
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Limits.
Chapter 5 Algorithms © 2007 Pearson Addison-Wesley. All rights reserved.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
“The study of algorithms is the cornerstone of computer science.” Algorithms Fall 2011.
Chapter 5 Algorithms Introduction to computer, 2nd semester, 2010/2011 Mr.Nael Aburas Faculty of Information Technology.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 4 Applications of the Derivative.
Algorithm: definition An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.
Chapter 5 Algorithms. © 2005 Pearson Addison-Wesley. All rights reserved 5-2 Chapter 5: Algorithms 5.1 The Concept of an Algorithm 5.2 Algorithm Representation.
Chapter 5: 演算法 Algorithms 陳以德助理教授 : 高醫大舊二棟 轉 2586
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
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.
Computer Science: An Overview Eleventh Edition
17 November 2015Birkbeck College1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
17 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Slide Copyright © 2009 Pearson Education, Inc. Unit 1 Number Theory MM-150 SURVEY OF MATHEMATICS – Jody Harris.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
Algorithms and Problem Solving
Computer Science: An Overview Eleventh Edition
CSE 504 Discrete Mathematics & Foundations of Computer Science
Chapter 5: Algorithms 5.1 The Concept of an Algorithm
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
Problem Solving and Algorithm Design
Computer Science: An Overview Tenth Edition
Presentation transcript:

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn Brookshear

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-2 Chapter 5: Algorithms 5.1 The Concept of an Algorithm 5.2 Algorithm Representation 5.3 Algorithm Discovery

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-3 Definition of Algorithm An algorithm is an ordered set of unambiguous, executable steps that defines a terminating process.

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-4 Figure 5.2 Folding a bird from a square piece of paper

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-5 Algorithm Representation Primitive: Well-defined set of building blocks from which algorithm representations can be constructed. Algorithms require well-defined primitives A collection of primitives constitutes a programming language.

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-6 Figure 5.3 Origami primitives

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-7 Pseudocode A notational system in which ideas can be expressed informally during the algorithm development process Pseudocode primitives: – Assignment –Conditional selection –Repeated execution –Procedure

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-8 Pseudocode Primitives Assignment name  expression (assign name the value of expression) Examples: total  a+b X  9

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-9 Pseudocode Primitives (continued) Conditional selection if condition then action if condition then action1 else action2 Example 1: if (year is a leap year) then (daily total  total divided by 366) else (daily total  total divided by 365)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-10 Pseudocode Primitives (continued) Conditional selection Example 2: if ( not raining) then ( if (temperature=hot) then (go swimming) else (play golf) ) else (watch television)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Pseudocode Primitives (continued) Repeated execution while condition do activity while ( tickets remain to be sold) do (sell a ticket) 5-11

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Example:Rewrite the following program segment using a while structure Count  1 repeat (print the value assigned to Count and Count  Count+1 ) until (Count=5) Count  1 while (Count < 5) do ( print the value assigned to Count and Count  Count + 1) 5-12

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-13 Pseudocode Primitives (continued) Procedure (a pseudocode unit)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Example: Greatest common divisor The Euclidean algorithm finds the greatest common divisor of two positive integers X and Y by the following process: As long as the value of neither X nor Y is zero, continue dividing the larger of the values by the smaller and assigning X and Y the values of the divisor and remainder, respectively 5-14

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Example: Greatest common divisor procedure Euclidean if (neither X nor Y is 0) then (divide the larger of X and Y by the smaller; Y ← the value of the remainder; X ← the value of the divisor; and apply Euclidean to X and Y ) 5-15

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-16 The Art of Problem Solving Polya’s Problem Solving Steps 1.Understand the problem. 2.Devise a plan for solving the problem. 3.Carry out the plan. 4.Evaluate the solution for accuracy and its potential as a tool for solving other problems.

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-17 Ages of Children Problem Person A is charged with the task of determining the ages of B’s three children –B tells A that the product of the children’s ages is 36. –A replies that another clue is required. –B tells A the sum of the children’s ages. –A replies that another clue is needed. –B tells A that the oldest child plays the piano. –A tells B the ages of the three children. How old are the three children?

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-18 Clue 1 : B tells A that the product of the children’s ages is 36

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-19 Clue 1 : B tells A that the product of the children’s ages is 36 Clue 2 : B tells A that the sum of the children’s ages (?)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-20 Clue 1 : B tells A that the product of the children’s ages is 36 Clue 2 : B tells A that the sum of the children’s ages Clue 3 : B tells A that oldest child play piano

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-21 Getting a Foot in the Door Try working the problem backwards Stepwise refinement: Divide the problem into smaller problems (top-down methodology) A top-down approach an overview of the system is formulated, specifying but not detailing any first-level subsystems (black boxes)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-22 Getting a Foot in the Door Solve an easier related problem –Relax some of the problem constraints –Solve pieces of the problem first (bottom-up methodology) In bottom up- approach, individual base elements of the system are first specified in great detail

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Example 1 The following is an addition problem in binary notation. Each letter represents a unique binary digit. Which letter represents 1 and which represents 0? 5-23

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Example 2 Design an algorithm for finding all the factors of a positive integer. For example, in the case of the integer 12, your algorithm should report the values 1,2,3,4,6 and 12. X  1 while (X ≤ N) do (if (X divides N) then report X X  X+1 ) 5-24