Block

Edit

Models

for

Approximate

String

Matching

Daniel

Lopresti

Andrew

Tomkins

dpl@research.panasonic.com

andrewt@cs.cmu.edu

Matsushita

Information

Technology

Laboratory

Panasonic

Technologies

Inc.

Two

Research

Way

Princeton

NJ

USA

November

Abstract

In

this

paper

we

examine

the

concept

of

string

block

edit

distance

where

two

strings

A

and

B

are

compared

by

extracting

collections

of

substrings

and

placing

them

into

correspondence

This

model

accounts

for

certain

phenomena

encountered

in

important

real-world

applications

including

pen

computing

and

molecular

biology

The

basic

problem

admits

a

family

of

variations

depending

on

whether

the

strings

must

be

matched

in

their

entireties

and

whether

overlap

is

permitted

We

show

that

several

variants

are

NP-complete

and

give

polynomial-time

algorithms

for

solving

the

remainder

Introduction

The

edit

distance

model

for

string

comparison

-LSB-

-RSB-

has

found

widespread

application

in

fields

ranging

from

molecular

biology

to

bird

song

classification

-LSB-

-RSB-

A

great

deal

of

research

has

been

devoted

to

this

area

and

numerous

algorithms

have

been

proposed

for

computing

edit

distance

efficiently

-LRB-

e.g.

-LSB-

-RSB-

-RRB-

In

a

previous

paper

-LSB-

-RSB-

we

introduced

a

new

application

of

edit

distance

in

the

realm

of

pen

computing

Approximate

ink

matching

or

AIM

is

the

concept

of

matching

handwritten/drawn

queries

against

an

existing

ink

database

While

ink

is

an

expressive

two-dimensional

medium

its

creation

when

viewed

in

the

temporal

domain

is

an

inherently

linear

process

the

motion

of

a

stylus

tip

against

a

writing

surface

Ink

can

be

treated

as

a

string

by

taking

pen

input

from

a

digitizing

tablet

and

segmenting

it

into

strokes

extracting

a

standard

set

of

features

-LRB-

e.g.

stroke

length

total

angle

traversed

-RRB-

and

clustering

the

resulting

vectors

into

a

smaller

number

of

basic

stroke

types

It

then

becomes

possible

to

compare

strings

over

this

ink

alphabet

using

approximate

string

matching

techniques

To

be

presented

at

the

Second

South

American

Workshop

on

String

Processing

Valpara

so/Vi

del

Mar

Chile

April

For

handwritten

text

-LRB-

English

and

Japanese

cursive

and

printed

-RRB-

our

empirical

studies

indicate

that

this

approach

which

is

writer-dependent

performs

quite

well

However

the

situation

becomes

more

complicated

for

pictorial

data

Certain

substructures

within

a

larger

image

can

correspond

stroke-for-stroke

but

these

basic

blocks

may

have

been

drawn

by

the

user

in

an

otherwise

arbitrary

order

Figure

demonstrates

this

the

two

trees

in

Picture

A

are

drawn

last

while

the

tree

in

Picture

B

is

drawn

first

Moreover

if

the

goal

is

to

search

a

database

the

best

match

may

be

imprecise

in

the

sense

that

certain

elements

are

omitted

or

repeated

This

phenomenon

is

also

illustrated

in

Figure

Intuitively

we

judge

the

two

pictures

to

be

quite

similar

even

though

Picture

A

has

an

extra

tree

and

is

missing

the

car

and

driveway

Existing

string

matching

algorithms

are

not

flexible

enough

to

capture

these

forms

of

block

motion

AA

bstract

Basic

BlocksP

icture

BA

Block

String

Matching

Figure

Approximate

string

matching

applied

to

hand-drawn

pictorial

data

Likewise

in

genetic

sequence

alignment

some

biologists

suggest

that

comparisons

based

on

simple

edit

distance

may

fail

to

account

for

certain

common

evolutionary

processes

-LSB-

-RSB-

Global

dynamic

programming

alignments

of

such

rearranged

sequences

yield

unpredictable

evolutionarily

confusing

results

Global

alignment

methods

are

generally

incapable

of

dealing

with

intrasequence

rearrangements

yet

this

phenomenon

is

quite

common

among

mosaic

and

repetitive

sequence

proteins

-LSB-

pg

-RSB-

So-called

local

schemes

such

as

the

well-known

BLAST

algorithm

-LSB-

AGM

-RSB-

can

determine

subregions

of

similarity

within

two

longer

sequences

However

to

the

best

of

our

knowledge

there

presently

exists

no

fully

automatic

technique

for

correlating

the

relationships

between

the

multiple

local

matches

returned

Manual

inspection

of

a

dot

matrix

plot

appears

to

be

the

most

popular

approach

for

addressing

this

problem

today

As

shown

in

Figure

to

compare

two

sequences

A

and

B

a

table

of

size

jAj?jBj

from

-LSB-

-RSB-

Dot

matrix

analysis

is

the

only

currently

available

tool

that

deals

sensibly

with

this

phenomenon

-LSB-

pg

-RSB-

is

built

and

a

dot

placed

at

the

-LRB-

i

j

-RRB-

th

entry

if

the

ith

symbol

of

A

is

the

same

as

the

jth

symbol

of

B.

To

reduce

noise

a

minimum

number

of

exact

matches

within

a

window

centered

around

the

location

in

question

can

be

required

before

a

dot

is

placed

there

In

our

example

the

window

is

nucleotides

and

must

contain

at

least

matches

The

resulting

plot

is

then

examined

visually

for

interesting

similarities

Dot

Plot

of

B.taurus

DNA

sequence

x

B.taurus

BoIFN-alpha

A

mRNA

Base

Window

Stringency

Points

taurus

BoIFN-alpha

AmRNA

-LRB-

to

-RRB-

B.taurus

DNA

sequence

-LRB-

to

-RRB-

Figure

Dot

matrix

plot

of

two

short

genetic

sequences

In

this

paper

we

describe

a

family

of

models

for

the

string

block

edit

problem

These

formalize

in

a

succinct

and

rigorous

way

the

notions

illustrated

in

the

preceding

examples

We

prove

that

certain

variants

are

NP-complete

and

give

polynomial-time

algorithms

for

the

remainder

We

conclude

the

paper

by

suggesting

some

directions

for

further

research

Block

Edit

Models

Standard

edit

distance

allows

the

relationship

between

two

strings

to

be

expressed

graphically

by

means

of

a

trace

An

example

showing

how

quick

brown

fox

can

be

mapped

into

kick

draw

flax

is

q

u

i

c

k

b

r

o

w

n

f

o

x

k

i

c

k

d

r

a

w

f

l

a

x

The

special

symbol

is

used

to

represent

the

absence

of

a

character

A

transformation

from

a

character

into

is

considered

a

deletion

-LRB-

e.g.

u

;-RRB-

from

into

a

character

an

insertion

-LRB-

e.g.

a

-RRB-

and

from

one

character

into

another

different

character

a

substitution

-LRB-

e.g.

q

k

-RRB-

As

a

rule

the

arrows

in

a

trace

are

not

allowed

to

cross

Moreover

the

character-to-character

correspondence

is

determined

on

an

individual

basis

with

no

regard

to

higher-level

structure

Consider

now

a

trace

comparing

the

strings

hello

world

and

world

hello

is

dictated

by

the

model

and

the

dynamic

programming

algorithm

used

to

perform

the

computation

h

e

l

l

o

w

o

r

l

d

w

o

r

l

d

h

e

l

l

o

The

cost

of

this

alignment

is

five

deletions

and

five

insertions

By

overlooking

the

higher-level

structure

-LCB-

the

motion

of

the

word

hello

from

the

beginning

of

the

string

to

the

end

-LCB-

traditional

edit

distance

-LRB-

e.g.

-LSB-

-RSB-

-RRB-

produces

a

trace

that

seems

to

miss

the

true

relationship

between

the

two

strings

There

is

no

obvious

way

of

taking

the

result

returned

by

simple

edit

distance

and

using

it

to

generate

a

more

representative

block

matching

Figure

presents

a

block

trace

relating

the

strings

The

quick

brown

fox

jumps

over

the

lazy

dog

and

Jump

over

the

brown

fox

lazy

dog

Quick

This

captures

both

the

low-level

notion

of

approximate

string

matching

-LRB-

e.g.

the

close

similarity

between

the

blocks

jumps

over

the

and

Jump

over

the

-RRB-

as

well

as

the

higher-level

concept

of

block

motion

We

seek

algorithms

capable

of

producing

traces

such

as

this

String

BT

heq

uickb

rown

foxj

umps

over

thel

azy

dog.J

ump

over

theb

rown

fox

l

azy

dog.Q

uick!String

A

Figure

Example

of

a

block

trace

We

now

present

a

more

formal

definition

of

a

string

block

edit

model

Substring

Families

Assume

we

have

a

finite

alphabet

Let

A

-LSB-

am

-RSB-

and

B

-LSB-

bn

-RSB-

be

strings

over

the

alphabet

ai

bj

We

say

that

a

t-block

substring

family

of

A

Ajt

is

a

multiset

containing

t

substrings

of

A

some

of

which

may

be

identical

In

the

following

we

will

write

Ajt

fA

-LRB-

-RRB-

A

-LRB-

t

-RRB-

g

with

the

understanding

that

the

A

-LRB-

i

-RRB-

's

need

not

be

distinct

A

corresponding

t-block

substring

family

of

B

Bjt

is

a

multiset

of

t

substrings

of

B

If

the

substrings

in

Ajt

do

not

overlap

we

say

the

family

is

disjoint

If

each

character

of

A

is

contained

in

some

substring

we

say

the

family

represents

a

cover

of

A.

Thus

Figure

shows

a

mapping

between

substring

families

such

that

on

the

left

is

a

disjoint

cover

and

on

the

right

is

neither

disjoint

nor

a

cover

Figure

illustrates

that

substantial

overlap

can

occur

between

candidate

substrings

of

genetic

sequences

hence

there

is

an

argument

for

preferring

substring

families

that

are

not

necessarily

disjoint

in

this

case

Finally

in

Figure

one

of

the

substring

families

is

a

disjoint

cover

while

the

other

is

disjoint

but

not

a

cover

In

general

we

may

require

that

either

or

both

of

the

substring

families

be

disjoint

and/or

a

cover

Each

possible

combination

of

constraints

represents

a

particular

block

edit

model

For

succinctness

we

introduce

the

following

notation

C

must

be

a

cover

C

need

not

be

a

cover

D

must

be

disjoint

D

need

not

be

disjoint

To

refer

to

the

model

in

which

the

first

substring

family

must

be

a

disjoint

cover

and

the

second

substring

family

is

unconstrained

we

write

CD-CD

-LRB-

Note

from

a

computational

standpoint

by

symmetry

CD-CD

is

exactly

the

same

problem

-RRB-

Block

Edit

Distance

Before

defining

block

edit

distance

we

require

an

underlying

function

dist

that

returns

the

cost

of

corresponding

a

substring

of

A

with

a

substring

of

B

dist

fi

j

j

i

j

jAjg

fk

l

j

k

l

jBjg

R

In

practice

it

is

natural

to

assume

that

dist

is

traditional

string

edit

distance

but

any

cost

function

could

be

used

The

algorithms

we

give

work

for

arbitrary

measures

and

the

reductions

work

for

bivalued

measures

so

the

generality

of

the

cost

function

does

not

affect

the

difficulty

of

the

problem

The

block

edit

distance

B

between

two

strings

A

and

B

is

defined

as

the

best

way

to

choose

substring

families

of

A

and

B

and

correspond

each

member

of

Ajt

with

some

member

of

Bjt

For

each

pairing

a

cost

is

assessed

based

on

the

distance

between

the

two

substrings

The

correspondence

between

blocks

is

given

by

a

permutation

oe

S

-LRB-

t

-RRB-

from

the

permutation

