Skip to content

Commit 00abc34

Browse files
Ln16.字符串编辑距离 (#40)
* 字符串编辑距离的图片文件2张 * 字符串编辑距离tex文件 * 修改makefile * 修改book.tex * Update LN16.tex * try to fix * fix math env Co-authored-by: wangnengjie <751614701@qq.com>
1 parent dc249cf commit 00abc34

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ TEX=\
77
$(SRC)/Ln9-NearestPoints.tex\
88
$(SRC)/Ln11-LargeIntegerMultiplication.tex\
99
$(SRC)/dynamic-programming-1.tex\
10+
$(SRC)/LN16.tex\
1011
$(SRC)/Ln17-DP-ShortestPath.tex\
1112
$(SRC)/Ln18-DP-ZeroOneKnapsack.tex\
1213
$(SRC)/Ln19-DP-ContextFreeGrammar.tex\
@@ -16,7 +17,7 @@ TEX=\
1617
$(SRC)/Ln06-MST.tex\
1718
$(SRC)/Ln07-redblue.tex\
1819
$(SRC)/Ln26-P-NP.tex\
19-
$(SRC)/Proof-of-Statute\
20+
$(SRC)/Proof-of-Statute.tex\
2021

2122
all: book.pdf
2223
.PHONY: all clean dev clean-all

book.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
\input{src/Ln9-NearestPoints.tex}
4747
\input{src/Ln11-LargeIntegerMultiplication.tex}
4848
\input{src/dynamic-programming-1.tex}
49+
\input{src/LN16.tex}
4950
\input{src/Ln17-DP-ShortestPath.tex}
5051
\input{src/LN18-DP-ZeroOneKnapsack.tex}
5152
\input{src/Ln19-DP-ContextFreeGrammar.tex}

image/connect1.png

5.15 KB
Loading

image/connect2.png

9.46 KB
Loading

src/LN16.tex

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
\chapter{字符串编辑距离}
2+
3+
\begin{introduction}
4+
\item 问题引入
5+
\item 相关概念
6+
\item 算法思想
7+
\end{introduction}
8+
9+
\section{问题引入}
10+
如何定义两个字符串的距离呢?ocurrance和occrrence有多大的区别呢?下面我们将讨论两个字符串的距离问题。
11+
\section{相关概念}
12+
\begin{definition}{匹配M}{matching}
13+
字符串X有$x_1$$x_n$共n个字符,字符串Y有$y_1$$y_m$共m个字符。X和Y之间存在一个匹配M,其满足:$if (i,j) \in M, (l,k)\in M, i<l iff j<k$
14+
\end{definition}
15+
16+
%距离代价:
17+
18+
%$\alpha_{xy}$ :两个不同的字符x和y相匹配的代价,则$\alpha_{xy}=0$.
19+
20+
%$\delta$ :每存在一个没有被选择的字符就会多一个$\delta$.
21+
22+
%总距离代价:所有$\delta$ 和 $\alpha$ 的和。
23+
24+
\begin{definition}{距离代价}{penalty}
25+
$\alpha_{xy}$:两个不同的字符x和y相匹配的代价,则$\alpha_{xy}=0$.
26+
27+
$\delta$:每存在一个没有被选择的字符就会多一个$\delta$.
28+
29+
总距离代价:所有$\delta$$\alpha$ 的和。
30+
\end{definition}
31+
32+
示例:
33+
34+
\begin{figure}[htb]
35+
\centering
36+
\includegraphics[scale=0.6]{image/connect1.png}
37+
\caption{字符串匹配}\label{fig:connect1}
38+
\end{figure}
39+
如上图所示,其中的总距离代价为$\alpha_{ae} + \delta$
40+
41+
\section{算法思想}
42+
从后往前推:
43+
44+
bopt (i,j):字符串$x_1,\ldots,x_i$$y_1,\ldots,y_j$之间的最佳匹配
45+
\begin{equation}
46+
bopt (m,n)=\begin{cases}
47+
bopt(m-1,n-1)+\alpha_{x_m y_n} & \text{$x_m$$y_n$ 相连} \\
48+
bopt (m-1,n)+\delta & \text{$x_m$跳过} \\
49+
bopt (m,n-1)+\delta & \text{$y_n$跳过}
50+
\end{cases}
51+
\end{equation}
52+
53+
从前往后推:
54+
55+
fopt (i,j):字符串$x_i,\ldots,x_m$
56+
57+
$y_j,\ldots,y_n$
58+
之间的最佳匹配
59+
\begin{equation}
60+
fopt (1,1)=\begin{cases}
61+
fopt(2,2)+\alpha_{x_1 y_1} & \text{$x_1$$y_1$ 相连} \\
62+
fopt (2,1)+\delta & \text{$x_1$跳过} \\
63+
fopt (1,2)+\delta & \text{$y_1$跳过}
64+
\end{cases}
65+
\end{equation}
66+
初始化:
67+
$bopt (i,0) = \delta_i $ $bopt (0,i) = \delta_j$
68+
69+
构造图:
70+
71+
\begin{figure}[htb]
72+
\centering
73+
\includegraphics[scale=0.6]{image/connect2.png}
74+
\caption{构造图}\label{fig:connect2}
75+
\end{figure}
76+
按图构造方法如图所示

0 commit comments

Comments
 (0)