How Can I Improve This Algorithm (LCS)

Posted by superguay on Stack Overflow See other posts from Stack Overflow or by superguay
Published on 2010-04-08T05:38:37Z Indexed on 2010/04/08 5:43 UTC
Read the original article Hit count: 299

Filed under:

(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list) (except-last-pair (cdr list))) '())) (define (car-last-pair list) (if (pair? (cdr list)) (car-last-pair (cdr list)) (car list))) (if (or (null? lst1) (null? lst2)) null (if (= (car-last-pair lst1) (car-last-pair lst2)) (append (lcs (except-last-pair lst1) (except-last-pair lst2)) (cons (car-last-pair lst1) '())) **(if (> (length (lcs lst1 (except-last-pair lst2))) (length (lcs lst2 (except-last-pair lst1)))) (lcs lst1 (except-last-pair lst2)) (lcs lst2 (except-last-pair lst1))))))

I dont want it to run over and over..

Regards, Superguay

© Stack Overflow or respective owner

Related posts about Scheme