group

on

t

elements

We

impose

the

additional

restriction

that

if

i

j

and

A

-LRB-

i

-RRB-

A

-LRB-

j

-RRB-

then

B

-LRB-

oe

-LRB-

i

-RRB-

-RRB-

B

-LRB-

oe

-LRB-

j

-RRB-

-RRB-

That

is

a

particular

pair

of

blocks

can

not

be

placed

into

correspondence

more

than

once

This

allows

us

to

keep

the

measure

from

diverging

if

a

negative-cost

pairing

exists

and

the

substring

families

do

not

have

to

be

disjoint

More

formally

B

-LRB-

A

B

-RRB-

min

t

min

Ajt

Bjt

min

-LRB-

t

-RRB-

-LRB-

tX

i

dist

A

-LRB-

i

-RRB-

B

-LRB-

oe

-LRB-

i

-RRB-

-RRB-

-RRB-

-LRB-

-RRB-

Equation

does

not

specify

whether

the

particular

substring

families

must

be

covers

disjoint

or

both

In

this

paper

we

examine

the

various

cases

show

which

are

hard

and

give

algorithms

for

those

that

are

solvable

in

polynomial

time

Table

summarizes

our

results

CD-CD

Block

Edit

Distance

is

NP-complete

In

this

section

we

show

that

if

both

substring

families

must

be

disjoint

covers

the

block

edit

distance

problem

is

NP-complete

In

a

later

section

we

extend

the

same

reduction

to

the

other

hard

versions

of

the

problem

Theorem

CD-CD

block

edit

distance

is

NP-complete

Proof

Membership

in

NP

is

trivial

We

must

show

that

the

problem

is

NP-hard

The

reduction

is

from

uniprocessor

scheduling

From

Garey

and

Johnson

-LSB-

-RSB-

per

common

usage

we

refer

to

dist

as

a

distance

when

in

fact

it

is

more

general

than

this

it

need

not

be

symmetric

can

take

on

negative

values

and

does

not

have

to

obey

the

triangle

inequality

distance

between

two

blocks

could

be

augmented

with

information

about

how

far

apart

they

are

in

the

original

A

and

B

strings

The

algorithms

we

shall

present

can

be

trivially

extended

to

allow

for

this

CD

CD

CD

CD

CD

O

-LRB-

-RRB-

Section

CD

O

-LRB-

-RRB-

NP-complete

Section

Section

CD

O

-LRB-

-RRB-

NP-complete

NP-complete

Section

Section

Section

CD

O

-LRB-

-RRB-

NP-complete

NP-complete

NP-complete

Section

Section

Section

Section

Table

Summary

of

the

results

presented

in

this

paper

Sequencing

With

Release

Times

and

Deadlines

Instance

Set

T

of

jobs

and

for

each

Jobt

T

a

length

l

-LRB-

t

-RRB-

Z

a

release

time

r

-LRB-

t

-RRB-

Z

and

a

deadline

d

-LRB-

t

-RRB-

Z

Question

Is

there

a

one-processor

schedule

for

T

that

satisfies

the

release

time

constraints

and

meets

all

the

deadlines

We

take

the

string

alphabet

to

be

Assume

that

the

number

of

jobs

in

the

scheduling

problem

is

N

jT

j.

For

n

Ng

we

define

the

string

-LRB-

j

-RRB-

to

be

-LRB-

j

-RRB-

N?j

z

-RCB-

-LCB-

j

z

-RCB-

-LCB-

N

z

-RCB-

-LCB-

Thus

for

all

j

j

-LRB-

j

-RRB-

j

and

-LRB-

-RRB-

We

must

now

specify

two

strings

and

a

cost

function

as

input

to

the

block

edit

distance

algorithm

String

A

will

represent

time

and

string

B

will

represent

the

jobs

Let

D

be

the

latest

deadline

D

maxfd

-LRB-

t

-RRB-

g.

Strings

A

and

B

will

have

length

Note

that

since

the

scheduling

problem

is

NP-hard

in

the

strong

sense

we

can

assume

that

the

size

of

the

input

is

O

-LRB-

D

-RRB-

so

these

strings

are

polynomial-sized

We

assume

without

loss

of

generality

that

P

i

l

-LRB-

i

-RRB-

D

That

is

if

all

jobs

are

scheduled

in

time

then

all

units

of

time

through

the

final

deadline

will

be

used

If

this

is

not

the

case

we

can

add

to

the

list

of

jobs

D?P

i

l

-LRB-

i

-RRB-

additional

jobs

with

length

release

time

and

deadline

D

to

meet

the

constraint

without

changing

the

problem

Figure

depicts

the

two

strings

TI

MEDTIM

N

tring

A

J

tring

B

J

OB

jJ

OBNTIM

IM

IM

EiT

IM

Figure

Strings

A

and

B

for

the

NP-completeness

reduction

Each

of

the

time-step

blocks

in

string

A

is

a

filled-in

copy

of

the

template

shown

in

Figure

We

need

some

new

notation

for

referencing

these

substrings

We

will

write

A

-LSB-

Timei

-RSB-

to

refer

to

the

ith

time-step

of

A

and

A

-LSB-

Timei

Chunkj

-RSB-

to

refer

to

the

jth

chunk

of

characters

in

substring

A

-LSB-

Timei

-RSB-

As

the

figure

shows

A

-LSB-

Timei

Chunkj

-RSB-

is

made

up

of

two

components

each

of

length

The

first

is

-LRB-

j

-RRB-

if

Jobj

may

start

at

time-step

i

-LRB-

i.e.

if

and

only

if

r

-LRB-

j

-RRB-

i

-RRB-

and

-LRB-

-RRB-

otherwise

Similarly

the

second

component

is

-LRB-

j

-RRB-

if

Jobj

may

end

at

time-step

i

-LRB-

i.e.

if

and

only

if

d

-LRB-

j

-RRB-

i

-RRB-

and

-LRB-

-RRB-

otherwise

Each

time-step

block

represents

a

string

of

characters

-LRB-

j

-RRB-

