Dynamic Programming
Logical re-use of computations
use
600.325/425 Declarative Methods - J.
Eisner
1
Dynamic Programming
Dynamic Programming is a general algorithm design
technique.
Invented by Amer
SORTING IN LINER TIME
The sorting algorithms we have seen
so far (insertion sort, merge sort,
quick sort, heap sort) are called
comparison sorts.
They only use comparisons to find
the order of eleme
Background: Binary Trees
Has a root at the topmost level
Each node has zero, one or two
children
A node that has no child is
called a leaf
For a node x, we denote the
left child, right child and t
VARIANTS OF SHORTEST PATH PROBLEM
SINGLE SOURCE SHORTEST PATH
Find the shortest path from a given
source vertex s to every other vertex
v used in the graph(Used in routers)
SINGLE DESTINATION SHORTES
Why we do sorting?
Searching for an element in an array will be
more efficient. (example: looking up for
information like phone number).
Its always nice to see data in a sorted display.
(example: sp
Insertion Sort Demo
Sorting problem:
Given an array of N integers, rearrange them so that they are in
increasing order.
Insertion sort
Brute-force sorting solution.
Move left-to-right through array.
E
Assembly Line Scheduling
Automobile factory with two assembly lines
Each line has n stations: S1,1, . . . , S1,n and S2,1, . . . , S2,n
Corresponding stations S1, j and S2, j perform the same funct
Knapsack problem
There are two versions of the problem:
(1) 0-1 knapsack problem and
(2) Fractional knapsack problem
(1) Items are indivisible; you either take an item or not.
Solved with dynamic pro
Definition
An algorithm is a finite sequence of step by step,
discrete, unambiguous instructions for solving a
particular problem
has input data, and is expected to produce output data
each instruc