ãã®èšäºã®å 容ã¯ã æ¥å°ŸèŸãšæååæ¥é èŸã®æŠå¿µã«é¢ããç¥èã ããã³ ãã€ããªæ€çŽ¢ã®ä»çµã¿ã«é¢ããç¥èãåæãšããŠããŸãã ãŸãã å®å®ãããœãŒããšãããåäœã®ãœãŒããäœã§ããããç解ããå¿ èŠããããŸãããŸããã«ãŠã³ãã«ããå®å®ãããœãŒãã®æå³ãç解ããå¿ èŠããããŸãã äžéšã®éšåã«ã€ããŠã¯ãã»ã°ã¡ã³ãã®æå°åé¡-Range Minimum QueryïŒRMQïŒã®ç¥èãå¿ èŠã§ãã ãŸããäžè¬çã«ãããªãã¯èŠåãåããŸããïŒèª°ããããç°¡åã ãšã¯èšããŸããã§ããã
ãµãã£ãã¯ã¹ã¢ã¬ã€ã¢ããªã±ãŒã·ã§ã³
ãã¹ãŠã®ããªãŒãåãããã«åœ¹ç«ã€ããã§ã¯ãããŸããã
ã ããããªãæšã¯ç§ãã¡ã«åããªãã®ã§ããïŒ ãŸãããã¡ãããåäŸã芪ãªã©ãžã®ãªã³ã¯ãä¿åããå¿ èŠãããããã§ãã ãã®å Žåã®äœ¿çšã¡ã¢ãªã®ãµã€ãºã¯ããããã®ãªã³ã¯ãä¿åãããŠããªãå Žåãããèãã倧ãããªããŸãã 第äºã«ãããã€ãã®æšæºã¢ãã±ãŒã¿ã䜿çšããŠããŒã¿ã«ã¡ã¢ãªãå²ãåœãŠããšããããŸããŸãªè§åºŠã§åæ£ãããŸããããªãŒãåãçµæãšããŠãã¡ã¢ãªãã£ãã·ã¥ã«åœ±é¿ããå€æ°ã®ã¡ã¢ãªé·ç§»ãæ³å®ãããŸãã ãã¡ããããã®åé¡ãæå¶ã§ããããªãã¯ããããŸããããªãŒããŒããé åã«é 眮ãããã€ã³ã¿ãŒã®ä»£ããã«é åã®ã€ã³ããã¯ã¹ã䜿çšããå¿ èŠããããŸãã ãããããšãããªãŒã¯ãã£ããããã¡ã¢ãªã®ããã«èŠããŸãã
ããŠããããã¯ãã¹ãŠã®æšã«å ±éã®åé¡ã§ãã ãããŠãæªåé«ãã¢ã«ãã¡ãããé ã®äŸåé¢ä¿ã¯ã©ãã§ããïŒ æ¥å°ŸèŸããªãŒã®å®çšçãªå®è£ ãèŠãŠã¿ãŸãããïŒããã«ééããŠããªãå Žåãããã¯åé¡ã®æ¬è³ªãç解ããããã«éèŠã§ã¯ãããŸããïŒã ãã®ãããªããªãŒã®åããŒãã«ã¯ã1ããïŒããšãã°ãåå²ã®ãªãçµç«¯é ç¹ã®ïŒã¢ã«ãã¡ãããã®ãµã€ãºãŸã§ã®åãžã®ãªã³ã¯ããããŸãã ãããã£ãŠãåé¡ã¯ãããã®ãªã³ã¯ãä¿åããæ¹æ³ã§ãã ããšãã°ãåããŒãã§ã¢ã«ãã¡ãããã®ãµã€ãºã®ãªã³ã¯ã®é åãä¿æã§ããŸãã ããã¯ããã«åäœããŸã-ãã®ããŒãã«å¯Ÿå¿ããåããããã©ããã調ã¹ãã«ã¯ãOïŒ1ïŒã䜿çšã§ããŸãã ããããé åã®ã»ãšãã©ã®ã»ã«ã«ã¯ãŒãåç §ãä¿åããããããã®ã»ã«ã®ã¡ã¢ãªã¯ãªããªããŸãã å°ããªã¢ã«ãã¡ãããïŒDNAã®ãã¯ã¬ãªãããªã©ïŒã®å Žåãããã¯å°çã§ããã挢åãæ³åããŠã¿ãŠãã ããã ååãšããŠãé ãã«è¡ãå¿ èŠã¯ãããŸããã倧æåãšå°æåãåºå¥ãããã·ã¢èªã®ã¢ã«ãã¡ãããã§ããèããããŸãããã空ã®ããŒã¿ã倧éã«ååŸããããã©ããã
åçã«å€åããé åïŒãã¯ãã«ïŒã«ç©ºã§ãªããªã³ã¯ã®ã¿ãé 眮ããããšã«ãããã¡ã¢ãªãããçµæžçã«äœ¿çšã§ããŸãããOïŒ1ïŒã®å¯Ÿå¿ããåããŒãã®ååšã®ç¢ºèªã¯éåžžã«çããããªããŸãã ãªã³ã¯ããœãŒãããã圢åŒã§ä¿åããå ŽåãOïŒãã°ïŒã¢ã«ãã¡ããããµã€ãºïŒïŒã ããã·ã¥ããŒãã«ãè©ŠããŠã¿ãããšãã§ããŸãããããã¯éåžžã«å€§ããªã¢ã«ãã¡ãããã«å¯ŸããŠã®ã¿æå³ããããããã«ãå¥ã®ã¬ãã«ã®éæ¥åç §ãå°å ¥ãããŸãã ãããŠããã®ãããªæšãæ§ç¯ããããšã¯ãã¯ãOïŒnïŒã§ã¯ãããŸããã äžè¬ã«ããããã®å Žåã§ããã¡ã¢ãªãšããã©ãŒãã³ã¹ã®éã§åŠ¥åããå¿ èŠããããŸãã
æ¥å°ŸèŸé å
1989幎ãManberãšMyersã¯ãæ¥å°ŸèŸé åãªã©ã®ããŒã¿æ§é ãšãããã䜿çšããŠéšåæååãæ€çŽ¢ããæ¹æ³ã説æããèšäºãå ¬éããŸããã æ¥å°ŸèŸé åã¯ãèŸæžåŒã«ãœãŒããããè¡ã®æ¥å°ŸèŸã®é åã§ãïŒçšèªãããããããªãå Žåã¯ã ãã®èšäºã®ãåé¡ã®èª¬æãã»ã¯ã·ã§ã³ãã芧ãã ããïŒã äžè¬çã«ãæ¥å°ŸèŸèªäœãæ ŒçŽããããšã¯æå³ããããŸãããç¹å®ã®æ¥å°ŸèŸã®å é ã®äœçœ®ãæ ŒçŽããã ãã§ååã§ãããé åã®å®çŸ©ãç解ããæ¹ãç°¡åã§ãã æååãmississippiãã®äŸã次ã«ç€ºããŸãã
ïŒ | æ¥å°ŸèŸ | ãµãã£ãã¯ã¹çªå· |
---|---|---|
1 | ç§ã¯ | 11 |
2 | äžã | 8 |
3 | ã€ã·ãã | 5 |
4 | ã€ã·ã·ãã | 2 |
5 | ãã·ã·ãã | 1 |
6 | ã〠| 10 |
7 | ppi | 9 |
8 | ã·ãã | 7 |
9 | ã·ã·ãã | 4 |
10 | ã·ãã㌠| 6 |
11 | ã·ã·ãã | 3 |
ãŸããéèŠãªæŠå¿µã¯æ¥å°ŸèŸã®ã©ã³ã¯ã§ããã€ãŸããæ¥å°ŸèŸããœãŒãæã«åãå Žæãã€ãŸãæ¥å°ŸèŸé åå ã®äœçœ®ã§ãã ãããã¯éæ°ã§ãã 1ã€ã®é åãæã£ãŠããã®ã§ãOïŒNïŒã®ããäžæ¹ãååŸã§ããã®ã§ãããããç¹ã«åºå¥ããŸããããããã£ãŠãåžžã«äž¡æ¹ãæå ã«çœ®ãããšãã§ããŸãã
æãåçŽãªéšåæååæ€çŽ¢
äŸãèããŠã¿ãŸãããã å ã®æååã¯"mississippi"ã§ãã ãäžå£ãã®ãµã³ãã«ãæ¥ããšããŸãããã æ¥å°ŸèŸé åã䜿çšããŠããã¹ãã«ãã¿ãŒã³ãçºçãããã©ããã確èªããæãç°¡åãªæ¹æ³ã¯ããã¿ãŒã³ã®æåã®æåãååŸãã ãã€ããªæ€çŽ¢ ïŒé åããœãŒããããïŒã䜿çšããŠãåãæåã§å§ãŸãæ¥å°ŸèŸãæã€ç¯å²ãèŠã€ããããšã§ãã ç¯å²å ã®ãã¹ãŠã®èŠçŽ ã䞊ã¹æ¿ããããæåã®æåãåãã§ãããããæåã®æåãåé€ããåŸã«æ®ãæ¥å°ŸèŸã䞊ã¹æ¿ããããŸãã ã€ãŸãã空ã®ç¯å²ãåŸããããããã¿ãŒã³å ã®ãã¹ãŠã®æåãæ£åžžã«èŠã€ãããŸã§ãæ€çŽ¢ç¯å²ãçµã蟌ãããã»ã¹ãç¹°ãè¿ãããšãã§ããŸãã æããã«ããã®ããã«ããŠãOïŒ| X | log | A |ïŒæäœã«å¯ŸããçããåŸãããŸãã
ãµã³ãã« | IP | si p | äžå£ |
---|---|---|---|
ç§ã¯ | ç§ã¯ | ç§ã¯ | |
äžã | äžã | äžã | |
ã€ã·ãã | ã€ã·ãã | ã€ã·ãã | |
ã€ã·ã·ãã | ã€ã·ã·ãã | ã€ã·ã·ãã | |
ãã·ã·ãã | ãã·ã·ãã | ãã·ã·ãã | |
ã〠| ã〠| ã〠| |
ppi | ppi | ppi | |
s ippi | si ppi | äžå£ã〠| |
s issippi | ã·ã·ãã | ã·ã·ãã | |
s sippi | ã·ãã㌠| ã·ãã㌠| |
ã·ã·ãã | ã·ã·ãã | ã·ã·ãã |
ãã€ããªæ€çŽ¢ãæ£é¢ãã䜿çšããå ŽåããŸã£ããåãè€éããååŸããŸãïŒãšããžã«æ²¿ã£ãã©ã€ã³ãšãµã³ãã«ã®äžå€®å€ã®å®å šãªèŸæžåŒæ¯èŒïŒOïŒlog | A |ïŒæ¯èŒã®å¹³åãäŸ¡æ Œããšã®æ¯èŒOïŒ| X |ïŒã
ããéã
æªãã¯ãªãããããè¯ãã å®éãæ€çŽ¢æååå šäœãé åèŠçŽ ãšæ¯èŒããå¿ èŠã¯ãããŸããã ãã€ããªæ€çŽ¢ã®åå埩ã§ãç®çã®èŠçŽ ãé 眮ã§ããç¹å®ã®ç¯å²ãæå®ããŸãã ãã®ç¯å²ã®ãã¹ãŠã®è¡ã¯ãããã€ãã®ç¹ã§äŒŒãŠããŸãã ã€ãŸãããããã®è¡ã«ã¯ãç®çã®è¡ãšå ±éã®ãã¬ãã£ãã¯ã¹ãä»ããŠããå ŽåããããŸããç¯å²å€ã®è¡ã«ã¯ãå ±éã®ãã¬ãã£ãã¯ã¹ãå«ãŸããªãããã§ãïŒãµã³ãã«ã®æ¢ã«åŠçãããéšåããã¬ãã£ãã¯ã¹ã®äžéšãšèŠãªããªããšããæå³ã§ïŒã
çŸåšã®ç¯å²ã®ãšããžãæã€æ®ãã®ãµã³ãã«ã®äžè¬çãªãã¬ãã£ãã¯ã¹ã®é·ããç¥ã£ãŠãããšä»®å®ããŸãl = lcpïŒ X ã S [ L ] ïŒããã³r = lcpïŒ X ã S [ R ] ïŒå·Šå³ã®ãšããžïŒ lcp-æé·å ±éãã¬ãã£ãã¯ã¹ïŒã æåã®ã¹ããŒãã¡ã³ãã¯ãlcpç¯å²å ã®ä»»æã®è¡ã«ã€ããŠãããã2ã€ã®æ°å€ã®æå°å€ä»¥äžã§ãããšããããšã§ãã ããã§ãªãå Žåãæ¥é èŸã®æåã®éšåãå€æŽããã«ãã·ã³ãã«ããã¿ãŒã³ã®å¯Ÿå¿ããã·ã³ãã«ãšæåã«äžèŽãã次ã«äžèŽãããåã³äžèŽããäœçœ®ããããŸãã ããã¯ãç¯å²ã®ãœãŒããšççŸããŸãã ãã®ã¢ã€ãã¢ãåŸããåœããåã®ããã«äœ¿çšããã®ã§ããã®ã¢ã€ãã¢ã«ã€ããŠè¯ãæ觊ãåŸãããšãéèŠã§ãã 2çªç®ã®ã¹ããŒãã¡ã³ãã¯æããã§ãããµã³ãã«ãšç¯å²å ã®ä»»æã®è¡ã®å ±éãã¬ãã£ãã¯ã¹ãm = minïŒlãrïŒä»¥äžã®å Žåãmæåã¯ããã«ã¹ãããããããããã®å Žåã§ãäžèŽããŠããããšãèªèããm + 1ããã®ã¿æ¯èŒããŸãïŒãããŠç¹å®ã®è¡ã®lcpã«ãªããŸãïŒã
ãããã£ãŠãæååãé¡ãã®ãã€ããªæ€çŽ¢ã§æé©åãããæååæ¯èŒãé©çšããŸãã ææªã®å Žåããã¡ããããããæ©æµãåããããšã¯ãããŸããïŒç®çã®èŠçŽ ãé åã®ç«¯ã«ããããé£å士ãlcpã§ãŸã£ããé¡äŒŒããŠããªãå ŽåãrïŒãŸãã¯lïŒã¯æ¯åå°ãããªããmãå°ãããªããŸããã€ãŸããããããããã§ãã¯ããå¿ èŠããããŸããã°ããšã®æå| A | åã ããããå®éšçµæã«ãããšãèªç¶ãªããã¹ãã®å Žåãæ€çŽ¢æéã¯OïŒlog | A || X |ïŒã«æ¯ã¹ãŠå€§å¹ ã«ççž®ãããŸãããç¹å®ã®æŒžè¿çŸè±¡ã«ã€ããŠèšãã®ã¯å°é£ã§ãã
ååãšããŠãå®çšçãªã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã§ã«ããã§ååã§ããããã¹ãŠãçµãå Žåã¯...
ããã«éã
ããã¯å¶éã§ã¯ãããŸããã é åã»ã¯ã·ã§ã³ã®ç«¯ã®äœçœ®ã¯ãã®ã»ã¯ã·ã§ã³ã®äžå¿ãå®çŸ©ãããã€ããªæ€çŽ¢ã§å®è£ ããããã®ãããªæ§æã¯ãã¹ãŠãåºå®ãµã€ãºã»ããã®ãµãã»ããã§ãã A | -2ã ãããã®æ§æã§m l = lcpïŒ S [ M ] ã S [ L ] ïŒããã³m r = lcpïŒ S [ M ] ã S [ R ] ïŒã®éãäºåã«èšç®ãããšä»®å®ããŸããããã§Mã¯LãšRã®éã®ã»ã¯ã·ã§ã³ã®äžå€®ã§ããããã¯ããã€ããªæ€çŽ¢ã¹ãããã§è¡ããŸãã
ãšããžã®1ã€ãããšãã°å·ŠåŽãèŠãŠã¿ãŸãããã l <m lãèšç®ããå Žåã巊端ã¯äžå€®ïŒããã³ãããã®éã®ä»»æã®èŠçŽ ïŒã«ç§ãã¡ãæããããã¯ããã«åŒ·ããæ¯èŒçµæã¯LãšMã®éã®ã»ã¯ã·ã§ã³å šäœã§äºåã«ããã£ãŠããŸãïŒlcpïŒ X ã S [ M ] ïŒ= lã ãã®ããšãããæ±ããããŠããèŠçŽ ããã®ã»ã¯ã·ã§ã³ã«ãªãããšã¯ããã«æããã§ãããæ¢ããŠããå Žåã¯å察ã®ååã«ãããŸãã l> m lã®å Žåãäžå€®ã¯ç®çã®ãµã³ãã«ãããå°ãã巊端ã«äŒŒãŠããŸãã ãããã£ãŠãlcpïŒ X ã S [ M ] ïŒ= m l ãããã³ãã®éã®ã©ããã«ç®çã®èŠçŽ ãæ¢ãå¿ èŠããããŸãã
åœç¶ã巊端ãå³ç«¯ã«çœ®ãæããŠããæšè«ã«å€åã¯ãããŸããã 1ã€ã®ã±ãŒã¹ã®ã¿ãèæ ®ãããŸããã§ããïŒl = m lããã³r = m r ïŒå°ãªããšã1ã€ã®çåŒãçã§ãªãå Žåãçµæã¯åã®æ®µèœã«åŸã£ãŠç¥ãããŠããŸãïŒã ãããããlcpïŒ X ã S [ M ] ïŒãmaxïŒlãrïŒããå°ãããªãããšã¯æããã§ãããããããã®æ£ç¢ºãªå®çŸ©ãšãæåãæ¯èŒããå¿ èŠãããæ¹æ³ãèŠã€ããããã«ïŒæçµçã«ïŒïŒäœçœ®maxïŒlãr ïŒ+1ã
äœãåŸãã®ïŒ ããã€ãã®lcpãçžäºã«æ¯èŒããããšã«ããããã€ããªæ€çŽ¢ã¹ãããã®äžéšãå®è¡ããŸããæåãæ¯èŒããå Žåã§ããæåXããšã«1åã®ã¿ã§ãïŒmaxïŒlãrïŒ+1ãåããŸããããã¯æ±ºããŠæ»ããªãããšãæå³ããŸãïŒã ãããã£ãŠã ææªã®å Žåã®OïŒlog | A | + | X |ïŒã¢ã«ãŽãªãºã ã®è€éããååŸããŸãã 確ãã«ããã€ããªæ€çŽ¢ã¢ã«ãŽãªãºã ã«ãã£ãŠèªå°ãããæ€çŽ¢ããªãŒã§èŠã€ãã£ãããã¹ãAã®æ¥å°ŸèŸã«ã¯ãäºåã«èšç®ãããlcpãå¿ èŠã§ãã
m rãããããªãããm lããããããªãå Žåã¯ãå¿é ããå¿ èŠã¯ãããŸããã ãšã³ããªããªããšäºåã«èšãæ©äŒã¯ãããŸããããããã¯è€éããæªåãããããšã¯ãããŸãããå³ç«¯ã ããèŠãŠã巊端ã ããèŠãŸãã l <m lã®å Žåãæ®ãã®ååãããã«èª¿ã¹ãl> m lã®å Žåã¯lãä¿åããrãm lãšããŠãã®ååã調ã¹ãŸãããl = m lã®å Žåãäžå€®å€èŠçŽ ãç®çã®æååãšæ¯èŒããŸãl + 1çªç®ã®äœçœ®ããéå§ããŸãã ãã®å Žåãæ»ããŸãããã€ãŸããã¢ã«ãŽãªãºã ã®è€éããæãªãããšãªãã巊端ã«å¯ŸããŠã®ã¿lcpãå®è¡ã§ããŸãã
LCPååŠç
èŠããŠããããã«ãå¹æçãªéšåæååæ€çŽ¢ã«ã¯ããµãã£ãã¯ã¹ã®ç¹å®ã®çµã¿åããã«å¯ŸããŠäºåã«èšç®ãããlcpãå¿ èŠã§ããã ããããååŸããæ¹æ³ã説æããå¿ èŠããããŸãã ãããã®æ¹æ³ã¯éåžžãã»ã°ã¡ã³ãã®æå°å€ãèŠã€ããåé¡RMQã«åž°çãããããã¢ã«ãŽãªãºã ã®ã¢ã«ãŽãªãºã ã®è€éãã¯ãRMQåé¡ãã©ãã ãå¹ççã«è§£æ±ºã§ãããã«å€§ããäŸåããŸãã å€ããå°ãªããåçŽãªã¢ã«ãŽãªãºã ã¯ãååŠçã§OïŒNlogNïŒãèŠæ±ã§OïŒ1ïŒããããŸãã ã€ãŸããOïŒNlogNïŒã§æ¥å°ŸèŸé åã®æ§ç¯ã䜿çšããå Žåãããã䜿çšããããšã¯ããªãå¯èœã§ãã ãã¡ãããç·åœ¢æéã§æ¥å°ŸèŸé åãäœæããå Žåã¯ãäžå®ã®ã¯ãšãªã§ç·åœ¢æéã«RMQååŠçã¢ã«ãŽãªãºã ã䜿çšããå¿ èŠããããŸãã
ãŸããããããlcpé åãäœæããŸã-ããã¯ãèŸæžçã«é£æ¥ãããµãã£ãã¯ã¹éã®lcpå€ã®é åã§ãïŒãµãã£ãã¯ã¹é åãäœæããåŸãã©ã®ãµãã£ãã¯ã¹ãé£æ¥ãã質åãåŒãèµ·ãããªããïŒã lcpé ââåãããå Žåã2ã€ã®èŠçŽ éã§lcpãèŠã€ãããšãlcpé åã®æå®ãããã»ã°ã¡ã³ãã®æå°å€ãã€ãŸãçŽç²ãªåœ¢åŒã®RMQã¿ã¹ã¯-ã»ã°ã¡ã³ãã®æå°å€ãèŠã€ããããšã«ãªããŸãã ãªãããããããªã®ãã¯ãæ¥å°ŸèŸã®é åºã®èæ ®ããæããã§ãïŒ2è¡ã®éã«lcpãããã«ããå Žåããããã®éã®ãã¹ãŠã®è¡ã«ã¯å°ãªããšãåãæ°ã®åãæåãå é ã«å«ãŸãããããã®è¡ã®éã®ãã¹ãŠã®lcpã¯æ¥µç«¯ãªçžäºã®lcp以äžã«ãªããŸãèŠçŽ ã
lcpé ââåã®æ§ç¯ã¯éåžžã«ç°¡åã§ãã ãã¡ãããæ¥å°ŸèŸé åãééããé£æ¥ããèŠçŽ ã®lcpãã«ãŠã³ãããããšã¯æ©èœããŸãã-ããã¯OïŒN 2 ïŒã§ãã ãã ããæ£ããé åºã§é åã調ã¹ãã°ãåã®æé ã®æ å ±ãèšç®ã«äœ¿çšã§ããŸãã ã€ãŸããå ã®è¡ã«çŸããé åºã§ãµãã£ãã¯ã¹ã䞊ã¹æ¿ããå Žåãåã¹ãããã§lcpã¯åã®ã¹ããããšæ¯èŒããŠ1ãè¶ ããŠæžå°ããããšã¯ã§ããŸãããã€ãŸãããããããå€ããå€åããªãå ŽåããããŸããã less then only1ãããã¯æ¬¡ã®çç±ã§èµ·ãããŸãã lcpïŒ A [i ..]ã A [j ..]ïŒ= lã§ããããšãããã£ãå Žåãæåã®æåããããããããšãæããã«1ã€æžããŸãïŒlcpïŒ A [i + 1 ..]ã A [j +1 ..]ïŒ= l-1ã ãã¡ãããiçªç®ãšjçªç®ã®æ¥å°ŸèŸãèŸæžåŒã«é£æ¥ããŠããããšãå€æããå Žåãi + 1çªç®ãšj + 1çªç®ãé£æ¥ããããšã¯ä¿èšŒãããŸããã ãããããã§ã«ããã£ãŠããããã«ããããã®éã®lcpã¯ããããã®éã®ã»ã°ã¡ã³ãå šäœã®æå°lcpã§ããã€ãŸããi + 1çªç®ã®æ¥å°ŸèŸãšèŸæžåŒã®åŸã«ç¶ãlcpã¯l-1以äžã§ãã
ïŒ | æ¥å°ŸèŸ | ã¹ããã | lcp |
---|---|---|---|
1 | ç§ã¯ | 10 | 1 |
2 | äžã | 7 | 1 |
3 | ã€ã·ãã | 4 | 4 |
4 | ã€ã·ã·ãã | 2 | 0 |
5 | ãã·ã·ãã | 1 | 0 |
6 | ã〠| 9 | 1 |
7 | ppi | 8 | 0 |
8 | ã·ãã | 6 | 2 |
9 | ã·ã·ãã | 3 | 1 |
10 | ã·ãã㌠| 5 | 3 |
11 | ã·ã·ãã | é£ã°ã |
ããã«ããããã¹ãŠã®æåãã¹ãããããŠæåŸãã2çªç®ïŒl-1ïŒã«ããããšãã§ããŸããããã¯ãããããçããããšã確èªããlçªç®ä»¥éã®æåã®ã¿ãæ¯èŒããããã§ãã ããã¯ããã§ãã¯ãè¡ããšãçŸåšã®lcpãå¢å ãããã匷å¶çã«æ¬¡ã®å埩ã«é²ãããšãæå³ããŸãã ãããã£ãŠãèŸæžçã«æåŸã®æ¥å°ŸèŸãé€ããã¹ãŠã®æ¥å°ŸèŸãæž¡ããšïŒçç¥ãããå¿ èŠããããŸãïŒãç·åœ¢æéOïŒNïŒã®lcpé åãååŸããŸãã
ãŸããããã ãã§ãã å¿ èŠãªãµãã£ãã¯ã¹ã®ãã¢ã®RMQãèŠã€ããããšã¯æ®ã£ãŠããŸãã RMQãœãªã¥ãŒã·ã§ã³ã¯ãååŠçãšãå®éã«ã¯èŠçŽ éã®æå°ã¯ãšãªãžã®å¿çã§æ§æãããŠããŸãã äž»ãªèšç®è² è·ã¯ååŠçã«ãããã¯ãšãªã®å®è¡ã¯OïŒ1ïŒã§è¡ãããããäžè¬çã«èšãã°ãä»»æã®ãµãã£ãã¯ã¹ã®lcpã«ã€ããŠOïŒ1ïŒã«çããããšãã§ãããããé¢å¿ã®ãããã¢ãšãããã®éã®lcpãæ瀺çã«æžãåºãå¿ èŠã¯ãããŸããããã€ããªæ€çŽ¢ã§åœ¹å²ãæãããã®ãå«ãã ããã«ãããä¿åãããå€ã®å¯ŸåŠæ¹æ³ãèããå¿ èŠããªããªããããããã¯éåžžã«ã¯ãŒã«ã§ãã ãŸã èšç®æžã¿ã®åœ¢åŒã§lcpãä¿åããå Žåã¯ãæ€çŽ¢ããªãŒã®ç¶æ ã«æ£ããçªå·ãä»ããå¿ èŠããããŸããã¡ã¢ãªå ã®å Žæãšãã€ããªããŒãå ã®ã¢ãã¬ã¹ã«ã€ããŠèªãã§ãã ããã
ç§ã¯RMQã®è§£æ±ºæ¹æ³ã«ã€ããŠã¯æžããŸãã-Habréã«ã¯OïŒNlogNïŒã®ç°¡åãªããŒãžã§ã³ã«é¢ããè¯ãèšäºãæ¢ã«ãããŸããããããŠãOïŒNïŒã®ããŒãã³ã¢ããŒãžã§ã³-Farah -Coltonã¢ã«ãŽãªãºã ãšãã³ããŒ
ãµãã£ãã¯ã¹é åã®æ§ç¯
ããŠãããã§æ¥å°ŸèŸé åãé©çšããæ¹æ³ãç¥ã£ãŠããŸãããããã¯ã©ãããæ¥ãã®ã§ããããïŒ æããã«ãæ¥å°ŸèŸããœãŒãããçŽæ¥çãªæ¹æ³ã§ãããæ§ç¯ããããšã¯é·ãããžãã¹ã§ã-OïŒN 2 logNïŒãããã§N = | A |ã OïŒNlogNïŒã§æ©èœããã¢ã«ãŽãªãºã ã¯å€æ°ãããŸãããOïŒNlogïŒã§æ©èœããã¢ã«ãŽãªãºã ããããŸãã OïŒNïŒãéåžžã«çŽããããïŒããšãã°ãæåã«ãµãã£ãã¯ã¹ããªãŒãæ§ç¯ãã次ã«ãããããµãã£ãã¯ã¹é åãåéãããªã©ïŒã ç¹å®ã®ã¿ã¹ã¯ã®æ倧å¹çãããã»ã©éèŠã§ãªãå Žåã¯ãã³ãŒãã®ãããããããèæ ®ããŠãNlogNãªãã·ã§ã³ã§åæ¢ããå¿ èŠããããŸãã 次ã«ããããã®ã«ããŽãªãã1ã€ã®å®è¡ã¢ã«ãŽãªãºã ã䜿çšããŸãã
OïŒNlogNïŒããã
ãããåäœã®äžŠã¹æ¿ãã®ä»çµã¿ãæãåºããŠãã ããããŸããäžäœã«åºã¥ããŠã«ãŠã³ãããããšã§èŠçŽ ããã±ããã«åé ãã次ã«æ¬¡ã®ãããã§åãããšãè¡ããŸãã ããã§ã¯ãåæ§ã®åäœãããŸããããŸã å°ãç°ãªããŸã-ãããåäœã®äžŠã¹æ¿ãããµãã£ãã¯ã¹ã«çŽæ¥é©çšãããšãOïŒN 2 ïŒãåŸãããŸãã
ããã¹ãããã§ãæåã®æåHã«åŸã£ãŠè¡ããœãŒãïŒãŸãã¯ãã±ããã«é 眮ïŒãããšããŸãã è¡ã®ãããã®éšåã«ãã¹ã±ããã®çªå·ãä»ããããšãã§ããŸãã ããããåæ¥å°ŸèŸS [ i ] = A [ i .. ]ã¯ãé åã®èŠçŽ ãšããŠã ãã§ãªããé åã®ä»ã®èŠçŽ ã®äžéšãšããŠãç¹ã«æ¥å°ŸèŸS [ iH ]ã®äœçœ®Hã®éšåæååãšããŠãèŠãããŸã ïŒããããããããããã«ãæ«å°Ÿã®å¢çå¹æãçç¥ããŸãïŒæåå-ç®çã®æ°ã®ã»ã³ããã«ãæåŸãŸã§æžã蟌ãããšã§åé¿ã§ããŸãïŒã ã€ãŸããæåã®Hãµãã£ãã¯ã¹æåã«ãã¹ã±ããçªå·ãä»ããŠã2çªç®ã®Hæåã«ãèªåçã«çªå·ãä»ããŸãã 次ã«ãïŒããã¹ãããã®ïŒãã¹ã±ããçªå·ã§æ§æããããã¢ã®ã»ãããååŸããŸãã ãããã®ãã¢ããããåäœã®ãœãŒãã§ãœãŒããããšã2Hã®æåã®æåã§ãã¹ã±ããã«è©°ã蟌ãŸããè¡ã®OïŒNïŒãåŸãããŸãã ãããã£ãŠãåã¹ãããã§åŠçãããæåã®æ°ã¯2åã«ãªããŸãã ããã«ãããOïŒlogNïŒã¹ããããšOïŒNlogNïŒã¢ã«ãŽãªãºã ã®å šäœçãªè€éããäžããããŸãã
æåã®ã¹ãããã«é¢ããå¥ã®å°ããªã³ã¡ã³ãã 次ã®ã¹ãããã§ãã¹ã±ããçªå·ããœãŒãããå¿ èŠããããããããããããšã®ãœãŒãã§åé¡ãåŒãèµ·ãããªãå Žåãæåã®ã¹ãããã¯æåã®æåã§è¡ããœãŒãããããšã§ãã ã¢ã«ãã¡ãããã®æ§è³ªã«ãã£ãŠã¯ããããåäœã®äžŠã¹æ¿ããã§ããªãããšãå€æããå ŽåããããŸãã 次ã«ãOïŒNlogNïŒè€é床ãšã®æ¯èŒã«åºã¥ããŠä»ã®ãœãŒããé©çšããOïŒNïŒãè¶ ãããã¹ââã±ããç¯å²ãèŠã€ããããšãã§ããŸãã ããã«ãããã¢ã«ãŽãªãºã ã®å šäœçãªè€éãã¯å€ãããŸããã
OãããïŒNïŒ
ããã¯KarkainenãšSandersã«ãã£ãŠ2003幎ã«å ¬éãããããªãæ°ããã¢ã«ãŽãªãºã ã§ãã ãã®ã¢ã«ãŽãªãºã ã¯ã¢ã«ãã¡ãããã§ã®ã¿æ©èœãããã®æåã¯OïŒNïŒæéã§çªå·ä»ãã§ããããšãããã«èŠåããå¿ èŠããããŸãïŒçªå·ä»ãã¯ãœãŒããšåçã§ããã€ãŸãããããåäœã®ãœãŒãã§OïŒNïŒã§ãœãŒãã§ããå¿ èŠããããŸãïŒã ãã®ä»ã¯ãŸãã§ãããããã§ãèµ·ãããŸãã
ã¢ã«ãŽãªãºã ã¯ååž°çã§ããã€ãŸãããã段éã§ãé·ããçãæååã®æ¥å°ŸèŸé åãèŠã€ãããšããåãåé¡ãçºçããŸãã ãã·ã·ããã®äŸãèããŠã¿ãŸãããã ãããã£ãŠãæåã«è¡ãããšã¯ã1ãNã®æ°åã䜿çšããŠã·ã³ãã«ã«çªå·ãä»ããæ°åã®ã¢ã«ãã¡ãããã«ç§»åããããšã§ãã åè¿°ããããã«ãããã¯OïŒNïŒãããåäœã®äžŠã¹æ¿ãã§å®è¡ã§ããŸãã ãã®åŸãå ã®ãå®éã®ãæåã«ã¯èå³ããªããæååã®æ°å€è¡šçŸã®ã¿ã䜿çšããŸãã ããã¯ããã€ãŠã¯æ°å€ã·ãŒã±ã³ã¹ã§ã¯ãªãã£ãããšãå¿ããããšãã§ããŸãã
次ã«ãããã¹ãå ã®ãã¹ãŠã®ãã©ã€ã°ã©ã ãå«ãã¹ãŒããŒã¢ã«ãã¡ããããäœæãããã®æ°ããã¢ã«ãã¡ãããã®æåã«èŸæžåŒé åºã§çªå·ãä»ããŸãã ãããã®ãã©ã€ã°ã©ã ãæååå ã®æåã«ãããªãããšã¯æããã§ãïŒäžèŽãããã®ãããå Žåãé€ããŸãïŒã ãã®ã¢ã«ãã¡ããããå¹æçã«äœ¿çšã§ããããã«ãããããæ¯åã¹ãŒããŒã¢ã«ãã¡ãããã§ãã©ã€ã°ã©ã ãæ€çŽ¢ãããã®èŸæžåŒäœçœ®ïŒèŸæžåŒäœçœ®ã¯ã©ã³ã¯ãšãåŒã°ããïŒãè¿ããªãã·ã§ã³ã¯ããŒã«ããŸããã ã©ã®ãããªãã©ã€ã°ã©ã ã®åé¡ããŸã£ããçºçããªãããã«ãããã«äžä»ãæåã«çªå·ãä»ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãå ¥åè¡ã®åæåãäžèŽãããå¿ èŠããããŸãïŒæ°åã§ããããå¿ããŠããŸãããïŒïŒãã®äœçœ®ã®ãã©ã€ã°ã©ã çªå·ã ããã¯ãå ã®è¡ããã®ãã¹ãŠã®ãã©ã€ã°ã©ã ãïŒè€è£œãšãšãã«ïŒãããããšã«ãœãŒããããã©ã€ã°ã©ã ã®å ã®äœçœ®ãç¶æããããšã«ãã£ãŠè¡ãããŸãã ãã®å Žåã®åŸç¶ã®çªå·ä»ãã¯é£ãããããŸããã
ããšãã°ã A = â mississippiâããããã©ã€ã°ã©ã {misãissãssiã... ppiãpi $ãi $$}ãããã³èŸæžåŒé åº{i $$ãippãissã... ssi}ãååŸã§ããŸãã ã»ã³ããã«ãå¿ èŠã«å¿ããŠè¡ãè£å®ããããããæå°æåãšèŠãªããŸãã
å ã®è¡ïŒ | m | ç§ã¯ | s | s | ç§ã¯ | s | s | ç§ã¯ | p | p | ç§ã¯ |
æ°å€æååïŒ | 2 | 1 | 4 | 4 | 1 | 4 | 4 | 1 | 3 | 3 | 1 |
ãã©ã€ã°ã©ã ïŒ | ãã¹ | iss | ssi | sis | iss | ssi | äžå£ | ipp | ppi | pi $ | ç§ã¯$$ |
ããªã°ã©ã ã®çªå·ä»ãïŒ | 4 | 3 | 9 | 8 | 3 | 9 | 7 | 2 | 6 | 5 | 1 |
ãã®æç¹ã§ãè¡ã®ãã¹ãŠã®ãã©ã€ã°ã©ã ãç°ãªãããšãå€æããå ŽåããããŸãã ãã©ã€ã°ã©ã ãç°ãªãå ŽåãèŸæžåŒé åºãæ¥å°ŸèŸã®èŸæžåŒé åºã決å®ãããããããã¯åæã®çµäºæ¡ä»¶ãšããŠäœ¿çšã§ããŸãïŒãã®æ¡ä»¶ã¯äœ¿çšã§ããŸããããçããæããã«ãªããŸã§è¡ãçããã®ã«æžããç¶ããã ãã§ãïŒã æåã®æååã¯ããã©ã€ã°ã©ã ã®åœ¢åŒã§3ã€ã®æ¹æ³ã§è¡šçŸã§ããŸããæååèªäœãããªã°ã©ã ã«åå²ãããæåã®æåã®ãªãæååãæåã®2æåã®ãªãæååã§ãã æååã®ãããã®è¡šçŸãT 0 ãT 1ãããã³T 2ãšåŒã³ãŸãã ãããã®ããããã¯ããªãªãžãã«ããã3åçãã§ãã ãŒãããäœçœ®ãæ°ããå Žåããããã®è¡šçŸã¯äœçœ®i mod 3 = 0ãi mod 3 = 1ããã³i mod 3 = 2ã®ãµãã£ãã¯ã¹ã®ã°ã«ãŒãã«å¯Ÿå¿ããŠåŒã³åºãããšãã§ããŸãã
T 0 ïŒ | ãã¹ | sis | äžå£ | pi $ |
4 | 8 | 7 | 5 | |
T 1 ïŒ | iss | iss | ipp | ç§ã¯$$ |
3 | 3 | 2 | 1 | |
T 2 ïŒ | ssi | ssi | ppi | |
9 | 9 | 6 |
次ã«ããã§ã€ã³ããè³ã§äœãããŸããããã®æå³ã¯åŸã§æããã«ãªããŸãïŒå ·äœçã«ã¯ãT 1ãšT 2ã® 3ã€ã®è¡ã®ãã¡2ã€ãããã©ã€ã°ã©ã ã®åœ¢ã§æ瀺ããé£çµããŠãååž°åŒã³åºãã§åãã¢ã«ãŽãªãºã ã«æž¡ããŸãã æããã«ãéä¿¡ãããæååã®é·ãã¯å ã®æååããã1/3çããªããŸãã ã¢ã«ãŽãªãºã ã®çµäºæã«ã¯ãæ¥å°ŸèŸé åïŒãŸãã¯ãåçã®ã©ã³ã¯ã®é åïŒãå¿ èŠã§ãã ãã©ã€ã°ã©ã ããæ°è¡ã«æ»ããšãã°ã«ãŒã1ãš2ã®ãµãã£ãã¯ã¹éã®èŸæžåŒé åºã«é¢ããæ å ±ãåŸãããŸãã
ã°ã«ãŒã0ã®æ¥å°ŸèŸã¯ãã·ã³ãã«ãšã°ã«ãŒã1ã®æ¥å°ŸèŸããæããã¢ããŸãã¯2æåã®ããªãã«ãšã°ã«ãŒã2ã®æ¥å°ŸèŸãšããŠè¡šãããšãã§ããŸããA [3k ..] =ïŒA [3k]ã A [3k + 1 ..]ïŒ= ïŒA [3k]ãA [3k + 1]ã A [3k + 2 ..]ïŒã æ¥å°ŸèŸã®ä»ã®ã°ã«ãŒããé£æ¥ããæ¥å°ŸèŸã«å€æããããã«ãåæ§ã®åŒãæžãããšãã§ããŸãã ã¿ã€ã0ã®æ¥å°ŸèŸãã·ã³ãã«ãšã¿ã€ã1ã®æ¥å°ŸèŸã®ãã¢ãšããŠè¡šçŸããŸãïŒããæ£ç¢ºã«ã¯ãã¿ã€ã1ã®æ¥å°ŸèŸã®ã©ã³ã¯ãæ¥å°ŸèŸèªäœã¯ç§ãã¡ã«ãšã£ãŠèå³æ·±ããã®ã§ã¯ãããŸããïŒã
ãã®æ®µéã§ãçžäºã«ãœãŒããããã¿ã€ã1ããã³2ã®ãµãã£ãã¯ã¹ãããã³ã¿ã€ã0ã®ãœãŒãããããµãã£ãã¯ã¹ã®åœ¢åŒã§ååž°çãªé¢æ°åŒã³åºãã®çµæãåŸãããŸããã¿ã€ã0ãµãã£ãã¯ã¹ãã¿ã€ã1ãšæ¯èŒããã«ã¯ãã¿ã€ã0ãµãã£ãã¯ã¹ãã¿ã€ã1ã«ãã¿ã€ã1ãã¿ã€ã2ã«å€æããå¿ èŠããããŸããïŒA [3l]ã A [3l + 1 ..]ïŒVSïŒA [3m + 1]ã A [3m + 2] ..ïŒã ãããã®2ã€ã®ãã¢ãæ¯èŒããã®ã¯ç°¡åã§ãïŒæåã®æåãé åºã決å®ããããçããå Žåãé åºã¯ã°ã«ãŒã1ãš2ã®ãµãã£ãã¯ã¹ã®é åºã決å®ããŸããããã¯ããã®ã¢ã«ãŽãªãºã ã®ååž°åŒã³åºãã®çµæããããããŸãã ã¿ã€ã0ãš2ã®ãµãã£ãã¯ã¹ãæ¯èŒããããã«ããã§ãŒã³ã¯ãããã«å€§ãããªããŸãããæ¬è³ªã¯åãã§ãïŒïŒA [3l]ãA [3l + 1]ã A [3l + 2 ..]ïŒVSïŒA [3m + 2]ãA [3 ïŒm + 1ïŒ]ã A [3ïŒm + 1ïŒ+1 ..]ïŒã
äžèŠãããšããããªãããããã¹ãŠç·åœ¢ã®è€éããããããã®ãã¯æããã§ã¯ãããŸããã æåã«ãååž°åŒã³åºããé€ããã¹ãŠã«å¯ŸåŠããŸãã äžä»ãæåã®ãããåäœã®äžŠã¹æ¿ããããŒãã³ã°ãµãã£ãã¯ã¹ã¯ãã¹ãŠOïŒNïŒãã°ã«ãŒã0ã®ãµãã£ãã¯ã¹ã®ãããåäœã®äžŠã¹æ¿ãããã³äžŠã¹æ¿ããããé åã®ããŒãžãOïŒNïŒã§ãã ååž°åŒã³åºã-å ã®æååã®é·ãã®2/3ã®ã¢ã«ãŽãªãºã ãåŒã³åºããããã¢ã«ãŽãªãºã ã®è€éãã¯TïŒNïŒ= TïŒ2N / 3ïŒ+ OïŒNïŒã§ãã ãã®åŒãèªåèªèº«ã«ä»£å ¥ããŠãã€ã³ããããšã2/3ã®ä¿æ°ã§çæ¯æ°åã®åèšãåŸããããããOïŒNïŒãå¶éãããŸãã ãããã£ãŠãçµæã®è€éãã¯OïŒNïŒã§ãã
ãããã«
ããããæ¥å°ŸèŸé åã®é©çšæ¹æ³ãšæ§ç¯æ¹æ³ã§ãã ã¢ã«ãŽãªãºã ã¯éåžžã«èšå€§ã§ãããããã¹ãããšã¯éåžžã«é«åºŠãªã¿ã¹ã¯ã§ãã ç§ã¯ãããããªãäžè¬çãªçšèªã§èª¬æããŸããããæãããªçç±ã§ã³ãŒããæäŸããŸããã§ãã-èšèãšã³ãŒããå€ãããã§ãããã ã芧ã®ããã«ãã¢ã«ãŽãªãºã ã¯é«éã§ãããå®è£ ã®è€éãã®ç¹ã§ãããã«é ããããOïŒNïŒã§ã¯ãªãOïŒNïŒã®å Žåãªã©ãæ¬åœã«ãããè¡ãå¿ èŠããããã©ãããäœåºŠãèããçç±ããããŸãã
ãŸãããå®æããå®è£ ãã©ãã§èŠãããšãã§ãããããããã£ãšèªãå Žæããªã©ã®ãããªè³ªåãäºæ³ããŠããŸãã ãŠã£ãããã£ã¢ã®ããŒãžãååšãããšäž»åŒµããŠããããç§ã¯å人çã«ããã ã³ã³ãã¬ãŒã¿ãè¿œå ãããã¹ã¿ã€ã«ã®æ¢è£œã®å®è£ ãèŠãããšããªãã ãããšããã«ã¯èª¬æãšå®è£ ããããŸãã ããã«ãKarkainenãšSanders ã«ããå ã®èšäºã«ãé åæ§ç¯ã³ãŒãããããŸãã NlogNã®æ§ç¯ã«ã€ããŠã¯ãManberãšMyersã®èšäºã§èªãããšãã§ããŸããUdiManberãGene Myers-ããµãã£ãã¯ã¹é åïŒãªã³ã©ã€ã³æååæ€çŽ¢ã®æ°ããæ¹æ³ãã