if

JOBj

may

start

at

TIME

i

-LRB-

-RRB-

otherwiseC

HUNK

j

A

-LSB-

TIMEi

CHUNK

j

-RSB-

C

HUNKN

-LRB-

j

-RRB-

if

JOB

j

may

end

at

TIME

i

-LRB-

-RRB-

otherwise

-LSB-

TI

ME

i

-RSB-

Figure

Template

of

a

time-step

block

At

this

point

we

have

completely

specified

string

A

We

now

turn

to

the

structure

of

string

B

by

specifying

the

job

blocks

in

Figure

Following

the

notation

introduced

previously

we

will

write

B

-LSB-

Jobj

-RSB-

to

refer

to

the

entire

block

Jobj

Each

such

block

is

a

string

consisting

of

l

-LRB-

j

-RRB-

characters

Within

B

-LSB-

Jobj

-RSB-

each

of

the

l

-LRB-

j

-RRB-

substrings

of

characters

corresponds

to

a

time-step

so

we

will

write

B

-LSB-

Jobj

Timei

-RSB-

to

refer

to

the

ith

group

of

characters

within

B

-LSB-

Jobj

-RSB-

Finally

these

characters

are

broken

into

N

chunks

of

characters

each

of

which

corresponds

to

a

particular

task

We

will

refer

to

the

kth

chunk

within

time-step

i

in

job

j

as

B

-LSB-

Jobj

Timei

Chunkk

-RSB-

Within

B

-LSB-

Jobj

Timei

-RSB-

all

chunks

except

those

numbered

j

will

consist

of

's

We

now

give

the

procedure

for

assigning

substrings

to

each

of

the

chunks

As

in

the

construction

of

string

A

the

first

and

second

groups

of

characters

are

used

to

hold

information

about

starting

and

ending

a

job

respectively

start

-LRB-

i

j

-RRB-

ae

-LRB-

i

-RRB-

if

j

-LRB-

-RRB-

otherwise

-LRB-

-RRB-

end

-LRB-

i

j

-RRB-

ae

-LRB-

i

-RRB-

if

j

l

-LRB-

i

-RRB-

-LRB-

-RRB-

otherwise

-LRB-

-RRB-

B

-LSB-

Jobi

Timej

Chunkk

-RSB-

ae

-LRB-

-RRB-

jj

-LRB-

-RRB-

if

i

k

start

-LRB-

i

j

-RRB-

jj

end

-LRB-

i

j

-RRB-

otherwise

-LRB-

-RRB-

B

-LSB-

Jobi

Chunki

-RSB-

has

the

effect

of

constraining

job

i

to

begin

at

or

after

its

release

time

while

B

-LSB-

Jobi

Timel

-LRB-

i

-RRB-

Chunki

-RSB-

constrains

it

to

end

at

or

before

its

deadline

This

is

depicted

in

Figure

This

completes

the

specification

of

both

strings

All

that

remains

is

to

give

the

cost

function

dist

This

function

returns

for

all

pairs

of

substrings

with

the

following

exception

l

-LRB-

j

-RRB-

-LRB-

j

-RRB-

-LRB-

-RRB-

CHU

HUNK

jC

HUNKN

B

-LSB-

JOBj

TI

CHUNK

j

-RSB-

T

IM

IM

IME

l

-LRB-

j

-RRB-

B

-LSB-

JOB

j

TIM

-RSB-

B

-LSB-

JO

B

j

-RSB-

Figure

Template

of

a

job

block

dist

-LRB-

-RRB-

if

and

only

if

there

exist

indices

and

j

such

that

the

following

conditions

hold

A

-LSB-

-RSB-

A

-LSB-

-RSB-

B

-LSB-

Jobj

-RSB-

l

-LRB-

j

-RRB-

r

-LRB-

j

-RRB-

and

d

-LRB-

j

-RRB-

This

particular

cost

function

is

formulated

so

that

a

zero-cost

matching

if

one

exists

yields

a

solution

to

the

uniprocessor

scheduling

problem

We

now

prove

a

series

of

lemmas

that

will

allow

us

to

equate

block

string

matches

with

job

schedules

Lemma

The

substring

-LRB-

j

-RRB-

j

occurs

in

strings

A

and

B

only

at

block

boundaries

Proof

Break

both

strings

into

blocks

of

length

By

their

construction

each

block

consists

of

-LRB-

i

-RRB-

for

i

Any

substring

t

of

length

will

overlap

at

most

two

such

blocks

say

and

Create

s

jj

For

t

to

equal

-LRB-

j

-RRB-

for

some

j

there

must

exist

a

transition

in

s

that

corresponds

to

positions

N

and

N

in

t

But

such

transitions

occur

in

at

most

two

places

in

s

at

positions

N

and

N

-LRB-

i.e.

-RRB-

and

at

positions

and

-LRB-

i.e.

-RRB-

That

is

t

can

equal

-LRB-

j

-RRB-

if

and

only

if

t

or

t

Thus

the

substring

-LRB-

j

-RRB-

occurs

only

at

block

boundaries

for

j

This

completes

the

proof

of

Lemma

At

this

point

we

require

some

additional

notation

Consider

two

substrings

drawn

from

A

and

drawn

from

B.

Let

be

the

first

characters

of

si

and

be

the

last

characters

of

si

Our

goal

is

to

show

that

the

distance

function

defined

earlier

will

never

return

for

substrings

that

are

not

taken

from

appropriate

locations

in

A

and

B

We

do

so

by

presenting

two

sets

of

definitions

and

accompanying

lemmas

The

first

defines

a

syntactic

property

between

two

strings

and

shows

that

no

other

substrings

can

fulfill

the

zero-cost

conditions

of

dist

The

second

makes

precise

the

notion

of

appropriate

location

and

relates

it

to

the

syntactic

property

Definition

Substrings

and

have

the

match

property

if

the

following

conditions

hold

They

both

have

length

l

-LRB-

j

-RRB-

for

some

j

N

The

-LRB-

-RRB-

th

block

of

characters

in

and

are

