Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Homework 3 Questions - Design and Analysis of Algorithm | CSCI 212, Assignments of Computer Science

Material Type: Assignment; Professor: Choi; Class: Design & Analysis of Algorithm; Subject: Computer Science; University: George Washington University; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-81q-1
koofers-user-81q-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
George Washington University
Department of Computer Science
Csci 212 - Homework 3
Due date: April 23, 2009
Email to bowuzh@gwmail.gwu.edu by 11:59PM or submit to CS Dept by 5PM.
1. Given a sequence of nreal numbers A(1),· · · , A(n), give a dynamic programming algorithm
to determine a contiguous subsequence A(i),· · · , A(j) for which the sum of elements in the
subsequence is maximized. Analyze the time complexity of your algorithm.
2. You are given ntypes of coin denominations of values v(1) < v(2) <· · · < v (n) (all integers).
Assume v(1) = 1, so you can always make change for any amount of money C. Give a
dynamic programming algorithm which makes change for a given amount of money Cwith
as few coins as possible. Analyze the time complexity of your algorithm.
3. Given a sequence of nreal numbers A(1),· · · , A(n), Give a dynamic programming algorithm to
determine a subsequence (not necessarily contiguous) of maximum length in which the values
in the subsequence form a strictly increasing sequence. Analyze the time complexity of your
algorithm.
4. Consider a 2-D map with a horizontal river passing through its center. There are ncities on the
southern bank with x-coordinates a(1),· · · , a(n) and ncities on the northern bank with x-
coordinates b(1),· · · , b(n). You want to connect as many north-south pairs of cities as possible
with bridges such that no two bridges cross. When connecting cities, you can only connect
city ion the northern bank to city ion the southern bank. Give a dynamic programming
algorithm to solve this problem and analyze the time complexity of your algorithm.
5. You have a set of nintegers each in the range 0,···, K. Partition these integers into two subsets
such that you minimize |S1S2|, where S1and S2denote the sums of the elements in each of
the two subsets. Give a dynamic programming algorithm to solve this problem and analyze
the time complexity of your algorithm.
6. Given two text strings Aof length nand Bof length m, you want to transform Ainto B
with a minimum number of operations of the following types: delete a character from A,
insert a character into A, or change some character in Ainto a new character. The minimal
number of such operations required to transform Ainto Bis called the edit distance between
Aand B. Give a dynamic programming algorithm to solve this problem and analyze the time
complexity of your algorithm.
7. You are given a boolean expression consisting of a string of the symbols ’true’, ’false’, ’and’,
’or’, and ’xor’. Count the number of ways to parenthesize the expression such that it will
evaluate to true. For example, there is only 1 way to parenthesize ’true and false xor true’
such that it evaluates to true. Give a dynamic programming algorithm to solve this problem
and analyze the time complexity of your algorithm.
pf2

Partial preview of the text

Download Homework 3 Questions - Design and Analysis of Algorithm | CSCI 212 and more Assignments Computer Science in PDF only on Docsity!

George Washington University Department of Computer Science Csci 212 - Homework 3

Due date: April 23, 2009 Email to bowuzh@gwmail.gwu.edu by 11:59PM or submit to CS Dept by 5PM.

  1. Given a sequence of n real numbers A(1), · · · , A(n), give a dynamic programming algorithm to determine a contiguous subsequence A(i), · · · , A(j) for which the sum of elements in the subsequence is maximized. Analyze the time complexity of your algorithm.
  2. You are given n types of coin denominations of values v(1) < v(2) < · · · < v(n) (all integers). Assume v(1) = 1, so you can always make change for any amount of money C. Give a dynamic programming algorithm which makes change for a given amount of money C with as few coins as possible. Analyze the time complexity of your algorithm.
  3. Given a sequence of n real numbers A(1), · · · , A(n), Give a dynamic programming algorithm to determine a subsequence (not necessarily contiguous) of maximum length in which the values in the subsequence form a strictly increasing sequence. Analyze the time complexity of your algorithm.
  4. Consider a 2-D map with a horizontal river passing through its center. There are n cities on the southern bank with x-coordinates a(1), · · · , a(n) and n cities on the northern bank with x- coordinates b(1), · · · , b(n). You want to connect as many north-south pairs of cities as possible with bridges such that no two bridges cross. When connecting cities, you can only connect city i on the northern bank to city i on the southern bank. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.
  5. You have a set of n integers each in the range 0, · · · , K. Partition these integers into two subsets such that you minimize |S 1 − S 2 |, where S 1 and S 2 denote the sums of the elements in each of the two subsets. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.
  6. Given two text strings A of length n and B of length m, you want to transform A into B with a minimum number of operations of the following types: delete a character from A, insert a character into A, or change some character in A into a new character. The minimal number of such operations required to transform A into B is called the edit distance between A and B. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.
  7. You are given a boolean expression consisting of a string of the symbols ’true’, ’false’, ’and’, ’or’, and ’xor’. Count the number of ways to parenthesize the expression such that it will evaluate to true. For example, there is only 1 way to parenthesize ’true and false xor true’ such that it evaluates to true. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.
  1. You are given an ordered sequence of n cities, and the distances between every pair of cities. You must partition the cities into two subsequences (not necessarily contiguous) such that person A visits all cities in the first subsequence (in order), person B visits all cities in the second subsequence (in order), and such that the sum of the total distances traveled by A and B is minimized. Assume that person A and person B start initially at the first city in their respective subsequences. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.
  2. You have n 1 items of size s 1 , n 2 items of size s 2 , and n 3 items of size s 3. You’d like to pack all of these items into bins each of capacity C, such that the total number of bins used is minimized. Give a dynamic programming algorithm to solve this problem and analyze the time complexity of your algorithm.

10 Given an matrix of integers, you are to write a program that computes a path of minimal weight. A path starts anywhere in column 1 (the first column) and consists of a sequence of steps terminating in column n (the last column). A step consists of traveling from column i to column i+1 in an adjacent (horizontal or diagonal) row. The first and last rows (rows 1 and m) of a matrix are considered adjacent, i.e., the matrix “wraps” so that it represents a horizontal cylinder. For example, a move from cell (1, 1) to cell (m, 2) is legal. Legal steps are illustrated in Figure 1.

Figure 1:

The weight of a path is the sum of the integers in each of the n cells of the matrix that are visited. For example, two slightly different 5 × 6 matrices are shown in Figure 2 (the only difference is the numbers in the bottom row). The minimal path is illustrated for each matrix. Note that the path for the matrix on the right takes advantage of the adjacency property of the first and last rows. Design an dynamic programming algorithm to solve this problem.

Figure 2: