Algorithms and Problem Solving1 - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Algorithms and Problem Solving1

Description:

... 'Computer Science Illuminated' by Nell Dale and John Lewis. ... A little humor can be ... responsibilities are a little more complicated, often involving ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 36
Provided by: QuaziAbid5
Category:

less

Transcript and Presenter's Notes

Title: Algorithms and Problem Solving1


1
Algorithms and Problem Solving
  • Mainly based on Chapter 6 Problem Solving and
    Algorithm Design from the Book Computer
    Science Illuminated by Nell Dale and John Lewis.

2
Objectives
  • 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
  • Apply the object-oriented design methodology to
    develop a collection of interacting objects to
    solve a problem

3
Problem Solving
  • Problem solving is the act of finding a solution
    to a perplexing, distressing, vexing, or
    unsettled question

4
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

5
Problem Solving and Algorithms
  • Ask questions to understand the problem
  • Look for familiar things
  • Divide and conquer
  • Test your solution

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 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?

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

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

9
Algorithms
  • An algorithm is defined as a finite set of steps,
    each of which may require one or more operations
    and if carried out on a set of inputs, will
    produce one or more outputs after a finite amount
    of time.

10
The Computer Problem-Solving Process
11
Pseudocode
  • Uses a mixture of English and formatting to make
    the steps in the solution explicit

12
Following an Algorithm
  • Preparing a Hollandaise sauce

13
Following an Algorithm (cont.)
  • Preparing a Hollandaise sauce

Page 150
14
Developing an Algorithm
  • The plan must be suitable in a suitable form
  • Two methodologies that are currently in use
  • Top-down design
  • Object-oriented design

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

16
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

17
A General Example
  • Planning a large party

18
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

19
A Computer Example
20
A Computer Example
21
A Computer Example
22
A Computer Example
23
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

24
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

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

26
CRC Cards
27
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

28
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

29
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

30
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

31
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
32
Computer Example
  • First pass at a list of classes

33
Computer Example
  • Filtered list

34
CRC Cards
35
Responsibility Algorithms
Write a Comment
User Comments (0)
About PowerShow.com