both

-LRB-

j

-RRB-

The

block

of

characters

in

and

are

both

-LRB-

j

-RRB-

We

now

show

that

any

two

substrings

with

distance

must

have

the

match

property

Lemma

If

dist

-LRB-

-RRB-

then

substrings

and

have

the

match

property

Proof

By

the

definition

of

dist

and

the

construction

of

strings

A

and

B

the

length

condition

for

the

match

property

is

clearly

satisfied

We

now

examine

the

-LRB-

-RRB-

th

block

of

characters

in

and

For

the

time-step

substring

this

will

be

the

first

characters

of

A

-LSB-

Chunkj

-RSB-

and

assuming

that

Jobj

may

start

at

time-step

-LRB-

we

know

that

r

-LRB-

j

-RRB-

from

the

definition

of

dist

-RRB-

this

will

be

-LRB-

j

-RRB-

Likewise

for

the

job

substring

this

will

be

the

first

characters

of

B

-LSB-

Jobj

Chunkj

-RSB-

which

by

definition

is

also

-LRB-

j

-RRB-

Next

we

examine

the

block

of

characters

in

and

For

the

time-step

substring

this

corresponds

to

the

last

characters

of

A

-LSB-

Chunkj

-RSB-

which

assuming

Jobj

can

terminate

at

time-step

-LRB-

again

this

is

true

from

the

definition

of

dist

-RRB-

is

-LRB-

j

-RRB-

For

the

job

substring

this

block

corresponds

to

the

last

characters

of

B

-LSB-

Jobj

Timel

-LRB-

j

-RRB-

Chunkj

-RSB-

which

is

also

-LRB-

j

-RRB-

This

completes

the

proof

of

Lemma

Finally

we

must

guarantee

that

no

spurious

matches

can

occur

Definition

A

set

of

indices

and

j

and

the

substrings

they

induce

A

-LSB-

-RSB-

A

-LSB-

-RSB-

and

B

-LSB-

Jobj

-RSB-

are

valid

if

l

-LRB-

j

-RRB-

r

-LRB-

j

-RRB-

and

d

-LRB-

j

-RRB-

Note

that

and

are

not

considered

valid

if

either

is

taken

from

a

different

position

in

A

or

B

even

if

the

resulting

substrings

are

identical

Validity

is

a

property

of

the

indices

into

A

and

B.

Lemma

If

substrings

and

have

the

match

property

then

they

are

valid

Proof

We

must

show

that

substrings

of

A

and

B

will

match

only

if

they

represent

a

particular

job

and

a

feasible

time-slot

for

the

job

The

match

property

requires

that

the

string

-LRB-

j

-RRB-

appear

four

times

between

the

two

substrings

for

some

j

in

the

range

-LSB-

N

-RSB-

By

Lemma

we

can

conclude

that

any

erroneous

matches

could

come

about

only

as

a

result

of

-LRB-

j

-RRB-

's

placed

during

the

construction

of

A

and

B

and

not

from

random

patterns

appearing

in

the

strings

by

coincidence

Thus

and

must

begin

and

end

on

block

boundaries

within

A

and

B

respectively

Further

since

and

have

the

match

property

the

string

-LRB-

j

-RRB-

must

appear

as

the

-LRB-

-RRB-

th

block

of

characters

at

the

beginning

of

and

as

the

block

of

characters

in

the

last

characters

This

forces

substring

to

be

aligned

on

a

boundary

so

it

must

indeed

represent

a

legal

sequence

of

time-steps

In

this

case

the

details

of

the

construction

of

A

guarantee

that

job

j

can

be

scheduled

during

this

time-slot

and

meet

its

release

and

deadline

constraints

The

proof

for

substring

is

immediate

since

-LRB-

j

-RRB-

must

appear

exactly

twice

at

specific

locations

by

the

match

property

By

the

construction

of

B

this

can

only

occur

if

represents

job

j

This

completes

the

proof

of

Lemma

We

can

now

prove

the

primary

lemma

that

leads

directly

to

our

theorem

Lemma

The

uniprocessor

scheduling

problem

has

a

solution

if

and

only

if

the

corresponding

string

block

edit

problem

has

a

matching

that

is

a

zero-cost

disjoint

cover

Proof

If

the

scheduling

problem

is

solvable

then

by

the

definition

of

dist

this

will

yield

a

zero-cost

block

matching

That

the

matching

must

be

disjoint

is

clear

-LRB-

otherwise

two

jobs

will

have

been

scheduled

for

the

same

time-step

-RRB-

The

fact

that

it

is

a

cover

follows

from

our

earlier

assumption

that

the

total

duration

of

the

jobs

consumes

all

time-steps

up

to

the

latest

deadline

Assume

now

that

a

matching

exists

that

is

a

zero-cost

disjoint

cover

Since

the

cost

function

returns

only

or

by

Equation

the

cost

for

each

pair

of

blocks

must

be

Hence

by

Lemma

all

of

the

pairings

have

the

match

property

Applying

Lemma

this

means

they

correspond

to

valid

substrings

and

therefore

represent

an

assignment

of

jobs

to

time-slots

that

satisfies

the

constraints

of

the

scheduling

problem

By

the

construction

of

string

B

all

of

the

jobs

are

scheduled

This

completes

the

proof

of

the

lemma

With

Lemma

we

have

completed

the

proof

of

Theorem

showing

that

CD-CD

block

edit

distance

is

NP-complete

NP-completeness

of

Other

Models

In

this

section

we

show

that

essentially

the

same

reduction

works

for

the

other

hard

models

listed

in

Table

Theorem

The

CD-CD

CD-CD

and

CD-CD

block

edit

distance

problems

are

NP-complete

Proof

As

before

membership

in

NP

is

obvious

so

we

need

only

demonstrate

how

the

reduction

can

be

applied

to

these

models

Theorem

states

that

the

problem

is

hard

if

both

substring

families

must

be

disjoint

covers

The

same

proof

can

be

used

if

one

substring

family

need

not

be

a

cover

Recall

that

string

A

represents

time-steps

Clearly

a

block

matching

that

does

not

use

all

of

the

available

time

but

still

schedules

all

of

the

jobs

in

a

valid

way

is

just

as

difficult

to

achieve

This

shows

that

CD-CD

is

NP-complete

Likewise

the

problem

remains

difficult

if

one

substring

family

need

not

be

disjoint

For

this

variant

we

use

the

same

reduction

but

do

not

require

the

substring

family

chosen

from

B

to

be

disjoint

Thus

all

jobs

must

be

matched

-LRB-

i.e.

B

must

still

be

a

cover

-RRB-

to

distinct

units

of

time

-LRB-

i.e.

A

must

be

disjoint

-RRB-

but

jobs

can

also

be

re-used

to

help

cover

all

of

the

time-steps

Again

the

original

reduction

need

not

be

changed

This

shows

that

CD-CD

is

NP-complete

Combining

these

two

observations

if

the

time

string

need

not

be

covered

and

the

job

string

need

not

be

disjoint

the

resulting

schedule

will

still

be

valid

so

the

reduction

holds

This

shows

that

CD-CD

is

NP-complete

completing

the

proof

of

the

theorem

To

finish

the

last

two

hard

entries

in

Table

we

must

make

minor

changes

to

the

cost

function

Theorem

The

CD-CD

and

CD-CD

block

edit

distance

problems

are

NP-complete

Proof

For

the

CD-CD

model

we

can

adapt

the

reduction

fairly

simply

In

this

case

neither

string

must

be

disjoint

so

time-steps

and

jobs

can

be

re-used

more

than

once

We

change

the

distance

measure

so

that

a

valid

match

between

Jobi

and

a

particular

sequence

of

time-steps

has

cost

and

all

other

substring

pairings

have

cost

Then

if

a

schedule

exists

a

string

matching

can

be

constructed

with

total

distance

N

otherwise

no

such

match

can

be

found

The

proof

for

the

CD-CD

model

is

similar

If

neither

string

must

be

covered

the

problem

makes

sense

only

if

negative

distances

are

allowed

-LRB-

otherwise

the

best

match

would

always

return

empty

substring

families

for

both

strings

-RRB-

We

modify

the

distance

measure

so

that

a

valid

match

has

cost

Since

both

substring

families

must

be

disjoint

no

time-step

or

job

can

be

re-used

Hence

if

a

matching

with

distance

N

can

be

found

it

must

correspond

to

a

schedule

If

no

such

match

can

be

found

then

no

schedule

exists

This

completes

the

proof

of

the

theorem

Polynomial-Time

Algorithms

for

Block

Editing

We

now

present

a

family

of

polynomial-time

algorithms

to

compute

block

edit

distance

when

at

least

one

of

the

substring

families

is

unconstrained

Say

that

B

is

the

string

whose

substring

family

need

not

be

disjoint

or

a

cover

For

the

discussion

that

follows

it

will

be

convenient

to

assume

we

have

an

array

W

defined

as

below

for

i

j

m

W

-LRB-

i

j

-RRB-

min

k

l

fdist

-LRB-

ai

aj

bk

bl

-RRB-

g

-LRB-

-RRB-

That

is

W

-LRB-

i

j

-RRB-

gives

the

value

of

the

best

possible

match

between

ai

aj

and

any

substring

of

B

Since

portions

of

B

can

be

re-used

and

it

need

not

be

covered

the

information

in

W

is

sufficient

to

perform

the

needed

calculations

for

the

CD-CD

problem

we

will

define

similar

matrices

W

for

the

other

problems

in

their

respective

subsections

We

write

T

-LRB-

W

-RRB-

to

mean

the

time

required

to

compute

a

matrix

W

and

shall

discuss

later

how

W

can

be

computed

more

efficiently

than

the

naive

implementation

when

dist

is

standard

edit

distance

Consider

the

diagram

shown

in

Figure

Each

of

the

intervals

ai

aj

in

the

figure

represents

a

substring

of

A

and

is

labelled

with

W

-LRB-

i

j

-RRB-

Note

that

W

-LRB-

i

i

-RRB-

represents

the

best

match

between

the

single

character

ai

and

any

interval

of

B

As

before

a

substring

family

of

A

is

a

multiset

of

substrings

-LRB-

i.e.

intervals

-RRB-

If

the

intervals

do

not

overlap

the

family

is

disjoint

if

the

union

of

the

intervals

is

the

entire

line

the

family

is

a

cover

Enforcing

or

relaxing

these

constraints

-LRB-

all

relative

to

string

A

-RRB-

results

in

different

versions

of

the

block

edit

distance

problem

It

is

clear

from

Figure

that

W

induces

a

complete

interval

graph

a

well-studied

class

for

which

most

known

problems

have

efficient

solutions

-LSB-

-RSB-

We

now

present

a

series

of

dynamic

programming

recurrences

for

the

variants

of

block

edit

distance

that

admit

poly-time

solutions

based

on

choosing

intervals

in

a

way

that

satisfies

certain

constraints

tring

-LRB-

-RRB-

cost

of

best

match

between

and

any

substring

of

B

Figure

Possible

string

matches

viewed

as

intervals

We

define

M

-LRB-

i

-RRB-

to

be

the

best

block

match

between

ai

and

B

for

the

particular

model

we

are

interested

in

Once

we

have

computed

M

for

i

m

-LRB-

recall

that

jAj

m

-RRB-

our

final

answer

is

B

-LRB-

A

B

-RRB-

M

-LRB-

m

-RRB-

CD-CD

Block

Edit

Distance

We

begin

with

the

CD-CD

block

edit

distance

problem

in

which

the

substring

family

of

A

must

be

both

disjoint

and

a

cover

We

can

compute

M

using

the

following

recurrence

Algorithm

CD-CD

M

-LRB-

i

-RRB-

min

j

i

M

-LRB-

j

-RRB-

W

-LRB-

j

i

-RRB-

-LRB-

-RRB-

In

this

recurrence

M

-LRB-

i

-RRB-

allows

the

