联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2020-12-01 10:45

DATA STRUCTURES AND ALGORITHM ANALYSIS

COMP 3804

Assignment 3

Date Due: Friday, Nov 27, 2020

Time Due: 6pm

Your assignment should be typed and submitted online on CuLearn. You should upload a pdf file on CuLearn.

All questions are of equal value.

1. Suppose you want to place fast food restaurants at various locations along a highway. For simplicity, let

us model the highway as the X-axis. You have a list of potential locations for the fast food restaurants

x1, x2, . . . , xn. For simplicity, you may assume x1 < x2 < . . . < xn. For each location, you have an estimated

revenue r1, r2, . . . , rn. However, for environmental reasons, the distance between two fast food restaurants

must be at least 20 kilometers, that is for two consecutive fast food restaurants xi and xj , we must have

xj − xi ≥ 20. Design a placement algorithm that will optimize your estimated revenue. For example, if your

possible fast food restaurant locations are (2, 17, 24, 32, 48), and your estimated revenue is (9, 22, 11, 2,

12), then your optimal placement is one fast food restaurant at location 17 and one at 48 which gives you an

estimated revenue of 22+12=34. It is possible to place a fast food restaurant at locations 2, 24, 48 however,

that only gives you an estimated revenue of 9+11+12 = 32 which is less revenue. However, if your estimated

revenue is (9, 22, 14, 2, 12), that is the revenue of location 24 is 14 instead of 11, then the optimal solution

would be to place the fast food restaurants at 2, 24, 48.

(a) Design an algorithm to find a placement that maximizes revenue.

(b) Prove your algorithm is correct.

(c) Analyze the run time of your algorithm. For full marks, your algorithm should run in O(n) time.

2. In class, we saw how given two strings x = x1x2 . . . xn and y = y1y2 . . . ym, we can find the longest common

substring. For example, if x = 9, 2, 8, 3, 7, 4, 1 and y = 2, 3, 9, 6, 8, 5, 7, 1, 4 then the longest common substring

is 9, 8, 7, 1. However, suppose we want to compute the longest one that is also increasing, which in this case

would be 2, 3, 4. Design an algorithm to compute this. (Hint: We also saw in class how to compute the longest

increasing subsequence using Dynamic Programming. You need to figure out how to combine the ideas in both

algorithms to compute this).

(a) Design the algorithm.

(b) Prove your algorithm is correct.

(c) Analyze the run time of your algorithm. For full marks, your algorithm should run in polynomial time.

3. Let G = (V, E) be an undirected graph. Let s, t ∈ V be a pair of vertices such that the length of the shortest

path from s to t in G has length greater than |V |/2, i.e. the number of edges in this path is greater than |V |/2.

Prove or disprove that there must exist a vertex v ∈ V − {s, t} such that the deletion of v disconnects G.

4. Let G = (V, E) be a simple connected graph. Let T be the tree that results when you run DFS on G from a

vertex v ∈ V . Let T be the same tree that results when you run BFS on G from vertex v. Prove or disprove that

G = T.

1

COMP 3804 ASSIGNMENT 3 2

5. The chromatic number of a graph G is the smallest number of colors needed to color the vertices of G so that

no two adjacent vertices get the same color, (i.e., the minimum number k such that the vertices of G can be

colored with k colors so that no two adjacent vertices get the same color). For example, a bipartite graph has

chromatic number 2. The length of a cycle in a graph is the number of edges (i.e. vertices) on that cycle. For

any cycle C, let its length be denoted by |C|.

(a) Let G be a graph. Suppose the following is true for G: for any two cycles C1 and C2 in G, if |C1| is odd

and |C2| is odd then C1 and C2 have a vertex in common. Prove that such a graph G can be colored with

at most five colors.

(b) Explain how you can use DFS or BFS to find such a 5 coloring of the vertices. The runtime of your

algorithm should not exceed the runtime of DFS or BFS.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp