@algoritm.ts/ lcs (英语)
查找“% 1” 的打印符执行 分类 (长相通分序.
这个软件包提供了Lcs算法的三个不同的执行. 衡量复杂程度 这些算法,让$N 1美元和$N 2美元分别成为两个序列的子序列长度. 而让$L$成为最长的普通子序列的长度,再由$D=2L-N 1-N 2$.
-
myers_lcs(N1: number, N2: number, equals: (x: number, y: number) => boolean): [x: number, y: number][]数字 : 本文介绍的香草算法 O(ND) 差异算法及其变化。 。 。 .- 时间复杂度: $O( (N 1 + N 2))\times D)$
- 内存复杂度: $O( N 1)\ times N 2) $
-
myers_lcs_linear_space(N1: number, N2: number, equals: (x: number, y: number) => boolean): [x: number, y: number][]数字 : 线性空间精密算法 O(ND) 差异算法及其变化。 。 。 .- 时间复杂度: $O(N 1 + N 2) * D) 美元
- 内存复杂度:$O(N 1 + N 2)
-
lcs_dp(N1: number, N2: number, equals: (x: number, y: number) => boolean): [x: number, y: number][]这种执行基于动态编程,可以找到最小的词典 医生.- 时间复杂度: $O( N 1)\ times N 2) $
- 内存复杂度: $O( N 1)\ times N 2) $
以下定义引自维基百科 (单位:千美元)https://en.wikipedia.org/wiki/Longest common subsequence problem 互联网档案馆的存檔,存档日期2014-12-21:
最长的普通子序列(LCS)问题是找到最长的子序列的问题 常见于一组序列中的所有序列(通常只有两个序列). 和那个不同 最长的常见子字符串问题:与子字符串不同,子序列不需要占用 原序列内的连续位置。 最长的普通子序列问题是 经典的计算机科学问题, 数据比较程序的基础 如 diff 工具, 并具有计算语言学和生物信息学的应用. 它也被广泛使用 修改控制系统,如用于调和对a的多处更改的 Git 修订控制的文件集.
安装
-
无
npm install --save @algorithm.ts/lcs -
小时
pnpm add @algorithm.ts/lcs
使用量
-
基础
import { lcs_dp, lcs_myers_size } from '@algorithm.ts/lcs' const s1: number[] = [1, 2, 3, 4, 6, 6, 7, 8, 6] const s2: number[] = [2, 3, 4, 7, 9, 8, 2, 3, 5, 2] lcs_myers_size(s1.length, s2.length, (x, y) => s1[x] === s2[y]) // => 5 lcs_dp(s1.length, s2.length, (x, y) => s1[x] === s2[y]) // => [ [1, 0], [2, 1], [3, 2], [6, 3], [7, 5] ] // // Here is why: // // 0 1 2 3 4 5 6 7 8 9 // s1: 1 2 3 4 6 6 7 8 6 // s2: 2 3 4 7 9 8 2 3 5 2 // // s1[1] <----> s2[0] // s1[2] <----> s2[1] // s1[3] <----> s2[2] // s1[6] <----> s2[3] // null <----> s2[4] // s1[7] <----> s2[5] // null <----> s2[6] // null <----> s2[7] // null <----> s2[8] // null <----> s2[9]
相关
- O(ND) 差异算法及其变化。 。 。 .
- 最长公共子序列(LCS)| (光和尘)
- 维基百科中的相关条目: 相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接相接