best

match

in

B

corresponding

to

aj

ai

to

be

added

to

the

optimal

solution

for

aj

for

all

possible

cuts

in

the

string

j

It

is

easy

to

show

this

satisfies

the

requirement

that

the

substring

family

for

A

be

a

disjoint

cover

By

dynamic

programming

the

value

of

M

-LRB-

i

-RRB-

can

be

computed

in

time

O

-LRB-

i

-RRB-

given

all

previous

M

-LRB-

j

i

-RRB-

Thus

the

total

time

to

compute

M

-LRB-

m

-RRB-

is

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

CD-CD

Block

Edit

Distance

We

now

address

the

problem

where

the

substring

family

must

be

disjoint

but

need

not

cover

A.

For

this

case

we

define

another

W

matrix

W

-LRB-

i

j

-RRB-

minfW

-LRB-

i

j

-RRB-

g

-LRB-

-RRB-

Used

in

place

of

W

in

Equation

W

allows

sections

of

A

to

be

skipped

whenever

it

is

advantageous

to

do

so

The

recurrence

is

Algorithm

CD-CD

M

-LRB-

i

-RRB-

min

j

i

M

-LRB-

j

-RRB-

W

-LRB-

j

i

-RRB-

-LRB-

-RRB-

The

time

bound

is

exactly

the

same

as

for

Equation

namely

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

CD-CD

Block

Edit

Distance

Next

we

consider

the

variant

in

which

the

substring

family

of

A

must

be

a

cover

but

need

not

be

disjoint

Recall

that

block

edit

distance

as

defined

in

Equation

does

not

allow

the

same

block

pairing

to

be

used

more

than

once

Here

we

see

why

this

should

be

so

otherwise

the

block

edit

distance

between

two

strings

A

and

B

could

be

-LRB-

if

a

negative-cost

pairing

exists

-RRB-

We

require

a

version

of

W

that

allows

the

substring

in

A

to

match

one

or

more

intervals

in

B

W

-LRB-

i

j

-RRB-

ae

W

-LRB-

i

j

-RRB-

if

W

-LRB-

i

j

-RRB-

P

k

l

minfdist

-LRB-

ai

aj

bk

bl

-RRB-

g

otherwise

-LRB-

-RRB-

Similarly

we

define

W

to

represent

the

cost

of

zero

or

more

matches

W

-LRB-

i

j

-RRB-

min?W

-LRB-

i

j

-RRB-

-LRB-

-RRB-

We

can

now

use

the

following

recurrence

to

allow

overlapping

intervals

Algorithm

CD-CD

M

-LRB-

i

-RRB-

min

j

i

min

-LSB-

j

i

-RSB-

M

-LRB-

k

-RRB-

W

-LRB-

j

i

-RRB-

X

-LSB-

j

i

-RSB-

W

-LRB-

k

i

-RRB-

-LRB-

-RRB-

Intuitively

the

recurrence

can

be

understood

as

follows

we

require

at

least

one

interval

in

B

to

cover

ai

yielding

the

W

term

We

can

also

include

other

intervals

ending

at

ai

but

only

if

they

lower

the

overall

cost

giving

us

the

W

term

Finally

we

combine

this

with

any

previous

best

matching

ending

somewhere

in

the

range

-LSB-

j

i

-RSB-

-LRB-

recall

that

the

substring

family

of

A

must

be

a

cover

-RRB-

which

explains

the

M

term

Note

that

this

can

still

be

computed

in

O

-LRB-

-RRB-

time

despite

the

additional

minimization

and

summation

If

the

outer

minimization

is

taken

in

reverse

order

-LRB-

i.e.

j

-LRB-

i

-RRB-

-RRB-

then

for

fixed

i

the

value

-LSB-

j

i

-RSB-

M

-LRB-

k

-RRB-

can

be

computed

from

-LSB-

j

i

-RSB-

M

-LRB-

k

-RRB-

in

constant

time

min

-LSB-

j

i

-RSB-

M

-LRB-

k

-RRB-

min

ae

M

-LRB-

j

-RRB-

min

-LSB-

j

i

-RSB-

M

-LRB-

k

-RRB-

oe

-LRB-

-RRB-

A

similar

trick

applies

in

the

case

of

the

summation

Hence

the

running

time

remains

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

CD-CD

Block

Edit

Distance

Finally

we

give

a

recurrence

to

solve

the

problem

when

neither

substring

family

is

constrained

We

can

extend

the

ideas

of

the

previous

subsection

to

solve

this

problem

Algorithm

CD-CD

M

-LRB-

i

-RRB-

min

j

i

M

-LRB-

i

-RRB-

W

-LRB-

j

i

-RRB-

X

-LSB-

j

i

-RSB-

W

-LRB-

k

i

-RRB-

-LRB-

-RRB-

The

M

-LRB-

i

-RRB-

term

incorporates

the

best

shorter

matching

-LRB-

one

which

does

not

include

ai

-RRB-

and

the

use

of

W

frees

the

substring

family

of

A

from

having

to

be

a

cover

Since

any

new

interval

added

to

the

matching

at

step

i

must

overlap

ai

and

no

interval

in

the

best

so

far

may

contain

ai

we

maintain

the

invariant

that

no

block

pairing

is

used

more

than

once

Again

this

recurrence

can

be

evaluated

in

time

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

Time

Complexity

As

we

indicated

each

of

the

recurrences

requires

O

-LRB-

-RRB-

time

where

m

jAj

However

they

all

depend

on

having

a

matrix

W

so

the

full

time

bound

is

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

If

we

build

W

according

to

its

definition

-LRB-

i.e.

Equation

-RRB-

for

example

we

must

fill

in

O

-LRB-

-RRB-

entries

by

comparing

O

-LRB-

-RRB-

values

each

of

which

can

take

time

O

-LRB-

mn

-RRB-

to

compute

when

dist

is

standard

string

edit

distance

Thus

naively

T

-LRB-

W

-RRB-

O

-LRB-

-RRB-

There

is

however

a

well-known

modification

of

the

basic

