Difference Algorithm

Difference Algorithm

- Myers Algorithm
- SES / LCS
- Edit Graph

- Paul Heckel Algorithm

427bc6d67b4b2724ed1ab066fb720f96?s=128

YuyaHorita

August 31, 2018
Tweet

Transcript

  1. %J⒎FSFODF"MHPSJUIN :VZB)PSJUB(JU)VCIPSJUBZVZB5XJUUFSIPSJUB@ZVZB $ZCFS"HFOU *OD J04%$

  2. None
  3. "HFOEB  *OUSPEVDUJPO w ࠩ෼ͱ͸ʁ w ฤूͱ͍͏ߟ͑ํ  .ZFST"MHPSJUIN w

    'FBUVSFT w 4&4-$41SPCMFN w &EJU(SBQI w ݪཧ w .ZFST0WFSWJFX  1BVM)FDLFM"MHPSJUIN w 'FBUVSFT w ݪཧ w )FDLFM0WFSWJFX  4VNNBSZ
  4. *OUSPEVDUJPO

  5. source = [1, 2, 3, 4, 5] ࠩ෼ͱ͸ʁ target =

    [1, 3, 5, 7] EJ⒎ TPVSDF UBSHFU 
  6. source = [1, 2, 3, 4, 5] ࠩ෼ͱ͸ʁ target =

    [1, 3, 5, 7] EJ⒎ TPVSDF UBSHFU  %FMFUF %FMFUF *OTFSU
  7. source = [1, 2, 3, 4, 5] ࠩ෼ͱ͸ʁ target =

    [1, 3, 5, 7] EJ⒎ TPVSDF UBSHFU  %FMFUF %FMFUF *OTFSU &EJU4DSJQU
  8. ฤूͱ͍͏ߟ͑ํ         

    TPVSDF UBSHFU
  9.  ฤूͱ͍͏ߟ͑ํ        

     TPVSDF UBSHFU EJ⒎ TPVSDF UBSHFU  %FMFUF %FMFUF *OTFSU
  10. .ZFST"MHPSJUIN

  11. 'FBUVSFT w 4JNQMF w 0 /% $PNQMFYJUZ w %FMFUF*OTFSU4DSJQU w

    4IPSUFTU w "EPQUFEJO%J⒎6UJM IUUQTEFWFMPQFSBOESPJEDPNSFGFSFODFBOESPJETVQQPSUWVUJM%J⒎6UJM
  12. ࠷୹ͷ൑ఆ͸ʁ

  13. ࠷୹ͷఆྔత൑அ w 4&44IPSUFTU&EJU4DSJQU w -$4ɿ-POHFTU$PNNPO4VCTFRVFODF w &EJU4DSJQUTPVSDFˠUBSHFUͷฤूʹඞཁͳ*OTFSU %FMFUF4DSJQUͷ͜ͱ w 4VCTFRVFODFɿ഑ྻ͔Β͍͔ͭ͘ͷཁૉΛऔΓআ͍ͯಘΒΕΔ഑ྻ

    4&4-$41SPCMFN
  14. ࠷୹ͷఆྔత൑அ w 4&44IPSUFTU&EJU4DSJQU w -$4ɿ-POHFTU$PNNPO4VCTFRVFODF w &EJU4DSJQUTPVSDFˠUBSHFUͷฤूʹඞཁͳ*OTFSU %FMFUF4DSJQUͷ͜ͱ w 4VCTFRVFODFɿ഑ྻ͔Β͍͔ͭ͘ͷཁૉΛऔΓআ͍ͯಘΒΕΔ഑ྻ

    source = [1, 2, 3, 4, 5] FY [1, 2, 5] [2, 3, 4, 5] [1, 2, 4, 3] [1, 3, 4, 6] 4&4-$41SPCMFN
  15. ࠷୹ͷఆྔత൑அ w 4&44IPSUFTU&EJU4DSJQU w -$4ɿ-POHFTU$PNNPO4VCTFRVFODF w &EJU4DSJQUTPVSDFˠUBSHFUͷฤूʹඞཁͳ*OTFSU %FMFUF4DSJQUͷ͜ͱ w 4VCTFRVFODFɿ഑ྻ͔Β͍͔ͭ͘ͷཁૉΛऔΓআ͍ͯಘΒΕΔ഑ྻ

    4&4-$41SPCMFN ˞EVBMQSPCMFN source = [1, 2, 3, 4, 5] FY [1, 2, 5] [2, 3, 4, 5] [1, 2, 4, 3] [1, 3, 4, 6]
  16. Ͳ͏΍ͬͯ୳ͦ͏

  17. &EJU(SBQI ίϯϐϡʔλͰղ͚ͦ͏ͳײ͡ʹදݱ

  18. &EJU(SBQI source = [A, B, C, A, B, B, A]

    target = [C, B, A, B, A, C] ίϯϐϡʔλͰղ͚ͦ͏ͳײ͡ʹදݱ
  19. source = [A, B, C, A, B, B, A] target

    = [C, B, A, B, A, C] (0, 0) A B C A B B A C B A B A C 0 1 2 3 4 5 0 1 2 3 4 5 6 source target 4UBSU (7, 6) &OE
  20. source = [A, B, C, A, B, B, A] target

    = [C, B, A, B, A, C] (0, 0) A B C A B B A C B A B A C 0 1 2 3 4 5 0 1 2 3 4 5 6 source target NBUDIQPJOU QPJOUBTTBNFTZNCPM (7, 6) 4UBSU &OE
  21. source = [A, B, C, A, B, B, A] target

    = [C, B, A, B, A, C] (0, 0) A B C A B B A C B A B A C 0 1 2 3 4 5 0 1 2 3 4 5 6 source target NBUDIQPJOU QPJOUBTTBNFTZNCPM (7, 6) &EHFʹԊͬͯɺ4UBSU͔Β&OE·ͰҠಈ͢Δ ӈɾԼɾࣼΊํ޲ͷҠಈ㲈EFMFUF JOTFSU EPOPUIJOH 4UBSU &OE 4UBSU &OE
  22. source = [A, B, C, A, B, B, A] target

    = [C, B, A, B, A, C] (0, 0) A B C A B B A C B A B A C 0 1 2 3 4 5 0 1 2 3 4 5 6 source target NBUDIQPJOU QPJOUBTTBNFTZNCPM (7, 6) 4&4 4UBSU &OE 4UBSU࠲ඪ&OE࠲ඪͷ࠷୹ܦ࿏  4UBSU &OE
  23. (0, 0) 0 1 2 3 4 5 (7, 6)

    0 1 2 3 4 5 6 Delete A Delete B 3JHIU.PWFNFOU #PUUPN.PWFNFOU %JBHPOBM.PWFNFOU EFMFUF JOTFSU EPOPUIJOH TBNFTZNCPM NBUDIQPJOU QPJOUBTTBNFTZNCPM Insert B Insert C source = [A, B, C, A, B, B, A] target = [C, B, A, B, A, C] A B C A B B A C B A B A C target Delete B 4UBSU &OE source 4UBSU &OE
  24. w&EJU(SBQIฤू࡞ۀΛίϯϐϡʔλͰղ͚ͦ͏ͳײ͡ʹදݱɻ wӈҠಈ%FMFUF wԼҠಈ*OTFSU wࣼΊҠಈEPOPUIJOH TBNFFMFNFOU 4&4-$41SPCMFNΛղ͘4UBSU࠲ඪ͔Β&OE࠲ඪ΁ͷ࠷୹ܦ࿏Λݟ͚ͭΔ

  25. ݪཧ

  26. ҠಈίετJT%JBHPOBM  source = [A, B, C, A, B, B,

    A] target = [C, B, A, B, A, C] (0, 0) 0 1 2 3 4 5 (7, 6) 0 1 2 3 4 5 6 Delete A Delete B NBUDIQPJOU QPJOUBTTBNFTZNCPM Insert B Insert C A B C A B B A C B A B A C target Delete B 4UBSU &OE ࠷୹ܦ࿏ͷ૯Ҡಈίετ % 4&4ͷεΫϦϓτ਺ source 4UBSU &OE
  27. Myers Algorithm w%͔Β࢝Ίͯɺ&OE࠲ඪΛ໨ࢦ͢ wແཧͩͬͨΒɺ%Λ૿΍ͯ͠౸ணग़དྷΔ·Ͱ܁Γฦ͢ w ͍͚Δ͔ͳʁ͍͚Δ͔ͳʁ͍͚ ˞͋͘·Ͱɺ%ճͰ࠷ԕͷ࠲ඪΛ໨ࢦ͢ɻ ࣼΊҠಈ͸શͯফඅ

  28. Lઢɿx - y = kͰ&EJU(SBQI্ʹͰ͖Δର֯ઢ

  29. (0, 0) 0 1 2 3 4 5 (7, 6)

    0 1 2 3 4 5 6 Delete A Delete B NBUDIQPJOU QPJOUBTTBNFTZNCPM Insert B Insert C source = [A, B, C, A, B, B, A] target = [C, B, A, B, A, C] A B C A B B A source C B A B A C target Delete B 4UBSU &OE 3 1 x - y = k 0 -1 2 Y Z 4UBSU &OE
  30. (0, 0) 0 1 2 3 4 5 (7, 6)

    0 1 2 3 4 5 6 Delete A Delete B NBUDIQPJOU QPJOUBTTBNFTZNCPM Insert B Insert C source = [A, B, C, A, B, B, A] target = [C, B, A, B, A, C] A B C A B B A source C B A B A C target Delete B 4UBSU &OE 3 1 x - y = k 0 -1 2 Y Z k + 1 k - 1 k 4UBSU &OE
  31. (0, 0) 0 1 2 3 4 5 (7, 6)

    0 1 2 3 4 5 6 Delete A Delete B NBUDIQPJOU QPJOUBTTBNFTZNCPM Insert B Insert C source = [A, B, C, A, B, B, A] target = [C, B, A, B, A, C] A B C A B B A source C B A B A C target Delete B 4UBSU &OE 3 1 0 -1 2 Y Z k + 1 k - 1 k ඇର֯ͳҠಈΛ%ճߦͬͨ࠷௕ͷܦ࿏ %͕ح਺ͳΒLح਺ͷର֯ઢ %͕ۮ਺ͳΒLۮ਺ͷର֯ઢ্Ͱࢭ·Δ 4UBSU &OE
  32. For D ← 0 to M + N Do For

    k ← -D to D in steps of 2 Do Until D Path gets to furthest point Do Move on edges If (N, M) is the reached point Then Found the SES. Array[with: k] M = source.count N = target.count %͕ح਺ͳΒLح਺ͷର֯ઢ %͕ۮ਺ͳΒLۮ਺ͷର֯ઢ্Ͱࢭ·Δ &EJU(SBQI্Ͱ࠷ԕͷύε͸֎प Complexity: O((M+N)D) ίετ%Ͱߦ͚ͨ࠷ԕͷ࠲ඪΛLઢຖʹه࿥ %શͯԼҠಈ %શͯӈҠಈ &OE࠲ඪ
  33. .ZFST0WFSWJFX w 4&4-$41SPCMFNΛղͨ͘ΊͷΞϧΰϦζϜ w &EJU(SBQI w Ҡಈίετ % ɾLઢͷ֓೦Λ׆༻ w

    %FMFUF *OTFSUऔಘޙɺͦΕΛ.PWF 6QEBUF4DSJQUʹม׵͢Δ ͜ͱ͸Մೳ
  34. 1BVM)FDLFM"MHPSJUIN

  35. w 4JNQMF0QUJNJ[BCMF w 0 / $PNQMFYJUZ w %FMFUF *OTFSU .PWF4DSJQU

    w /PU"MXBZT4IPSUFTU w #BTFPG 'FBUVSFT 3Y%BUB4PVSDFT
  36. ݪཧ

  37. TPVSDF UBSHFU 4ZNCPM5BCMF       

         &MFNFOU DPVOUJOTPVSDF DPVOUJOUBSHFU JOEFYJOTPVSDF                OVMM        OVMM source = [1, 2, 3, 4, 5, 4] target = [1, 3, 5, 2, 2, 7] w TPVSDF UBSHFUͷ֤ཁૉ &MFNFOU Λ,FZͱͯ͠ɺ%JDUJPOBSZͷ4ZNCPM5BCMFʹొ࿥ w 7BMVFʹ͸ͦͷཁૉͷ TPVSDF಺Ͱͷ਺ɺUBSHFU಺Ͱͷ਺ɺTPVSDF಺ͰͷJOEFY ˞ݸ͚ͩͷ৔߹ ݸPS̎ݸҎ্ͷ৔߹͸OVMM
  38. TPVSDF UBSHFU 4ZNCPM5BCMF       

         &MFNFOU DPVOUJOTPVSDF DPVOUJOUBSHFU JOEFYJOTPVSDF                OVMM        OVMM source = [1, 2, 3, 4, 5, 4] target = [1, 3, 5, 2, 2, 7] w TPVSDF UBSHFUͷ֤ཁૉ &MFNFOU Λ,FZͱͯ͠ɺ%JDUJPOBSZͷ4ZNCPM5BCMFʹొ࿥ w 7BMVFʹ͸ͦͷཁૉͷ TPVSDF಺Ͱͷ਺ɺUBSHFU಺Ͱͷ਺ɺTPVSDF಺ͰͷJOEFY ɾશཁૉΛ؅ཧ͢Δ4ZNCPM5BCMFΛҰͭ༻ҙ ɾTPVSDF UBSHFUͦΕͧΕͷཁૉͷొ࿥࡞ۀΛߦ͏ ˞ݸ͚ͩͷ৔߹ ݸPS̎ݸҎ্ͷ৔߹͸OVMM
  39. UBSHFU TPVSDF 4ZNCPM5BCMF       &MFNFOU

    DPVOUJOTPVSDF DPVOUJOUBSHFU JOEFYJOTPVSDF                OVMM        OVMM w TPVSDF UBSHFUͷͦΕͧΕͷཁૉͱରରԠͨ͠\TPVSDF UBSHFU^3FGFSFODFTΛ༻ҙ͢Δɻ w ରରԠ͍ͯ͠Δཁૉ΁ͷࢀরΛอ࣋͠ɺࢀরݩ͸4ZNCPM5BCMFPS΋͏ยํͷ഑ྻ ˞ͲͪΒʹ΋ͦͷཁૉ͕͋Δ৔߹͸΋͏ยํͷ഑ྻ͕༏ઌ       TZNCPM5BCMF TZNCPM5BCMF TZNCPM5BCMF TZNCPM5BCMF TZNCPM5BCMF TZNCPM5BCMF UBSHFU3FGFSFODFT
  40. UBSHFU TPVSDF 4ZNCPM5BCMF       &MFNFOU

    DPVOUJOTPVSDF DPVOUJOUBSHFU JOEFYJOTPVSDF                OVMM        OVMM w TPVSDF UBSHFUͷͦΕͧΕͷཁૉͱରରԠͨ͠\TPVSDF UBSHFU^3FGFSFODFTΛ༻ҙ͢Δɻ w ରରԠ͍ͯ͠Δཁૉ΁ͷࢀরΛอ࣋͠ɺࢀরݩ͸4ZNCPM5BCMFPS΋͏ยํͷ഑ྻ ˞ͲͪΒʹ΋ͦͷཁૉ͕͋Δ৔߹͸΋͏ยํͷ഑ྻ͕༏ઌ       UIF0UIFS UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF TZNCPM5BCMF UBSHFU3FGFSFODFT
  41. UIF0UIFS UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF TZNCPM5BCMF    

      UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF UIF0UIFS TZNCPM5BCMF       TPVSDF TPVSDF3FGFSFODFT UBSHFU UBSHFU3FGFSFODFT
  42. w UIF0UIFSࢀরͷ৔߹.PWF w TZNCPM5BCMFࢀরͷ৔߹TPVSDFˠ%FMFUF UBSHFUˠ*OTFSU UIF0UIFS UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF

    TZNCPM5BCMF       UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF UIF0UIFS TZNCPM5BCMF       TPVSDF TPVSDF3FGFSFODFT UBSHFU UBSHFU3FGFSFODFT
  43. ૬खଆͷ഑ྻʹཁૉ͕͋ΔͳΒɺJOEFYΛม͑Δ.PWFͰ0, 4ZNCPM5BCMF͔͠ࢀরग़དྷͳ͍ͳΒɺ TPVSDFͳΒ%FMFUFɺUBSHFUͳΒ*OTFSU͢Δ͔͠ແ͍ UIF0UIFS UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF TZNCPM5BCMF 

         UIF0UIFS UIF0UIFS UIF0UIFS TZNCPM5BCMF UIF0UIFS TZNCPM5BCMF       ˞ແବͳ.PWF͕ൃੜ͢ΔՄೳੑ༗Γ TPVSDF TPVSDF3FGFSFODFT UBSHFU UBSHFU3FGFSFODFT w UIF0UIFSࢀরͷ৔߹.PWF w TZNCPM5BCMFࢀরͷ৔߹TPVSDFˠ%FMFUF UBSHFUˠ*OTFSU
  44. )FDLFM0WFSWJFX w )BTI5BCMFΛ׆༻ͨ͠ɺཁૉͷJOEFYऔಘ w TPVSDFͱUBSHFUͷ֤ཁૉͷࢀরؔ܎ͷߏங w %FMFUF *OTFSU .PWFʹՃ͑ͯɺ6QEBUFͷऔಘ΋Մೳ w

    .ZFSTͱ͸จԽ͕ҟͳΓɺ4&4-$41SPCMFN͸ؔ܎ͳ͍
  45. w ར༻෯ͷ޿͞ɾ$PNQMFYJUZ༏ҐੑͳͲ͕ಛ௃తͳɺ.ZFSTɾ)FDLFMͷ ͭͷݪཧΛղઆɻ͓໾ʹཱͯΕ͹ w IUUQTHJUIVCDPNIPSJUBZVZB%J⒎FSFODF"MHPSJUIN$PNQBSJTPO w 0 / ͷ$PNQMFYJUZΛ࠾༻͍ͯ͠ΔϥΠϒϥϦ΋͋Δ͕ɺ6*͕བྷΉࠩ෼ߋ৽ ϥΠϒϥϦͱͯ͋͑ͯͦ͠ΕΛબͿཧ༝͸༨Γແ͍͔΋ʁ

    w બఆΞϧΰϦζϜɾ࣍ݩߋ৽ɾશCBUDI6QEBUF0QFSBUJPOTରԠɾ଎౓ɾFUD 4VNNBSJ[F  IUUQTHJUIVCDPNSB%J⒎FSFODF,JU
  46. ɾHeckel, Paul (1978), "A Technique for Isolating Differences Between Files”,

    Communications of the ACM, 21: 264–268, doi:10.1145/359460.359467, retrieved 2011-12-04 ɾE. W. Myers, ‘‘An O(ND) difference algorithm and its variations,’’ Algorithmica, 1 (1986), pp. 251−266. 3FGFSFODFT