What is the running time? is it O(n)?
I think the running time of this solution is O(n). But, I'm 开发者_StackOverflownot sure. Can anyone help me figure it out?
(define (poly x coeff)
(polyaux x (reverse coeff) 0))
;; the aux function
(define (polyaux x coeff acc)
(if (null? coeff)
acc
(polyaux x (cdr coeff) (+ (* acc x) (car coeff)))))
thanks
If the n in O(n) refers to the length of coeff, then it has to be. At every step, coeff gets one item shorter until it is gone.
精彩评论