|
-
Mar 22nd, 2005, 01:44 AM
#1
Thread Starter
Stuck in the 80s
Time Complexity
How do I find out the time complexity for:
T(n) = 1 if n <= 4
1 + T(n-4) for n > 4
n is even
Any help is appreciated.
-
Mar 22nd, 2005, 06:11 AM
#2
Re: Time Complexity
 Originally Posted by The Hobo
How do I find out the time complexity for:
T(n) = 1 if n <= 4
1 + T(n-4) for n > 4
n is even
Any help is appreciated.
Though I've studied math I'm not familiar with the term "time complexity", maybe I know the Spanish version under quite different words, but I'm interested...
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Mar 22nd, 2005, 01:32 PM
#3
Addicted Member
Circa 1995
Engineer - I think we should put our website address on our paper catalogs.
Vice President - Don't get too excited about this internet thing.
I am sorry, but the Oracle was mistaken. You cannot help us.
-Matrix video game
I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. ... and it probably never will support anything other than AT-harddisks, as that's all I have :-(.
-Linus
Question. Do you know that the character "?" means I'm asking a question? Question. Do you know that spoken inflection also provides the same cue? So please don't say, "Question" before you ask your question. Believe me I'll know.
That said, I would have said this first if it had to precede what I'm telling you now. Having said that, what I'm telling you now is the same thing I just said about the annoying phrases "That said" and "Having said that".
Are you threatening me, Master Jedi?
-Chancellor Palpatine
-
Mar 22nd, 2005, 04:27 PM
#4
Re: Time Complexity
You reduce n by a fixed amount until you reach a value <4, so that is O(n) steps. Or do you mean that T(n) is the complexity and you want to reduce it to a big oh notation?
-
Apr 2nd, 2005, 01:58 PM
#5
Thread Starter
Stuck in the 80s
Re: Time Complexity
I know it goes something like:
Code:
T(N) = 1 + T(N - 4)
T(N - 4) = 1 + T(N - 8) T(N) = 1 + (1 + T(N - 8))
T(N - 8) = 1 + T(N - 12) T(N) = 1 + (1 + (1 + T(N - 12)))
But I don't know why, or what my result is supposed to look like...and I can't find anything on the web to help. Any have any ideas?
-
Apr 2nd, 2005, 03:10 PM
#6
Re: Time Complexity
You should look at it the other way around:
T(n) = 1 for 0<n<=4
T(n) = 2 for 4<n<=8
T(n) = 3 for 8<n<=12
You can now substitute T(i):
a = T(n) = 1 for 4*a-4<n<=4*a
b = T(n) = 2 for 4*b-4<n<=4*b
c = T(n) = 3 for 4*c-4<n<=4*c
So, given T(n) you can caluculate the range of minn<n<=maxn:
minn(T(n)) = 4*T(n)-4
maxn(T(n)) = 4*T(n)
Now to reverse this function you need to map a range to a single number, this can be done with the ceil function (roundig up) and a division:
T(n) = ceil(n/4)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|