Top Banner
Problem Decomposition and Abstraction
22

Problem Decomposition and Abstraction

Mar 23, 2016

Download

Documents

matana

Problem Decomposition and Abstraction. Problem Solving. Which one is easier: Solving one big problem, or Solving a number of small problems?. Problem Solving. Which one is easier: Solving one big problem, or Solving a number of small problems? - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Problem Decomposition  and Abstraction

Problem Decomposition and Abstraction

Page 2: Problem Decomposition  and Abstraction

Problem Solving

Which one is easier: Solving one big problem, or Solving a number of small problems?

Page 3: Problem Decomposition  and Abstraction

Problem Solving

Which one is easier: Solving one big problem, or Solving a number of small problems?

What are the advantages of small problems?

Page 4: Problem Decomposition  and Abstraction

Problem Solving

Which one is easier: Solving one big problem, or Solving a number of small problems?

What are the advantages of small problems? Easier to solve Easier to ensure the solution is correct

In order to have a number of small problems What do we need to do first?

Page 5: Problem Decomposition  and Abstraction

Common Mistake

Dive into the details (e.g. at the level of Java instructions)

Do not consider decomposing the problem first “in English”

Page 6: Problem Decomposition  and Abstraction

Tic-tac-toe

We would like to build a tic-tac-toe game that a human can play against another

How would you decompose the problem?

Page 7: Problem Decomposition  and Abstraction

Problem Decomposition

1. Display the board2. Make a move3. Decide winner

Can these smaller problems be independently solved? tested?

Page 8: Problem Decomposition  and Abstraction

Decide Winner

Seems to be complicated, what can we do?

Page 9: Problem Decomposition  and Abstraction

Decide Winner

Seems to be complicated, what can we do? Decompose!

Page 10: Problem Decomposition  and Abstraction

Decide Winner

Seems to be complicated, what can we do? Decompose!

a. Check 3 rowsb. Check 3 columnsc. Check 2 diagonals

Can they be independently Solved? Tested?

Page 11: Problem Decomposition  and Abstraction

Top-down Decomposition

1. Display the board2. Make a move3. Decide winner

a. Check 3 rowsb. Check 3 columnsc. Check 2 diagonals

Page 12: Problem Decomposition  and Abstraction

Make a Move

Decompose:

Page 13: Problem Decomposition  and Abstraction

Make a Move

Decompose: Ask for a move Update the board

Page 14: Problem Decomposition  and Abstraction

Top-down Decomposition

1. Display the board2. Make a move

a. Ask for a moveb. Update the board

3. Decide winnera. Check 3 rowsb. Check 3 columnsc. Check 2 diagonals

Two levels of abstraction

Page 15: Problem Decomposition  and Abstraction

When to stop decomposing a problem?

Page 16: Problem Decomposition  and Abstraction

When to stop decomposing a problem?

Until you’re confident you can solve the smaller problems correctly Different for different people

Page 17: Problem Decomposition  and Abstraction

Make a Move

Recall there are two human players

Who makes a move?

Page 18: Problem Decomposition  and Abstraction

Make a Move

Do we want To break it down to

2 smaller problems, each for a player

One problem that is flexible for the 2 players

?

Page 19: Problem Decomposition  and Abstraction

Make a Move

Do we want To break it down to

2 smaller problems, each for a player

One problem that is flexible for the 2 players

Prefer one problem that is flexible for 2 situations The 2 smaller problems are very similar Solving 2 similar problems is tedious

Rewriting almost the same instructions

Page 20: Problem Decomposition  and Abstraction

Make a Move

makeAMove(player) Similar to sqrt(x) makeAMove can be used with different players

Problem abstraction via parameters

Page 21: Problem Decomposition  and Abstraction

Summary

Problem decomposition Top-down

Decompose until you’re confident you can solve the small problems correctly.

Page 22: Problem Decomposition  and Abstraction

Summary

Problem decomposition Top-down

Decompose until you’re confident you can solve the small problems correctly.

Problem abstraction Different levels of abstraction in top-down

decomposition More general to more specific

Increase abstraction via parameters Allow the solution to be reused in different situations Avoid repeatedly writing almost the same instructions