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

Algorithm and Complexity Analysis
The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
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.
8 Algorithms Foundations of Computer Science ã Cengage Learning.
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.
Chapter 2: Algorithm Discovery and Design
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
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 9: Algorithms and Pseudo-code.
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
Chapter 2: Algorithm Discovery and Design
Chapter 7 Problem Solving with Loops
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 © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Eleventh Edition by J.
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
Invitation to Computer Science, Java Version, Second Edition.
Reynolds 2006 Complexity1 Complexity Analysis Algorithm: –A sequence of computations that operates on some set of inputs and produces a result in a finite.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Limits.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 5 Algorithms © 2007 Pearson Addison-Wesley. All rights reserved.
“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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn.
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.
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
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
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
Chapter 8 Algorithms.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Algorithms and Problem Solving
Q & A.
Computer Science: An Overview Eleventh Edition
Chapter 5: Algorithms 5.1 The Concept of an Algorithm
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
Computer Science — An Overview J. Glenn Brookshear
Algorithm Discovery and Design
Algorithms and Problem Solving
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 Modified by Marie desJardins for UMBC’s CMSC 100, Fall2008

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 5.4 Iterative Structures 5.5 Recursive Structures (skipping for now) 5.6 Efficiency and Correctness (coming back to this later)

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 Algorithm Representation Requires well-defined primitives A collection of primitives constitutes a programming language.

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

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 Primitives Assignment name  expression Conditional selection if condition then action

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-8 Pseudocode Primitives (continued) Repeated execution while condition do activity Procedure procedure name (generic names)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-9 Figure 5.4 The procedure Greetings in pseudocode

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-10 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-11 Getting a Foot in the Door Try working the problem backwards Solve an easier related problem –Relax some of the problem constraints –Solve pieces of the problem first (bottom up methodology) Stepwise refinement: Divide the problem into smaller problems (top-down methodology)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-12 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-13 Figure 5.5

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-14 Iterative Structures Pretest loop: while (condition) do (loop body) Posttest loop: repeat (loop body) until(condition)

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-15 Figure 5.6 The sequential search algorithm in pseudocode

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-16 Figure 5.7 Components of repetitive control

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-17 Figure 5.8 The while loop structure

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-18 Figure 5.9 The repeat loop structure

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-19 Figure 5.10 Sorting the list Fred, Alex, Diana, Byron, and Carol alphabetically

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-20 Figure 5.11 The insertion sort algorithm expressed in pseudocode

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-21 Algorithm Efficiency Measured as number of instructions executed Big theta notation: Used to represent efficiency classes –Example: Insertion sort is in Θ(n 2 ) Best, worst, and average case analysis

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-22 Complexity Classes

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-23 Figure 5.18 Applying the insertion sort in a worst-case situation

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-24 Figure 5.19 Graph of the worst-case analysis of the insertion sort algorithm

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-25 Figure 5.20 Graph of the worst-case analysis of the binary search algorithm