Logical re-use of computations
600.325/425 Declarative Methods - J.
Dynamic Programming is a general algorithm design
Invented by American mathematician Richard Bellman in the
1950s to solv
SORTING IN LINER TIME
The sorting algorithms we have seen
so far (insertion sort, merge sort,
quick sort, heap sort) are called
They only use comparisons to find
the order of elements.
The fastest worst-case running time
among these a
Background: Binary Trees
Has a root at the topmost level
Each node has zero, one or two
A node that has no child is
called a leaf
For a node x, we denote the
left child, right child and the
parent of x as left(x), right(x)
and parent(x), resp
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 SHORTEST
Find shortest path to a given
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: spreadsheet or database
Computers sort thi
Insertion Sort Demo
Given an array of N integers, rearrange them so that they are in
Brute-force sorting solution.
Move left-to-right through array.
Exchange next element with larger elements to its left,
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 function
but can take different amounts of time a1, j and a2
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 programming
(2) Items are divisible: you can take any frac
An algorithm is a finite sequence of step by step,
discrete, unambiguous instructions for solving a
has input data, and is expected to produce output data
each instruction can be carried out in a finite amount of
time in a