CSC645 - Chapter 6 - Dynamic Programming ADT

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/5

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

6 Terms

1
New cards

Dynamic Programming (DP) ADT Overview

  1. History / Definition

    • Invented by Mathematican , Richard E Ballman

    • The term “programming” actually refers to planning

  2. DP attempts to solve problems with overlapping subproblems (Rather than solve the same problem again & again, we store them in a table)

2
New cards

Dynamic Programming (DP) ADT DP Properties

  1. Overlapping sub-problems

    • → same sub-problem occur more than once

  2. Optimal substructure

    • → final solution = combination of optimal solution (from small solution, merge and get the final solution)

3
New cards

Overlapping sub-problems?

  • Solve 2 times or more DP attempts to solve problems with overlapping sub-problems

  • Eg: Fib (5)

Original solution:

 fun Fib(n)
 	if n=0|| n=1
 		return 1,
 	else return Fib(n-2) + Fib(n-1) 
DP ideas:
  • Just read from the table: • E.g. Fib(8)

4
New cards

DP: Transitive Closure (Warshal) War (2 pihak)

  1. Transitive closure means connectivity

  2. Is there a path for every node to all other nodes?

    • E.g. 1:

      • A can go to all node?

      • B can go to all node?

      • C can go to all node?

  3. DP algorithm that can solve this problem is *Warshal

Pseudo Code Warshal
  • E.g. 1

  • E.g. 2

  • E.g. 3

5
New cards

DP: All-Pair Shortest Path (Floyd Warshal)

  1. Finding the shortest path from any nodes to all other nodes.

  2. DP algorithm that can solve this problem is Floyd Warshall (Have weightage)

Pseudo Code Floyd Warshal
  • E.g. 1:

6
New cards

DP: Knapsack

  1. Choosing subset of n items that will fit a given constraints and yield maximum value.

Pseudo Code Knapsack
  • E.g.1

  • E.g.2