Administrative, Dynamic Programming, Course Evaluations | CS 361L, Study Guides, Projects, Research of Computer Science

Material Type: Project; Class: Data Structures and Algorithms; Subject: Computer Science; University: University of New Mexico; Term: Fall 2005;

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 07/23/2009

koofers-user-ujp
koofers-user-ujp 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 361, Lecture 26
Jared Saia
University of New Mexico
Outline
Administrative
Dynamic Programming
Course Evaluations
1
Administrative
The project is due this Thursday in class.
This deadline is strict - late projects will recieve no credit. (A
partially completed project turned in on time will get some
credit but a complete project turned in late will get no credit)
2
Project Deliverables
Each Group should turn in one project consisting of:
About 6-12 pages of text and figures
6-12 figures (please put multiple figures on one page where
possible)
Task list giving which tasks were performed by which group
members if appropriate. This should b e signed by all mem-
bers of the group.
3
pf3
pf4
pf5

Partial preview of the text

Download Administrative, Dynamic Programming, Course Evaluations | CS 361L and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CS 361, Lecture 26

Jared Saia

University of New Mexico

Outline

Administrative

Dynamic Programming

Course Evaluations

Administrative

The project is due this Thursday in class.

credit but a complete project turned in late will get no credit)partially completed project turned in on time will get someThis deadline is strict - late projects will recieve no credit. (A

Project Deliverables

Each Group should turn in one project consisting of:

About 6-12 pages of text and figures

possible)6-12 figures (please put multiple figures on one page where

members if appropriate.Task list giving which tasks were performed by which group

This should be signed by all mem-

bers of the group.

Project Deliverables

Each

individual

should turn in the following:

An

evaluation

of the contribution to the group project of

cellent).every member of your group on a scale of 1(poor) to 10(ex-

To do this, write down the name of each member

of your group (including yourself),

and put a number be-

tween 1 and 10 next to each name.

Please be honest and

professional in your evaluation.

Your evaluation will be one

of your group.factor used to determine the project grade for each member

Project Comments

Before you turn in the project:

Reread “The Top

n

Project Mistakes” section in the project

description section on the course web page

You will loose points if you make these same mistakes

Dynamic Programming

the following way: Dynamic Programming is different than Divide and Conquer in

bines solutions to solve original problemproblems, solves the subproblems recursively and then com-“Divide and Conquer” divides problem into independent sub-

independent, i.e. the subproblems share subsubproblemsDynamic Programming is used when the subproblems are not

work than necessaryFor these kinds of problems, divide and conquer does more

saves the answer in a table for future referenceDynamic Programming solves each subproblem once only and

The Pattern

Formulate the problem recursively.

. Write down a formula

smaller subproblemsfor the whole problem as a simple combination of answers to

sidering the intermediate subproblems in the correct order.recurrence and works its way up to the final solution by con- Write an algorithm that starts with the base cases of yourBuild solutions to your recurrence from the bottom up.

problems. This is frequentlyNote: Dynamic Programs store the results of intermediate sub-

but not always

done with some type

of table.

Key Observation

remaining alignment must also be optimalIf we remove the last column in an optimal alignment, the

subalignment of all but the last column.Easy to prove by contradiction: Assume there is some better

Then we can just

a better overall alignment.paste the last column onto this better subalignment to get

Note:

The last column can be either:

  1. a blank on top

aligned with a character on bottomaligned with a blank on bottom or 3) a character on topaligned with a character on bottom, 2) a character on top

DP Solution

find a recursive definitionTo develop a DP algorithm for this problem, we first need to

Assume we have a

m

length string

A

and an

n

length string

B

Let

E

i, j

) be the edit distance between the first

i characters

of

A

and the first

j

characters of

B

Then what we want to find is

E

n, m

Recursive Definition

Say we want to compute

E

i, j

) for some

i

and

j

tion toFurther say that the “Recursion Fairy” can tell us the solu-

E

i ′ , j

), for all′

i ′ ≤

i ,

j ′ ≤

j ,

except

for

i ′ =

i

and

j ′ =

j

Q: Can we compute

E

i, j

) efficiently with help from the our

fairy friend?

Recursive Definition

There are three possible cases:

Insertion:

E

i, j

E

i (^) −

, j

)

Deletion:

E

i, j

E

i, j

Substitution:

If

a i =

b j , E

( i, j

E

i −

1 , j

1), else

E

i, j

E

i (^) −

, j

Summary

Let

I

A

[

i ] 6 =

B

[

j ]) = 1 if

A

[

i ] and

B

[

j ] are different, and 0 if they

are the same. Then:

E

i, j

) = min

  

E

i (^) −

, j

) + 1

E

i, j

E

i (^) −

, j

I

A

[

i ] 6 =

B

[

j ])

  

Base Case(s)

It’s not too hard to see that:

E

(

, j

) =

j

for all

j , since the

j

characters of

B

must be

aligned with blanks

Similarly,

E

i, (^) 0) =

i

for all

i

Recursive Alg

gorithmWe now have enough info to directly create a recursive al-

the following recurrence:The run time of this recursive algorithm would be given by

T

m,

T

, n

O

T

m, n

T

m, n

T

m

(^) −

(^1)

, n

T

n

(^1)

, m

O

Solution:

T

n, n

n ), which is terribly, terribly

slow.

Better Idea

We can build up a

m

×

n

table which contains all values of

E

i, j

in the 0-th row and 0-th columnWe start by filling in the base cases for this table: the entries

above, to the left and above and to the left.To fill in any other entry, we need to know the values directly

Thus we can fill in the table in the standard way:

left to

in each cell are always availableright and top down to ensure that the entries we need to fill

Reconstructing an optimal alignment

optimal alignmentIn this code, we do not keep info around to reconstruct the

to achieve the current cell’s minimum edit distancewhich stores, for each cell, a pointer to the cell that was usedHowever, it is a simple matter to keep around another array

pointers from the bottom rightTo reconstruct a solution, we then need only follow these

corner up

to the top left

corner

In Class Exercise

and “bab”.Create a string alignment table for the two strings “abba”

Put “abba” at the top of the table and “bab”

on the left side

Qi: (

i = 1

(^) 5) What is the

i -th row of your table

ments achieve it?Q6: What is the minimum edit distance and how many align-

Take Away

the recurrence from the bottom up1) formulated the problem recursively 2) built a solution toTo solve the string alignment problem, we did the following:

Dynamic Programming

We’ve seen a use of DP for the String Alignment Problem

tiplyMany other uses including: Finding the optimal way to mul-

matrices,

algorithms

for

scheduling

jobs,

finding

the

gorithm), etc.shortest paths in a graph, application in AI (the Viterbi al-

lem and then use memorization (i.e. we build a table)In all cases, we first find a recursive formulation of the prob-