Myers的差异:为什么V [k − 1] <V [k + 1]保证选择其他D路径?

时间:2018-10-09 12:38:45

标签: algorithm diff cls

作为论文中的伪代码

4. If k = −D or k ≠ D and V[k − 1] < V[k + 1] Then
5. x ← V[k + 1]
6. Else
7. x ← V[k − 1]+1
8. y ← x − k

第4行表明,如果k不是-D或D,则取x较大的那个,而不是找出蛇。这让我感到困惑,我不应该同时计算v [k-1]和v [k + 1]并找出哪个路径更远吗?如果我选择一个较大的x作为起点,而事实证明我们的观点会引向更远的道路,该怎么办?

还有,据此:

  

即,进一步将(x',y’+ 1)(x“ + 1,y”)   对角线k,然后跟随对角线边缘,直到不再   可以这样做,或者直到达到编辑图的边界。

我认为作者建议(x',y'+ 1)和(x“ + 1,y”)(在这种情况下,v [k-1]和v [k + 1])都应进行计算。

那么我有什么想念的吗?

1 个答案:

答案 0 :(得分:0)

我认为论文缺少证明,这很简单,但是我认为缺失会导致一些混乱(对我而言),因此我在此提供此证明:

在第6页第4行中,代码如下:

 f k = −D or k ≠ D and V[k − 1] < V[k + 1] Then
    x ← V[k + 1]
 Else
    x ← V[k − 1]+1

我不认为lemma2会导致这种情况,lemma2的目的是证明可以使用贪婪策略解决此问题。根据{{​​1}},通常的方法是获取从Given the endpoints of the furthest reaching (D − 1)-paths in diagonal k+1 and k−1, say (x’,y’) and (x",y") respectively, Lemma 2 gives a procedure for computing the endpoint of the furthest reaching D-path in diagonal k. Namely, take the further reaching of (x’,y’+1) and (x"+1,y") in diagonal k and then follow diagonal edges until it is no longer possible to do so or until the boundary of the edit graph is reached.v[k - 1]延伸的两个点,并找出哪一条是更进一步的到达路径。但这将导致双重批评。这证明了为什么仅检查v[k + 1]有效的原因:

lemma4: 如果为V[k − 1] < V[k + 1],则路径v[k - 1] < v[k + 1]后面带有蛇形垂直边缘的路径将是对角线k的进一步重行路径。

证明: 让我们将v[k + 1]设为v[k - 1],将x1设为v[k + 1]。因此在对角线k中紧跟x2的点是x1(向右),紧跟(x1 + 1, x1 + 1 - k)的点是x2(向下); y位置在这里没有用。 然后问题变为:(x2, x2 - k)if x1 < x2, then x1 + 1 <= x2起 假设x1 < x2 -> x2 - x1 > 0,然后x1 + 1 > x2,因此x2 - x1 < 1。但是在编辑图中,基本移动为1,0 < x2 - x1 < 1永远不会发生,因此假设是错误的,因此0 < x2 - x1 < 1

我已在https://github.com/psionic12/Myers-Diff-in-c-/blob/master/README.md上发布了它和实现,欢迎您讨论。