Jump to content

Orders of growth in Scheme

- - - - -

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

#1
infimum

infimum

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

How can i determine the orders of growth of the time and space complexities?

For example in this code:

(define almony
(lambda (n m)
(if (< n 1)
0
(+ m (almony m (/ n 2))))))

Thanks...

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You could rewrite the function as a recursive procedural function (in C, for example), and compute the complexity there.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
infimum

infimum

    Newbie

  • Members
  • Pip
  • 3 posts
I'm sorry, i don't understand. What do you mean " rewrite as a recursive procedural function"? (and this is my first programming language, so i dont no nothing about C).

However, I think that the space complexity is O(m), because there is a pending operation, am i right? And what about the time complexity?

Thanks again for your time.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
From what I can tell (roughly), space complexity will be less than O(m), and time and space complexity will be the same. Also, the values of both m and n are relevant.

Have you traced through a few calls, such as (almony 10 20) and (almony 20 20) and (almony 100 100)?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog