GithubHelp home page GithubHelp logo

chinacoders / java-diff Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skypanda100/java-diff

0.0 1.0 0.0 1.96 MB

根据LCS最长公共子串算法,采用java实现比较文本的不同之处(增加,删除,更新)

Java 100.00%

java-diff's Introduction

原理

举例说明:A=GGATCGA,B=GAATTCAGTTA

第一步:初始化LD矩阵

公式一

若ai=bj,则LD(i,j)=LD(i-1,j-1)

若ai≠bj,则LD(i,j)=Min(LD(i-1,j-1),LD(i-1,j),LD(i,j-1))+1

第二步:利用上述的公式一,计算第一行

第三步,利用上述的公示一,计算其余各行

第四步,定位在矩阵的右下角

第五步,回溯单元格,至矩阵的左上角

若ai=bj,则回溯到左上角单元格

若ai≠bj,回溯到左上角、上边、左边中值最小的单元格,若有相同最小值的单元格,优先级按照左上角、上边、左边的顺序

若当前单元格是在矩阵的第一行,则回溯至左边的单元格

若当前单元格是在矩阵的第一列,则回溯至上边的单元格

依照上面的回溯法则,回溯到矩阵的左上角

第六步,根据回溯路径,写出匹配字串

若回溯到左上角单元格,将ai添加到匹配字串A,将bj添加到匹配字串B

若回溯到上边单元格,将ai添加到匹配字串A,将_添加到匹配字串B

若回溯到左边单元格,将_添加到匹配字串A,将bj添加到匹配字串B

搜索晚整个匹配路径,匹配字串也就完成了

A:GGA_TC_G__A

B:GAATTCAGTTA

成果物

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.