最长的后缀球拍

时间:2018-02-26 23:07:56

标签: list racket complexity-theory suffix

我必须在两个不同大小的列表的O(n ^ 2)时间复杂度最长的后缀下进行。我禁止在列表或辅助前缀函数上使用reverse,我需要得到结果同样的订单。

(define (common-suffix L1 L2)
  (if (= (length L1) (length L2))      
     (if (= 0  (min (length L1) (length L2)))
         '()         
         (if (equal? (car L1) (car L2))
             (append  (cons (car L1) null) (common-suffix (cdr L1) (cdr L2)))
             (append (common-suffix (cdr L1) (cdr L2)) null)))
     (if (< (length L1) (length L2))
         (common-suffix L1  (cdr L2))
         (common-suffix (cdr L1) L2))))

这是我的实现,我只需要知道它是否在O(N ^ 2)时间复杂度下。谢谢:))

0 个答案:

没有答案
相关问题