Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis.

Slides:



Advertisements
Similar presentations
Problem Solving and Algorithm Design
Advertisements

Slides modified by Erin Chambers Problem Solving and Algorithm Design.
6-1 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer problem-solving process and relate it to Polya’s.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Problem Solving and Algorithms
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Algorithms and Problem Solving-1 Algorithms and Problem Solving Mainly based on Chapter 6: “Problem Solving and Algorithm Design” from the Book: “Computer.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
1 Chapter 6 Object-Oriented Software Design and Implementation.
Algorithms and Problem Solving-1 Algorithms and Problem Solving Mainly based on Chapter 6: “Problem Solving and Algorithm Design” from the Book: “Computer.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 2: Algorithm Discovery and Design
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis.
Chapter 1 Software Engineering. Homework ► Read Section 2.2 (pages 79-98) ► Answer questions: ► 7, 8, 11, 12, & 13 on page 134. ► Answer on paper, hand.
6-1 Problem Solving Problem solving is the act of finding a solution to a perplexing, distressing, vexing, or unsettled question.
Chapter 1 Program Design
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Problem Solving and Algorithm Design
Chapter 2: Algorithm Discovery and Design
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
Chapter 9 High-Level Programming Languages: C++. Chapter Goals Describe the expectations of high level languages Distinguish between functional design.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
CPS 120: Introduction to Computer Science
Chapter 9 Object-Oriented Design and High-Level Programming Languages.
Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List operations.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
CS 1308 Computer Literacy and The Internet Software.
1 C++ Plus Data Structures Nell Dale Chapter 1 Software Engineering Principles Modified from the Slides made by Sylvia Sorkin, Community College of Baltimore.
Algorithms CS139 – Aug 30, Problem Solving Your roommate, who is taking CS139, is in a panic. He is worried that he might lose his financial aid.
Chapter 6 Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing,
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Apply top-down design methodology to develop an algorithm to solve a problem Define the.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Data Structures Using C++ 2E
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
A little hardware; a little software CS 139 – 08/29/07.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 4 ADT Sorted List. Sorted Type Class Interface Diagram SortedType class IsFull GetLength ResetList DeleteItem PutItem MakeEmpty GetItem Private.
Algorithms CS280 – 10/20/05. Announcement  Part 1 of project 2 due.  Read chapters 10, 7 for this unit  Tuesday we will also be in the classroom We.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Chapter 2 Principles of Programming and Software Engineering.
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.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Algorithms Sept 4, Tuesday’s Lab You developed an algorithm Input – an 8 ½ x 11 inch piece of paper Audience – Fellow classmates Process – Instructions.
Algorithms and Problem Solving
C++ Plus Data Structures
Object-Oriented Design
Chapter 1 Software Engineering.
PROBLEM SOLVING SKILLS
Problem Solving and Algorithm Design
Problem Solving and Algorithm Design
Programming We have seen various examples of programming languages
Algorithms and Problem Solving
Presentation transcript:

Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis

6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer problem-solving process and relate it to Polya’s How to Solve It list Distinguish between following an algorithm and developing one Apply top-down design methodology to develop an algorithm to solve a problem

6-3 Chapter Goals (cont.)-skipped Define the key terms in object-oriented design Apply object-oriented design methodology to develop a collection of interacting objects to solve a problem Discuss the following threads as they relate to problem solving: information hiding, abstraction, naming things, and testing

6-4 Problem Solving Problem solving is the act of finding a solution to a perplexing, distressing, vexing, or unsettled question

6-5 Problem Solving G. Polya wrote How to Solve It: A New Aspect of Mathematical Method His How to Solve It list is quite general –Written in the context of solving mathematical problems –The list becomes applicable to all types of problems

6-6 Ask Questions... …to understand the problem –What do I know about the problem? –What is the information that I have to process in order to find the solution? –What does the solution look like? –What sort of special cases exist? –How will I recognize that I have found the solution?

6-7 Look for Familiar Things You should never reinvent the wheel In computing, you see certain problems again and again in different guises A good programmer sees a task, or perhaps part of a task (a subtask), that has been solved before and plugs in the solution

6-8 Divide and Conquer Break up a large problem into smaller units that we can handle –Applies the concept of abstraction –The divide-and-conquer approach can be applied over and over again until each subtask is manageable

6-9 Algorithms An algorithm is set of instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data The instructions are unambiguous

6-10 Computer Problem-Solving Figure 6.2 The computer problem-solving process

6-11 Figure 6.3: The Interactions Between Problem-Solving Phases

6-12 Pseudocode Uses a mixture of English and formatting to make the steps in the solution explicit Page 149

6-13 Following an Algorithm Preparing a Hollandaise sauce Figure 6.4

6-14 Following an Algorithm (cont.) Preparing a Hollandaise sauce Page 150

6-15 Developing an Algorithm The plan must be suitable in a suitable form Two methodologies that currently used –Top-down design –Object-oriented design

6-16 Top-Down Design Breaking the problem into a set of subproblems called modules Creating a hierarchical structure of problems and subproblems

6-17 Top-Down Design This process continues for as many levels as it takes to expand every task to the smallest details A step that needs to be expanded is an abstract step Figure 6.5 An example of top-down design

6-18 A General Example Planning a large party Figure 6.6 Subdividing the party planning

6-19 A Computer Example Problem –Create an address list that includes each person’s name, address, telephone number, and address –This list should then be printed in alphabetical order –The names to be included in the list are on scraps of paper and business cards

6-20 A Computer Example Page 156

6-21 A Computer Example Page 157

6-22 A Computer Example Page 158 read

6-23 A Computer Example Page 159

6-24 Testing the Algorithm The process itself must be tested Testing at the algorithm development phase involves looking at each level of the top-down design

6-25 Testing the Algorithm Desk checking: sit at a desk with a pencil and paper and work through the design Walk-through: Manual simulation of the design by the team members –Take sample data values and simulate the design using the sample data Inspection: The design is handed out in advance, and one person (not the designer) reads the design line by line while the others point out errors skip 26-39

6-26 Object-Oriented Design-all skipped A problem-solving methodology that produces a solution to a problem in terms of self-contained entities called objects An object is a thing or entity that makes sense within the context of the problem –For example, a student

6-27 Object-Oriented Design A group of similar objects is described by an object class, or class A class contains fields that represent the properties and behaviors of the class –A field can contain data value(s) and/or methods (subprograms) –A method is a named algorithm that manipulates the data values in the object

6-28 Relationships Between Classes Containment –“part-of” –An address class may be part of the definition of a student class Inheritance –Classes can inherit data and behavior from other classes –“is-a”

6-29 Object-Oriented Design Methodology Four stages to the decomposition process –Brainstorming –Filtering –Scenarios –Responsibility algorithms

6-30 CRC Cards Page 165

6-31 Brainstorming A group problem-solving technique that involves the spontaneous contribution of ideas from all members of the group –All ideas are potential good ideas –Think fast and furiously first, and ponder later –A little humor can be a powerful force Brainstorming is designed to produce a list of candidate classes

6-32 Filtering Determine which are the core classes in the problem solution There may be two classes in the list that have many common attributes and behaviors There may be classes that really don’t belong in the problem solution

6-33 Scenarios Assign responsibilities to each class There are two types of responsibilities –What a class must know about itself (knowledge) –What a class must be able to do (behavior) Encapsulation is the bundling of data and actions in such a way that the logical properties of the data and actions are separated from the implementation details

6-34 Responsibility Algorithms The algorithms must be written for the responsibilities –Knowledge responsibilities usually just return the contents of one of an object’s variables –Action responsibilities are a little more complicated, often involving calculations

6-35 Computer Example Let’s repeat the problem-solving process for creating an address list Brainstorming and filtering –Circling the nouns and underlining the verbs Page 171

Computer Example First pass at a list of classes Page 172

Computer Example Filtered list Page 172

6-38 CRC Cards Page 173

6-39 Responsibility Algorithms Page 175

6-40 Information Hiding Deferring the details –Giving a name to a task and not worrying about how the task is to be implemented until later –Abstraction and information hiding are two sides of the same coin

6-41 Information Hiding Abstraction is the result with the details hidden –Data abstraction refers to the view of data –Procedural abstraction refers to the view of actions –Control abstraction refers to the view of a control structure

6-42 Programming Languages Instructions written in a programming language can be translated into the instructions that a computer can execute directly Program: a meaningful sequence of instructions for a computer –Syntax: the part that says how the instructions of the language can be put together –Semantics: the part that says what the instructions mean

6-43 Ethical Issues: Plagiarism Plagiarism is by no means a new ethical concern –Access to the Web have billions of term papers available –Digital plagiarism is particularly difficult to detect since there is no visible difference between papers that have been downloaded and printed and those that were typed and printed Professors have developed ways to uncover web-based plagiarism –Use sites like plagiarism.org, which takes an uploaded portion of text and compares it to thousands of papers that exist online

6-44 Pseudo Code 練習 以下的 Pseudo Code 會執行 “ set count to count-1 ” 幾次 ? Set Count to 10 While (count >= 5) set count to count -1

6-45 Pseudo Code 練習 以下的 Pseudo Code 至多會執行 “ try to open jar ” 幾次 ? Set Count to 0 While (jar is not open and count < 10) Try to open jar If jar is not open set count to count +1

6-46 Pseudo Code 練習 以下的 Pseudo Code 執行完畢後 Cop = ? Driver= ? Set Cop to 0 Set Driver=40 While (Cop < Driver) Set Cop = Cop + 25 Set Driver = Driver + 20

6-47 Pseudo code 練習 ( 印出介於 10 及 100 間,所有的質數 ) 設定 要檢查的數 為 10 當要檢查的數 比 100 小 假設 要檢查的數 為質數 設定除數為 2 當 ( 要檢查的數 仍被認定為質數而且 除數 小於 ( 要檢查的數 /2) ) 如果要檢查的數可以 讓 除數 整除 確定不是質數 否則 除數 加 1 如果要檢查的數仍被認定為質數 印出 要檢查的數 要檢查的數 的值加 1

6-48 印出介於 10 及 100 間,所有的質數 ( 類程式碼 ) set number = 10 'number 為要檢查的數 while (number <= 100) 'number 比 100 小 set prime = true ' 假設為質數 set divider = 2 ' 設定除數為 2 while ( prime and divider < number/2) ' 還沒有找到可以整除而且 ' 除數 小於 要 ( 檢查的數 /2) if remainder of number/divider is 0 ' 可以整除 set prime = false ' 確定不是質數 else set divider = divider + 1 ' 除數加 1 if (prime) print number set number = number + 1