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...
Orders of growth in Scheme
Started by infimum, Nov 15 2009 03:47 PM
3 replies to this topic
#1
Posted 15 November 2009 - 03:47 PM
|
|
|
#2
Posted 16 November 2009 - 08:54 AM
You could rewrite the function as a recursive procedural function (in C, for example), and compute the complexity there.
#3
Posted 17 November 2009 - 10:01 AM
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.
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
Posted 17 November 2009 - 11:07 AM
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)?
Have you traced through a few calls, such as (almony 10 20) and (almony 20 20) and (almony 100 100)?


Sign In
Create Account

Back to top









