0% found this document useful (0 votes)
82 views

Problem Solving and Algorithm Design: Nell Dale - John Lewis

This document summarizes the goals of Chapter 6 which include determining if a problem can be solved by a computer, describing the problem-solving process, distinguishing between following and developing algorithms, and applying top-down and object-oriented design methodologies. It then discusses key aspects of problem solving like Polya's "How to Solve It" list, algorithms, pseudocode, testing algorithms, and information hiding.

Uploaded by

pangdownloadlang
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Problem Solving and Algorithm Design: Nell Dale - John Lewis

This document summarizes the goals of Chapter 6 which include determining if a problem can be solved by a computer, describing the problem-solving process, distinguishing between following and developing algorithms, and applying top-down and object-oriented design methodologies. It then discusses key aspects of problem solving like Polya's "How to Solve It" list, algorithms, pseudocode, testing algorithms, and information hiding.

Uploaded by

pangdownloadlang
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

Chapter 6

Problem Solving
and Algorithm Design
Nell Dale John Lewis
Chapter Goals

Determine whether a problem is suitable for a


computer solution
Describe the computer problem-solving process
and relate it to Polyas 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

62
Chapter Goals (cont.)

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

63
Problem Solving

Problem solving is the act of finding a


solution to a perplexing, distressing,
vexing, or unsettled question

64
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

65
Ask Questions...

to understand the problem


What do I know about the problem?
What is the information that I have to process in
order the 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?
66
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

67
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

68
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

69
Computer Problem-Solving

Figure 6.2 The computer problem-solving process

610
Figure 6.3: The Interactions
Between Problem-Solving Phases

611
Pseudocode

Uses a mixture of English and formatting


to make the steps in the solution explicit

Page 149

612
Following an Algorithm

Preparing a Hollandaise sauce

Figure 6.4
613
Following an Algorithm (cont.)

Preparing a Hollandaise sauce

Page 150

614
Developing an Algorithm

The plan must be suitable in a suitable


form
Two methodologies that currently used
Top-down design
Object-oriented design

615
Top-Down Design

Breaking the problem into a set of


subproblems called modules
Creating a hierarchical structure of
problems and subproblems

616
Top-Down Design

Figure 6.5
An example
of 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

617
A General Example

Planning a large party

Figure 6.6 Subdividing the party planning


618
A Computer Example

Problem
Create an address list that includes each
persons name, address, telephone number,
and e-mail 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

619
A Computer Example

Page 156

620
A Computer Example

Page 157
621
A Computer Example

Page 158
622
A Computer Example

Page 159
623
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

624
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

625
Object-Oriented Design

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

626
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

627
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

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

629
CRC Cards

Page 165

630
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

631
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 dont
belong in the problem solution

632
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

633
Responsibility Algorithms

The algorithms must be written for the


responsibilities
Knowledge responsibilities usually just return
the contents of one of an objects variables
Action responsibilities are a little more
complicated, often involving calculations

634
Computer Example

Lets repeat the problem-solving process


for creating an address list
Brainstorming and filtering
Circling the nouns and underlining the verbs

Page 171
635
Computer Example

First pass at a list of classes

Page 172
Computer Example

Filtered list

Page 172
CRC Cards

Page 173

638
Responsibility Algorithms

Page 175
639
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

640
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

641
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

642
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

643

You might also like