Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jamil Saquer and Razib Iqbal Computer Science Department

Similar presentations


Presentation on theme: "Jamil Saquer and Razib Iqbal Computer Science Department"— Presentation transcript:

1 A Dynamic Programing Based Solution to the Two-Dimensional Jump-It Problem
Jamil Saquer and Razib Iqbal Computer Science Department Missouri State University Springfield, MO

2 Introducing the problem
2D board with a cost to visit each cell A player starts at the top-left cell and wants to reach the bottom-right (exit) cell with the lowest cost Allowed moves: one cell to the right one cell below jump over one cell to the right Jump over one cell below 5 7 2 4 8 1 6 3 9

3 Possible Paths 5 7 2 4 8 1 6 3 9 5 7 2 4 8 1 6 3 9 cost = = 20 cost = = 29 5 7 2 4 8 1 6 3 9 cost = = 18

4 Goal Find the cheapest cost of playing the game
Find path that leads to playing the game with the cheapest cost

5 Review – 1D Jump-It 5 15 75 7 43 11

6 Review – 1D Jump-It solution: if board length == 1, visit that cell 5
start solution: if board length == 1, visit that cell 5 15 75 7 43 11

7 Review – 1D Jump-It solution: if board length == 1, visit that cell
start solution: if board length == 1, visit that cell if board length == 2, visit both cells 5 15 75 7 43 11

8 Review – 1D Jump-It solution: if board length == 1, visit that cell
start solution: if board length == 1, visit that cell if board length == 2, visit both cells if board length == 3, cheaper to jump over 5 15 75 7 43 11

9 Review – 1D Jump-It solution: if board length == 1, visit that cell
start solution: if board length == 1, visit that cell if board length == 2, visit both cells if board length == 3, cheaper to jump over else min_cost = board[i] min{jumpIt(i+1), jumpIt(i+2)} 5 15 75 7 43 11

10 2D Jump-It Finding the Cheapest Cost
Let jumpIt(r, c) be the cheapest cost of playing the game starting at any cell (r, c) Many cases 5 7 2 4 8 1 6 3 9

11 Finding the Cheapest Cost
5 7 2 4 8 1 6 3 9

12 Finding the Cheapest Cost
5 7 2 4 8 1 6 3 9

13 Dynamic Programming Solution
2D jump-It is a good candidate for DP Overlapping sub-problems Optimal sub-structure

14 Top-Down DP Solution board[i][j] contains cost of visiting cell (i, j)
costs – a cache table for storing solutions costs[i][j] minimum cost starting game at cell (i, j) fill cache table starting with basic cases 5 7 2 4 8 1 6 3 9 costs board

15 Top-Down DP Solution costs board fill last row starting
fill in last column fill the row before last fill the column before last fill rest of cache table 18 18 13 11 14 5 7 2 4 8 1 6 3 9 14 13 14 7 6 21 12 16 16 11 14 11 10 12 3 costs board

16 Finding Optimal path board costs path
Use another cache table, path, to remember moves path[i][j] - coordinates of cell visited after cell (i ,j) 1 2 3 4 5 7 2 4 8 1 6 3 9 18 18 13 11 14 14 13 14 7 6 1 21 12 16 16 11 2 14 11 10 12 3 3 board costs (0, 2) (0, 3) (0, 3) (1, 3) (1, 4) 1 (1,1) (1, 3) (1, 4) (1, 4) (3, 4) 2 (2, 1) (3, 1) (3, 2) (2, 4) (3, 4) 3 (3, 2) (3, 2) (3,4) (3, 4) (-1,-1) 1 2 3 4 path

17 2D Jump-It in The CS Curriculum
Good problem to use when teaching DP

18 Questions


Download ppt "Jamil Saquer and Razib Iqbal Computer Science Department"

Similar presentations


Ads by Google