Coursera - Algorithm (Princeton) - 习题与解答 - Week 12

Week 12

Longest path and longest cycle

问题

Consider the following two problems

  • LongestPath: Given an undirected graph GG and two distinct vertices s s s and t t t, find a simple path (no repeated vertices) between s s s and t t t with the most edges.
  • LongestCycle: Given an undirected graph G’, find a simple cycle (no repeated vertices or edges except the first and last vertex) with the most edges.

Show that LongestPath linear-time reduces to LongestCycle.

分析

从路径到环,可以说是在环路是路径的完备情况(两条最长路径构成一个长环),也就是说后者是前者多找一条最长路径(环路问题一次调用,线性时间归约到路径问题)

3Sum and 4Sum

问题

Consider the following two problems:

  • 3Sum: Given an integer array a a a, are there three distinct indices i i i, j j j, and k k k such that a i + a j + a k = 0 a_i + a_j + a_k = 0 ai+aj+ak=0?
  • 4Sum: Given an integer array b b b, are there four distinct integers i i i, j j j, k k k, and ℓ \ell such that b i + b j + b k + b ℓ = 0 b_i + b_j + b_k + b_\ell = 0 bi+bj+bk+b=0?

Show that 3Sum linear-time reduces to 4Sum.

分析(非原创,未解决)

define M = 1 + max ⁡ i ∣ a i ∣ M = 1 + \max_i | a_i | M=1+maxiai. To solve an instance of 3Sum with N N N integers, form an instance of 4Sum with N + 1 N+1 N+1 integers containing only one negative value ( − 3 M -3M 3M).

3Sum and 3Linear

问题

Consider the following two problems:

  • 3Linear: Given an integer array a a a, are there three indices (not necessarily distinct) i i i, j j j, and k k k such that a i + a j = 8   a k a_i + a_j = 8 \, a_k ai+aj=8ak?
  • 3Sum: Given an integer array b b b, are there three indices (not necessarily distinct) i i i, j j j, and k k k such that b i + b j + b k = 0 b_i + b_j + b_k = 0 bi+bj+bk=0?

Show that 3Linear linear-time reduces to 3Sum.

分析(非原创,未解决)

define M = 1 + m a x i ∣ a i ∣ M=1+maxi|ai| M=1+maxiai. To solve an instance of 3Linear with n n n integers, form an instance of 3Sum with 2 n 2n 2n integers.

Feasibility detection

问题

Suppose that you want to solve a linear program but you don’t have a starting initial basic feasible solution—perhaps the all 0 vector is not feasible. Design a related linear program whose solution will be a basic feasible solution to the original linear program (assuming the original linear program has a basic feasible solution).

分析

貌似就是说全零向量并非可行解的问题

单纯形算法就是解决这个问题的,加入了松弛变量,初始条件就直接将所有可选变量置零,用松弛变量构造可行解,然后逐步用可选变量替换掉松弛变量

Detecting unboundedness

问题

Describe how to modify the simplex algorithm to detect an unbounded linear program—a linear program in which there is a feasible solution that makes the objective function arbitrarily large.

分析(非原创)

就是说可行解域无上限的情况

官方的解法我确实看不懂……

Birkhoff-von Neumann theorem

问题

Consider the polyhedron P P P defined by ∑ i x i j = 1 \sum_i x_{ij} = 1 ixij=1, ∑ j x i j = 1 \sum_j x_{ij} = 1 jxij=1, and x i j ≥ 0 x_{ij} \ge 0 xij0. Prove that all extreme points of P P P have integer coordinates (0 or 1).

分析

再见

Graph 3-colorability

问题

An undirected graph is 3-colorable if the vertices can be colored red, green, or blue in such a way that no edge connects two vertices with the same color. Prove that 3COLOR is NP-complete.

分析(官方)

give a polynomial-time reduction from 3SAT to 3COLOR by creating three vertices for each clause.

Decision problems

问题

Traditionally, the complexity classes P and NP are defined in terms of decision problems (where the answer is either yes or no) instead of search problems (where the answer is the solution itself). Prove that the search problem version of SAT (find a binary solution to a given system of boolean equations?) polynomial-time reduces to the decision version of SAT (does there exists a binary solution to a given system of boolean equations?).

分析(官方)

to determine whether to set x_1x1 to true, set it to true; simplify the resulting system of boolean equations; and check whether there exists a solution to the simplified system.

Optimization problems

问题

Given an undirected graph with positive edge weights, the traveling salesperson problem is to find a simple cycle that visits every vertex and has minimum total weight. The search problem version of the problem is, given a parameter LL, find a tour of length at most LL. Prove that the optimization version of the problem polynomial-time reduces to the search version of the problem.

Remark: for many problems such as this one, the optimization version of the problem (which is not known to be in NP) is solvable in polynomial time if and only if the search version of the problem (which is easily seen to be in NP) is.

分析(官方)

use binary search.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值