Tuesday, August 13, 2013

Let's start with a list:
'(a b c d e f g h i j)

We'll add some elements:
'(a b c d e f g h i j k l m n o)

Delete some:
'(a b c d e i j k l m n o)

Add some more:
'(x y z a b c d e i j k l m n o)

Maybe delete one:
'(x y z b c d e i j k l m n o)

We want to compare the original sequence with the end sequence and
summarize the difference with a set of "indels", which specify the
indexes at where elements were inserted or deleted:

(diff '(a b c d e f g h i j) '(x y z b c d e i j k l m n o))

    :LEFT-SUBSEQ-START 0         ;; 'a'
    :RIGHT-SUBSEQ-START 0        ;; 'x y z'
    :LEFT-SUBSEQ-START 5         ;; 'f g h'
    :RIGHT-SUBSEQ-START 7        ;; nothing
    :LEFT-SUBSEQ-START 10        ;; nothing
    :RIGHT-SUBSEQ-START 9        ;; 'k l m n o'
Exercise 6 (hard): Implement this.

For an extreme challenge, implement this in a way that is not hopelessly inefficient.


Jason said...

I suppose it would be hard if you tried to come up with it yourself:


Anonymous said...

@Jason: isn't Edit distance a better starting point for this task?

pjb said...

What about a solution in O(length(a)+length(b))?

(defstruct indel left-subseq-start left-subseq-limit right-subseq-start right-subseq-limit)
(defun diff (a b)
(make-indel :left-subseq-start 0 :left-subseq-limit (length a)
:right-subseq-start 0 :right-subseq-limit (length b))))

The problem is ill-specified.