Jump to content

Complexity

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
infimum

infimum

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,
I didn't get the all concept of Complexity

For eaxample, in those codes i wrote:


(define (prefix k lst)
(cond ( (= k 0) '())
( (null? lst) '())
(else (cons (car lst) (prefix (- k 1) (cdr lst))))))

(define (runs k lst)
(let ((p (prefix k lst)))
(if (> k (length p)) '()
(cons p (runs k (cdr lst))))))


-----------

(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))

(define (accumulate-runs k op init lst)
(map (lambda (x) (accumulate op init x))
(runs k lst)))


---------------




How can i determine the complexity in both of those codes?
Thanks for any kind of help:)

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have to look at how many times the function will call itself, based on the number of elements in the list.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog