File:LongestSubstring.pdf
Summary
Description |
English: Example of the Longest common substring problem that has two different solutions: the strings "BADANAT" and "CANADAS" share the maximal-length substrings "ADA" and "ANA". Note that the substring occurrences overlap; yet no longer common substring can be obtained by 'uniting' them. |
Date | |
Source | Own work |
Author | Jochen Burghardt |
Other versions | File:LongestSubstring.pdf * File:LongestSubstring svg.svg |
LaTeX source code |
---|
\documentclass[12pt]{article}
\setlength{\unitlength}{1mm}
\usepackage[pdftex]{color}
\usepackage[paperwidth=36\unitlength,paperheight=16\unitlength]{geometry}
\setlength{\topmargin}{-36mm}
\setlength{\textwidth}{36\unitlength}
\setlength{\textheight}{16\unitlength}
\setlength{\oddsidemargin}{-23mm}
\setlength{\parindent}{0cm}
\pagestyle{empty}
% colors
\definecolor{fANA} {rgb}{0.00,0.70,0.00}
\definecolor{fADA} {rgb}{0.00,0.00,0.70}
\definecolor{fANAx} {rgb}{0.50,0.99,0.50}
\definecolor{fADAx} {rgb}{0.50,0.50,0.99}
%\definecolor{bANA} {rgb}{0.80,0.99,0.80}
%\definecolor{bADA} {rgb}{0.80,0.80,0.99}
%\definecolor{bAxA} {rgb}{0.60,0.99,0.99}
\begin{document}
\begin{picture}(33,13)%
% substring backgrounds
%\textcolor{bANA}{\put( 4,0){\makebox(0,0)[bl]{\rule{10mm}{3mm}}}}%
%\textcolor{bAxA}{\put(14,0){\makebox(0,0)[bl]{\rule{ 5mm}{3mm}}}}%
%\textcolor{bADA}{\put(19,0){\makebox(0,0)[bl]{\rule{10mm}{3mm}}}}%
%
%\textcolor{bADA}{\put( 4,10){\makebox(0,0)[bl]{\rule{10mm}{3mm}}}}%
%\textcolor{bAxA}{\put(14,10){\makebox(0,0)[bl]{\rule{ 5mm}{3mm}}}}%
%\textcolor{bANA}{\put(19,10){\makebox(0,0)[bl]{\rule{10mm}{3mm}}}}%
%
% strings
\put( 0,0){\makebox(0,0)[bl]{\sf C}}%
\put( 5,0){\makebox(0,0)[bl]{\sf A}}%
\put(10,0){\makebox(0,0)[bl]{\sf N}}%
\put(15,0){\makebox(0,0)[bl]{\sf A}}%
\put(20,0){\makebox(0,0)[bl]{\sf D}}%
\put(25,0){\makebox(0,0)[bl]{\sf A}}%
\put(30,0){\makebox(0,0)[bl]{\sf S}}%
%
\put( 0,10){\makebox(0,0)[bl]{\sf B}}%
\put( 5,10){\makebox(0,0)[bl]{\sf A}}%
\put(10,10){\makebox(0,0)[bl]{\sf D}}%
\put(15,10){\makebox(0,0)[bl]{\sf A}}%
\put(20,10){\makebox(0,0)[bl]{\sf N}}%
\put(25,10){\makebox(0,0)[bl]{\sf A}}%
\put(30,10){\makebox(0,0)[bl]{\sf T}}%
%
% substring matches
\textcolor{fANA}{\put( 4,3.5){\line(0,1){0.5}}}%
\textcolor{fANA}{\put(19,3.5){\line(0,1){0.5}}}%
%
\textcolor{fANA}{\put(14,8){\line(0,1){0.5}}}%
\textcolor{fANA}{\put(29,8){\line(0,1){0.5}}}%
%
\textcolor{fANAx}{\put( 4,4){\line(5,2){10}}}%
\textcolor{fANAx}{\put(19,4){\line(5,2){10}}}%
%
\textcolor{fADA}{\put(14,4.5){\line(0,1){0.5}}}%
\textcolor{fADA}{\put(29,4.5){\line(0,1){0.5}}}%
%
\textcolor{fADA}{\put( 4,9){\line(0,1){0.5}}}%
\textcolor{fADA}{\put(19,9){\line(0,1){0.5}}}%
%
\textcolor{fADAx}{\put(14,5){\line(-5,2){10}}}%
\textcolor{fADAx}{\put(29,5){\line(-5,2){10}}}%
%
% substrings
\thicklines%
\textcolor{fANA}{\put( 4,4){\line(1,0){15}}}%
\textcolor{fANA}{\put(14,8){\line(1,0){15}}}%
\textcolor{fADA}{\put(14,5){\line(1,0){15}}}%
\textcolor{fADA}{\put( 4,9){\line(1,0){15}}}%
\end{picture}
\end{document}
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.