Results 1 to 6 of 6

Thread: Time Complexity

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Time Complexity

    Quote 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)

  3. #3
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Re: Time Complexity

    I suppose he means this http://www.csc.liv.ac.uk/~ped/teacha...r/complex.html for optimizing his coding.
    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

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    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?

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    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
  •  



Click Here to Expand Forum to Full Width