Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem Decomposition and Abstraction. Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems?

Similar presentations


Presentation on theme: "Problem Decomposition and Abstraction. Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems?"— Presentation transcript:

1 Problem Decomposition and Abstraction

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

3 Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems? What are the advantages of small problems?

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

5 Common Mistake Dive into the details  (e.g. at the level of Java instructions) Do not consider decomposing the problem first  “in English”

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

7 Problem Decomposition 1. Display the board 2. Make a move 3. Decide winner Can these smaller problems be independently  solved?  tested?

8 Decide Winner Seems to be complicated, what can we do?

9 Decide Winner Seems to be complicated, what can we do?  Decompose!

10 Decide Winner Seems to be complicated, what can we do?  Decompose! a. Check 3 rows b. Check 3 columns c. Check 2 diagonals  Can they be independently  Solved?  Tested?

11 Top-down Decomposition 1. Display the board 2. Make a move 3. Decide winner a. Check 3 rows b. Check 3 columns c. Check 2 diagonals

12 Make a Move Decompose:

13 Make a Move Decompose:  Ask for a move  Update the board

14 Top-down Decomposition 1. Display the board 2. Make a move a. Ask for a move b. Update the board 3. Decide winner a. Check 3 rows b. Check 3 columns c. Check 2 diagonals Two levels of abstraction

15 When to stop decomposing a problem?

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

17 Make a Move Recall there are two human players Who makes a move?

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

19 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

20 Make a Move makeAMove(player)  Similar to sqrt(x)  makeAMove can be used with different players Problem abstraction  via parameters

21 Summary Problem decomposition  Top-down  Decompose until you’re confident you can solve the small problems correctly.

22 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


Download ppt "Problem Decomposition and Abstraction. Problem Solving Which one is easier:  Solving one big problem, or  Solving a number of small problems?"

Similar presentations


Ads by Google