Dynamic Programming Algorithm (DPA) for Edit-Distance

python 经典算法之--动态规划算法(Dynamic Programming Algorithm) 它通过将原问题分解为若干子问题,逐个求解子问题的最优解,从而得到原问题的最优解。= s2[j-1]时,dp[i][j] = max(dp[i-1][j], dp[i][j-1])。其中,dp[i-1][j]表示不选第i个物品,dp[i-1][j-w[i]]+v[i]表示选择第i个物品。当s1[i-1] == s2[j-1]时,dp[i][j] = dp[i-1][j-1] + 1;初始状态为dp[0][j] = 0和dp[i][0] = 0。初始状态为dp[i][0] = 0和dp[0][j] = 0。 阅读详情

The words `computer' and `commuter' are very similar, and a change of just one letter, p->m will change the first word into the second. The word `sport' can be changed into `spot' by the deletion of the `p', or equivalently, `spot' can be changed into `sport' by the insertion of `p'.

The edit distance of two strings, s1 and s2, is defined as the minimum number of point mutations required to change s1 into s2, where a point mutation is one of:

change a letter,
insert a letter or
delete a letter
 

The following recurrence relations define the edit distance, d(s1,s2), of two strings s1 and s2:

d('', '') = 0
d(s, '')  = d('', s) = |s|   -- i.e. length of s
d(s1+ch1, s2+ch2)
= min( d(s1, s2) + if ch1=ch2 then 0 else 1 fi,
d(s1+ch1, s2) + 1,
d(s1, s2+ch2) + 1 )
The first two rules above are obviously true, so it is only necessary consider the last one. Here, neither string is the empty string, so each has a last character, ch1 and ch2 respectively. Somehow, ch1 and ch2 have to be explained in an edit of s1+ch1 into s2+ch2. If ch1 equals ch2, they can be matched for no penalty, i.e. 0, and the overall edit distance is d(s1,s2). If ch1 differs from ch2, then ch1 could be changed into ch2, i.e. 1, giving an overall cost d(s1,s2)+1. Another possibility is to delete ch1 and edit s1 into s2+ch2, d(s1,s2+ch2)+1. The last possibility is to edit s1+ch1 into s2 and then insert ch2, d(s1+ch1,s2)+1. There are no other alternatives. We take the least expensive, i.e. min, of these alternatives.
 

The recurrence relations imply an obvious ternary-recursive routine. This is not a good idea because it is exponentially slow, and impractical for strings of more than a very few characters.

Examination of the relations reveals that d(s1,s2) depends only on d(s1',s2') where s1' is shorter than s1, or s2' is shorter than s2, or both. This allows the dynamic programming technique to be used.

A two-dimensional matrix, m[0..|s1|,0..|s2|] is used to hold the edit distance values:

m[i,j] = d(s1[1..i], s2[1..j])
m[0, 0] = 0
m[i, 0] = i,  i=1..|s1|
m[0, j] = j,  j=1..|s2|
m[i,j] = min( m[i-1,j-1]
+ if s1[i]=s2[j] then 0 else 1 fi,
m[i-1, j] + 1,
m[i, j-1] + 1 ),    i=1..|s1|, j=1..|s2|
m[,] can be computed row by row. Row m[i,] depends only on row m[i-1,]. The time complexity of this algorithm is O(|s1|*|s2|). If s1 and s2 have a `similar' length, about `n' say, this complexity is O(n2), much better than exponential!

 

 

Complexity
The time-complexity of the algorithm is O(|s1|*|s2|), i.e. O(n2) if the lengths of both strings is about `n'. The space-complexity is also O(n2) if the whole of the matrix is kept for a trace-back to find an optimal alignment. If only the value of the edit distance is needed, only two rows of the matrix need be allocated; they can be "recycled", and the space complexity is then O(|s1|), i.e. O(n).

Variations
The costs of the point mutations can be varied to be numbers other than 0 or 1. Linear gap-costs are sometimes used where a run of insertions (or deletions) of length `x', has a cost of `ax+b', for constants `a' and `b'. If b>0, this penalises numerous short runs of insertions and deletions.

Longest Common Subsequence
The longest common subsequence (LCS) of two sequences, s1 and s2, is a subsequence of both s1 and of s2 of maximum possible length. The more alike that s1 and s2 are, the longer is their LCS.

Other Algorithms
There are faster algorithms for the edit distance problem, and for similar problems. Some of these algorithms are fast if certain conditions hold, e.g. the strings are similar, or dissimilar, or the alphabet is large, etc..

Ukkonen (1983) gave an algorithm with worst case time complexity O(n*d), and the average complexity is O(n+d2), where n is the length of the strings, and d is their edit distance. This is fast for similar strings where d is small, i.e. when d<<n.

Applications
File Revision
The Unix command diff f1 f2 finds the difference between files f1 and f2, producing an edit script to convert f1 into f2. If two (or more) computers share copies of a large file F, and someone on machine-1 edits F=F.bak, making a few changes, to give F.new, it might be very expensive and/or slow to transmit the whole revised file F.new to machine-2. However, diff F.bak F.new will give a small edit script which can be transmitted quickly to machine-2 where the local copy of the file can be updated to equal F.new.

diff treats a whole line as a "character" and uses a special edit-distance algorithm that is fast when the "alphabet" is large and there are few chance matches between elements of the two strings (files). In contrast, there are many chance character-matches in DNA where the alphabet size is just 4, {A,C,G,T}.

Try `man diff' to see the manual entry for diff.

Remote Screen Update Problem
If a computer program on machine-1 is being used by someone from a screen on (distant) machine-2, e.g. via rlogin etc., then machine-1 may need to update the screen on machine-2 as the computation proceeds. One approach is for the program (on machine-1) to keep a "picture" of what the screen currently is (on machine-2) and another picture of what it should become. The differences can be found (by an algorithm related to edit-distance) and the differences transmitted... saving on transmission band-width.

Spelling Correction
Algorithms related to the edit distance may be used in spelling correctors. If a text contains a word, w, that is not in the dictionary, a `close' word, i.e. one with a small edit distance to w, may be suggested as a correction.

Transposition errors are common in written text. A transposition can be treated as a deletion plus an insertion, but a simple variation on the algorithm can treat a transposition as a single point mutation.

Plagiarism Detection
The edit distance provides an indication of similarity that might be too close in some situations ... think about it.

Molecular Biology
Example
An example of a DNA sequence from `Genebank' can be found [here]. The simple edit distance algorithm would normally be run on sequences of at most a few thousand bases.
 

The edit distance gives an indication of how `close' two strings are. Similar measures are used to compute a distance between DNA sequences (strings over {A,C,G,T}, or protein sequences (over an alphabet of 20 amino acids), for various purposes, e.g.:

to find genes or proteins that may have shared functions or properties
to infer family relationships and evolutionary trees over different organisms
 

Speech Recognition
Algorithms similar to those for the edit-distance problem are used in some speech recognition systems: find a close match between a new utterance and one in a library of classified utterances.

Notes
V. I. Levenshtein. Binary codes capable of correcting deletions, insertions and reversals. Doklady Akademii Nauk SSSR 163(4) p845-848, 1965,
also Soviet Physics Doklady 10(8) p707-710, Feb 1966.
Discovered the basic DPA for edit distance.
S. B. Needleman and C. D. Wunsch. A general method applicable to the search for similarities in the amino acid sequence of two proteins. Jrnl Molec. Biol. 48 p443-453, 1970.
Defined a similarity score on molecular-biology sequences, with an O(n2) algorithm that is closely related to those discussed here.
Hirschberg (1975) presented a method of recovering an alignment (of an LCS) in O(n2) time but in only linear, O(n)-space; see [here].
E. Ukkonen On approximate string matching. Proc. Int. Conf. on Foundations of Comp. Theory, Springer-Verlag, LNCS 158 p487-495, 1983.
Worst case O(nd)-time, average case O(n+d2)-time algorithm for edit-distance, where d is the edit-distance between the two strings.
See also exact, as opposed to approximate, (sub-)string [matching].
More research information on "the" DPA and Bioinformatics [here].
If your programming language does not support 2-dimensional arrays, and requires arrays or strings to indexed from zero upwards, some home-grown address translation will be needed to program the DPA defined above.

四、Dynamic-programming algorithm Dynamic--LCS (学习笔记,无什参考价值!) 1 问题 2 算法 2.1 Brute-force LCS algorithm 检查每一个subsequence是否是yyy的子列时,遍历yyy的每一个元素,看是否依次可以全部覆盖subsequence所有元素,所以其复杂度为O(n)O(n)O(n); 2.2 Dynamic-programming hallmark #1 动态规划的第一特征–最优子结构,下面用定理的方式证明这种特征; 这个性质是说,一个规模稍大的最优解问题建立在一些规模较小的最优解问题基础 阅读详情

