-2
def unknownsort(A[],x,y):
 if x ==y+1:
   if A[x]>A[y]:
     switch A[x] and A[y]
 elif y > x+1:
    z = (y-x+1)/3
    unkownsort(A[],x,y-z)
    unkownsort(A[],x+z,y)
    unkownsort(A[],x,y-z)

Is there a name for this equation? For T(n) what is have is T(n)= 3T(n) + Theta(n) is this right? I was planning to use Master's Theorem but im not sure exactly if this is right. Also what do you call this process of finding T(n)

I was thinking unkownsort is called three times so, T(n) = 3T(n), but it has a base case depending on the size of the input so T(n) = 3T(n)+theta(n). Now I was wondering if this equation would be wrong because of "z" since z manipulates the size of my array.

Somehow ive come up with this: T(n) = 3T(n/3)+1. Is this correct now?

user3175173
  • 103
  • 2
  • 13
  • Yes it is homework. However, the homework question asks what the function does. It is comparable to insertion sort. When first called it keeps on recursing as long as Y is the max length of an array and x is 0. Is asking homework related questions not allowed even though it would be cited? – user3175173 Feb 05 '14 at 00:29
  • 3
    @MitchWheat You'd need a better close reason that that - homework isn't off topic. – Bernhard Barker Feb 05 '14 at 00:40
  • IMO, homework WITHOUT attempt IS off-topic. Doing it for someone is is the long term unhelpful, and might even be considered cheating. – Mitch Wheat Feb 05 '14 at 01:23
  • Isnt what I have shown above work? Or does it have to be more formal? – user3175173 Feb 05 '14 at 01:25
  • You have updated your question since the original post. – Mitch Wheat Feb 05 '14 at 01:38
  • The updated equation you edited into your question is correct (but it's preferred to leave that out of the question, since it somewhat invalidates the question, and just keep it to the comments and answers). – Bernhard Barker Feb 05 '14 at 02:02

1 Answers1

0

Ok, homework, let's stick to hints then.

In 3T(n), the 3 is correct since there are 3 recursive calls, but the T(n) is not - the n should be (in the form n/c) the size which the next recursive calls work with, currently you're saying the size is the same.

The Theta(n) is incorrect - apart from the recursive calls, how much work is done in the function? Does the amount of work depend on x and y (you should probably assume that any arithmetic operation always takes a constant amount of time, although this isn't strictly true)?

Did you give us the whole function? If so, I'm not convinced that that algorithm of yours does anything particularly useful (while it looks like it is sorting, I'm not convinced it is, but I could be wrong), and thus probably doesn't have a name.

The T(n) equation is called a recurrence relation, so the process of finding it would simply be called the process of finding the recurrence relation (I'm not aware of a single term to denote this).

(The updated equation you edited into your question is correct)

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138