dynamic

programming

algorithm

that

allows

the

best

match

in

B

for

a

fixed

substring

in

A

to

be

found

in

time

O

-LRB-

mn

-RRB-

This

saves

a

factor

of

O

-LRB-

-RRB-

over

the

naive

approach

Furthermore

a

property

of

this

computation

is

that

the

table

generated

for

matching

ai

an

to

B

contains

information

about

the

best

substring

matches

for

ai

ak

as

well

for

i

k

n.

Hence

only

O

-LRB-

m

-RRB-

such

tables

need

be

built

to

compute

W

saving

another

O

-LRB-

m

-RRB-

Thus

T

-LRB-

W

-RRB-

O

-LRB-

-RRB-

All

of

the

other

versions

of

W

can

be

computed

from

W

and

the

tables

used

to

build

it

in

less

time

than

this

Hence

in

general

T

-LRB-

W

-RRB-

O

-LRB-

-RRB-

Since

this

dominates

the

time

needed

to

evaluate

the

recurrences

presented

earlier

the

full

time

complexity

in

all

cases

is

O

-LRB-

-RRB-

Conclusions

In

this

paper

we

have

examined

the

concept

of

string

block

edit

distance

where

two

strings

A

and

B

are

compared

by

extracting

collections

of

substrings

and

placing

them

into

correspondence

This

model

seems

to

account

for

certain

phenomena

encountered

in

important

real-world

applications

including

pen

computing

and

molecular

biology

As

we

demonstrated

the

basic

problem

admits

a

family

of

variations

depending

on

whether

the

strings

must

be

matched

in

their

entireties

and

whether

overlap

is

permitted

The

problem

is

NP

complete

if

both

substring

families

are

constrained

in

any

way

and

solvable

in

time

O

-LRB-

-RRB-

T

-LRB-

W

-RRB-

otherwise

We

gave

an

algorithm

for

computing

W

in

O

-LRB-

-RRB-

time

-LCB-

it

would

be

interesting

to

know

whether

this

result

can

be

improved

Another

open

question

concerns

the

existence

of

approximation

algorithms

for

the

more

difficult

versions

of

the

problem

-LRB-

especially

if

such

algorithms

also

overcome

the

bottleneck

of

having

to

compute

W

exactly

-RRB-

While

the

recurrences

presented

in

Section

for

the

poly-time

cases

are

not

guaranteed

to

return

a

disjoint

cover

for

string

B

this

does

not

exclude

the

possibility

under

some

scenarios

It

may

be

instructive

to

attempt

to

characterize

just

when

these

additional

constraints

can

be

satisfied

Acknowledgement

The

genetic

sequence

dot

matrix

plot

-LRB-

Figure

-RRB-

was

generated

using

Dotty

Plotter

a

program

written

by

Don

Gilbert

References

-LSB-

AGM

-RSB-

S.

F.

Altschul

W.

Gish

W.

Miller

E.

W.

Myers

and

D.

J.

Lipman

Basic

local

alignment

search

tool

Journal

of

Molecular

Biology

-LCB-

-LSB-

-RSB-

W.

I.

Chang

and

E.

L.

Lawler

Approximate

string

matching

in

sublinear

expected

time

In

Proceedings

of

the

Symposium

on

Foundations

of

Computer

Science

pages

-LCB-

-LSB-

-RSB-

M.

Gribskov

and

J.

Devereux

Sequence

Analysis

Primer

Stockton

Press

-LSB-

-RSB-

Z.

Galil

and

R.

Giancarlo

Data

structures

and

algorithms

for

approximate

string

matching

Journal

of

Complexity

-LCB-

-LSB-

-RSB-

M.

R.

Garey

and

D.

S.

Johnson

A

Guide

to

the

Theory

of

NP-Completeness

W.H.

Freeman

and

Company

-LSB-

-RSB-

M.

C.

Golumbic

Algorithmic

Graph

Theory

and

Perfect

Graphs

Academic

Press

New

York

-LSB-

-RSB-

Z.

Galil

and

K.

Park

An

improved

algorithm

for

approximate

string

matching

SIAM

Journal

on

Computing

-LRB-

-RRB-

-LCB-

-LSB-

-RSB-

R.

J.

Lipton

and

D.

P.

Lopresti

A

systolic

array

for

rapid

string

comparison

In

Henry

Fuchs

editor

Proceedings

of

the

Chapel

Hill

Conference

on

Very

Large

Scale

Integration

pages

-LCB-

Computer

Science

Press

-LSB-

-RSB-

D.

Lopresti

and

A.

Tomkins

On

the

searchability

of

electronic

ink

Technical

Report

MITL

June

To

be

presented

at

the

Fourth

International

Workshop

on

Frontiers

of

Handwriting

Recognition

Taipei

Taiwan

December

-LSB-

-RSB-

G.

M.

Landau

and

U.

Vishkin

Fast

parallel

and

serial

approximate

string

matching

Journal

of

Algorithms

-LCB-

-LSB-

-RSB-

F.

S.

Roberts

Graph

Theory

and

Its

Applications

to

Problems

of

Society

SIAM

Philadelphia

PA

-LSB-

-RSB-

D.

Sankoff

and

J.

B.

Kruskal

editors

Time

Warps

String

Edits

and

Macromolecules

The

Theory

and

Practice

of

Sequence

Comparison

Addison-Wesley

Reading

MA

-LSB-

-RSB-

E.

Ukkonen

Algorithms

for

approximate

string

matching

Information

and

Control

-LCB-

-LSB-

-RSB-

R.

A.

Wagner

On

the

complexity

of

the

extended

string-to-string

correction

problem

In

Proceedings

of

the

ACM

Symposium

on

Theory

of

Computing

Association

for

Computing

Machinery

-LSB-

-RSB-

R.

A.

Wagner

and

M.

J.

Fischer

The

string-to-string

correction

problem

Journal

of

the

Association

for

Computing

Machinery

-LCB-

O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O

approximate ink matching
approximate string matching
block edit distance
dynamic programming
sequence comparison