相关推荐

动态规划算法——背包问题(Dynamic Programming Algorithm - Knapsack Problem)

动态规划算法——背包问题(Dynamic Programming Algorithm - Knapsack Problem)背包问题(Knapsack Problem) (picture is from https://en.wikipedia.org/wiki/Knapsack_problem) The knapsack problem is a problem in combinator

UoM_XiaoShuaiShuai的博客 4963

Dynamic Programming(I)

Topics: Dynamic Programming(DP) paradigm Assembly-Line Scheduling Matrix-Chain Multiplication Rod Cutting Optimization Problems A design technique, like divide-and-conquer. Works bottom-up rather then top-down. Useful for optimization problems. Four-ste

weixin_45018859的博客 403

基于AutoDL复现A-LOAM

Ceres solver 是谷歌开发的一款用于非线性优化的库,在谷歌的开源激光雷达slam项目cartographer中被大量使用。在autodl上面租服务器,地区我租的重庆A区的,GPU我选择的是RTX4090,基础镜像选择的是Miniconda / conda3 / 3.8(ubuntu20.04)/11.6。在AutoDL中我使用的方式是先将该数据集先下载到自己的电脑上,然后再上传到虚拟机中。用MobaXterm解决该问题!搜到的一个解决方式:该问题属于ceres版本问题,将A-LOAM下的。

m0_61281610的博客 1943

【算法】动态规划(Dynamic Programming)

文章目录什么是动态规划算法数字三角形经典递归解法 什么是动态规划算法 总体思想 (1)动态规划算法与分治法类似,其基本思想也是将待求解问题分解成若干个子问题 (2)经分解得到的子问题往往不是互相独立的,有些子问题被重复计算多次 (3)如果能够保存已解决的子问题的答案,而在需要时再找出已求得的答案,就可以避免大量重复计算,从而得到多项式时间算法(备忘录法) (4)图解: 使用动态规划来求解的问题需要具备的基本要素包括: (1)重复子问题 递归算法求解问题时,每次产生的子问题并不总是新问题,有些子

高朗的博客 4万+

RT_Thread Studio使用——USB虚拟串口(VCP)

RT_Thread Studio使用——USB虚拟串口(VCP)

weixin_44735205的博客 3377

PCIe控制器深度解析-RK3588 PCIe子系统核心模块探秘

本文深度解析了RK3588芯片中PCIe子系统的核心架构与功能模块。文章将PCIe控制器比作智能交通枢纽,详细阐述了RADM、XADM、CDM、eDMA等核心模块的工作原理,包括数据流管理、地址转换、DMA加速及电源管理。旨在帮助开发者和硬件工程师深入理解RK3588 PCIe控制器的内部机制,为驱动开发、性能优化和故障排查提供清晰的思路与实用指导。

weixin_29246195的博客 190

动态规划算法(Dynamic Programming)

动态规划是一种用于解决具有重叠子问题和最优子结构性质的复杂问题的算法设计技巧。它将问题分解为更小的子问题,并通过保存这些子问题的解来避免重复计算。

Zaczc的博客 1743

[0352]基于JAVA的停车场收费智慧管理系统的设计与实现

其次,从经营管理层面考虑,本系统涵盖了丰富的月卡管理和财务结算功能,如月卡用户管理、缴费、注销、挂失、解挂、补办等全流程服务,以及临保和月保的结算汇总与欠费查询等功能,这不仅有助于规范停车场的日常运营管理,更能有效提高财务管理效率,降低运营成本,实现精细化、数字化的财务管控。综上所述,本课题计划研发的基于Java的停车场收费智慧管理系统将在现有研究成果的基础上,重点优化月卡用户全生命周期管理和财务统计分析功能,以满足现代停车场高效、精准、安全的管理需求,紧跟行业发展趋势,为推动智慧城市的建设贡献一份力量。

muyu2980的专栏 590

算法专题:动态规划(Dynamic Programming)

算法专题:动态规划(Dynamic Programming)算法专题:动态规划(Dynamic Programming)算法专题:动态规划(Dynamic Programming)算法专题:动态规划(Dynamic Programming)算法专题:动态规划(Dynamic Programming)

weixin_49376454的博客 1723

C# 读取图片和扫描PDF中的文本

本博客将探讨如何使用C#和OCR库实现从图片和扫描的 PDF 中提取文本。Spire.OCR for .NET 是一个OCR文字识别库,专为在 .NET 应用程序中识别图片的文本而设计。首先,使用 Spire.PDF 将扫描的 PDF 转换为图片,然后利用 Spire.OCR 从这些图片中提取文本。由于该OCR库并不支持直接处理PDF,因此要从扫描的 PDF 中提取文本,我们首先需要将 PDF 文档转换为图片。转换完成后,再利用 Spire.OCR 从生成的图片中提取文本。方法来识别图片中的文本。

nuclear2011的博客 5406

Python数据可视化 Pyecharts 制作 Map 地图

大家好,我是Mr数据杨。想象一下,作为一名军师,如诸葛亮或郭嘉,'Map’就如同那战争的沙盘,兵马行动的轨迹,都需要准确的地图作为基础。‘基本设置’,就如同摆设这张战争沙盘,规定棋子的起始位置。‘数据配置选项’和’地图数据项’,就好比是军师们手中的情报,了解各路诸侯的兵力、粮草、地形等重要信息,以便于他们更好地布局。‘Demo’则代表着练兵之地,军师们可以在此基于已有数据,试验各种战术。

Mr数据杨 4万+

[转载]Dynamic Programming Algorithm (DPA) for Edit-Distance

转自:http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic/Edit/ The words `computer and `commuter are very similar, and a change of just one letter, p->m will change the first word into the sec

Faith Seeker 739

GEE数据融合——Landsat (collection 2,level 2 )4、5、7、8、9长时间序列影像数据融合和视频导出分析

长时间序列影像数据融合是指将Landsat影像数据集合2级2(Level 2)中的4、5、7、8和9这五个卫星的数据进行融合。具体来说,这包括将同一地点的多个卫星影像数据进行处理和整合,以产生一个单一的、具有更高质量的影像产品。在长时间序列影像数据融合中,首先需要对不同卫星的影像数据进行校正,以消除不同卫星之间的光谱差异、辐射度问题和几何纠正误差等。然后,通过使用融合算法,将多个卫星的影像数据进行组合,以生成一张全新的、高质量的合成影像。

此星光明博客 1736

编辑距离 算法 Dynamic Programming Algorithm (DPA) for Edit-Distance

关于两个字符串s1,s2的差别,可以通过计算他们的最小编辑距离来决定。        所谓的编辑距离: 让s1和s2变成相同字符串需要下面操作的最小次数。 1.         把某个字符ch1变成ch2 2.         删除某个字符 3.         插入某个字符 例如      s1 = “12433” 和s2=”1233”;                      则

1819

2026基金本子新规必看!聚焦四大底层问题,利用AI辅助分别破解提升中标率

我拟申报的研究主题为【明确的研究主题或关键词组合】。选题方向也是评审专家关注的核心之一,申报前可以检索近五年领域前人中标项目,分析现有研究的空白与不足,并结合自身研究基础选择 “人无我有、人有我优” 的细分方向,如果是交叉学科选题,则要阐述不同学科的融合逻辑与创新点。“推动国家战略”、“带来行业发展”等宏观表述,有很多同仁都喜欢用这类话术开篇,但实际上宏大叙事无法替代具体的真实科学问题,明确不了研究要解决的核心痛点,更没有说明问题的现实针对性,评审看了往往抓不到研究的核心价值。

智能AI让学术科研更容易 297

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Dynamic programming algorithm

Optimal computer folding of large RNA sequences using thermodynamics and auxiliary information Year: 1981 Authors: Michael Zuker and Patrick Stiegler Journal Name: Nucleic Acids Research Motivation 将动态规划算法与热动力学数据结合。 Research Objective 基于动态规划算法提出一种更有效、快速、并且

weixin_43269419的博客 482

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

算法-动态规划 Dynamic Programming--从菜鸟到老鸟

前言最近在牛客网上做了几套公司的真题,发现有关动态规划(Dynamic Programming)算法的题目很多。相对于我来说,算法里面遇到的问题里面感觉最难的也就是动态规划(Dynamic Programming)算法了,于是花了好长时间,查找了相关的文献和资料准备彻底的理解动态规划(Dynamic Programming)算法。一是帮助自己总结知识点,二是也能够帮助他人更好的理解这个算法。后面的参

有图有真相 48万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

基础算法总结(一)Algorithm(动态规划 Dynamic Programming)

动态规划(Dynamic Programming) DP定义:   动态规划是分治思想的延伸,通俗一点来说就是大事化小,小事化无的艺术。   在将大问题化解为小问题的分治过程中,保存对这些小问题已经处理好的结果,并供后面处理更大规模的问题时直接使用这些结果。 动态规划具备了以下三个特点:   1. 把原来的问题分解成了几个相似的子问题。   2. 所有的子问题都只需要解决一次。   3. 储存子问题的解。 动态规划的本质:   是对问题状态的定义和状态转移方程的定义(状态以及状态之间的递推关系)。 动态规

时光若止-Dale 937

动态规划(Dynamic Programming)与贪心算法(Greedy Algorithms)

动态规划动态规划是用来解决优化问题的,即要作出一组选择以达到最优解。动态规划有两个标志:一是可以划分最优子问题,二是子问题有重叠性(可以自底向上存储这些子问题的解,把算法效率从指数时间降到多项式时间)。例如,动态规划可以运用在矩阵相乘上。在矩阵连乘的时候,在中间增加括号是不影响最后结果的。也就是说 A * B * C = A * ( B * C )。假设A、B、C的维数为10 X 100,

無名黑洞 6859

Dynamic Programming Algorithms

There are two ways to implement a DP algorithm: Bottom-up, also known as tabulation Top-down, also known as memoization Bottom-up (Tabulation) Bottom-up is implemented with iteration and starts at the base cases. Using the Fibonacci sequence as an examp

CHNMSCS 526

算法之动态规划(Dynamic Programming)

1、介绍 (1)   动态规划是解决多阶段决策过程最优化的一种有效的数学方法,他是美国学者Richard.bellman在1951年提出的,1957年他的专著《动态规划》的问世标志着运筹学的一个重要分支—-动态规划的诞生。   所谓多阶段决策问题是指这样一类问题,该问题的决策过程时一种在多个相互联系的阶段分别作出决策以形成序列决策的过程,而这些决策均是根据总体最优化这一共同的目标而采取的。 ...

强子的博客 2万+

Introduction to Algorithm ( chapter 15: Dynamic Programming)

Dynamic programming is a very powerful algorithmic paradigm in which a problem is solved by identifying a collection of subproblems and tackling them one by one, smallest first, using the answers to

liucheng17的专栏 902

Dynamic Programming(动态规划算法题总结)

写在前面 暑假也是闲来无事,就想做做动态规划的题。想想在过去不久的第十届蓝桥杯国赛经历,几乎全是动态规划的题,虽然有个别题可以用深搜广搜解决,但是能过的样例不超过30%,都会超时的。因此我想总结一下。希望不会让我掉头发,这太烧脑了… 1.矩形覆盖 我们可以用2 * 1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2 * 1的小矩形无重叠地覆盖一个2 * n的大矩形,总共有多少种方法? 思路 这个...

小白的Coding之旅 342

动态规划(Dynamic Programming)算法与LC实例的理解

动态规划(Dynamic Programming)算法与LC实例的理解 希望通过写下来自己学习历程的方式帮助自己加深对知识的理解,也帮助其他人更好地学习,少走弯路。也欢迎大家来给我的Github的Leetcode算法项目点star呀~~ 动态规划(Dynamic Programming)算法与LC实例的理解 DP是什么 基本定义 帮助理解的经典问题:硬币问题 第二个经典问题:斐波那契数列 ...

MapleStory的博客 4632

动态规划(dynamic programming)

概念 动态规划(dynamic programming)是运筹学的一个分支,是求解决策过程(decision process)最优化的数学方法。20世纪50年代初美国数学家R.E.Bellman等人在研究多阶段决策过程(multistep decision process)的优化问题时,提出了著名的最优化原理(principle of optimality),把多阶段过程转化为一系列单阶段问题,...

浮华饰浮华的博客 419

经典算法之动态规划(Dynamic Programming)

1、动态规划的定义   动态规划,dynamic Programming,是一种高效解决问题的方法,使用与具有重复子问题和最优子结构的问题。 2、动态规划的思想   动态规划算法通常用于求解具有某种最优性质的问题。在这类问题中,可能会有许多可行解。每一个解都对应于一个值,我们希望找到具有最优值的解。动态规划算法与分治法类似,其基本思想也是将待求解问题分解成若干个子问题,先求解子问题,然后从这...

青萍之末的博客 3067
上一篇: 如何运行C++ STL程序
vector_conductor
博客等级 码龄20年 0粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值