Which Algorithm is Faster?
- From: "eKo1" <berndlosert@xxxxxxxxxxxx>
- Date: 26 Dec 2006 09:43:04 -0800
I have a problem that asks:
We have a problem that can be solved by a direct (nonrecursive)
algorithm that operates in n^2 time. We also have a recursive algorithm
for this problem that takes n lg n operations to divide the input into
two equal pieces and lg n operations to combine the two solutions
together. Show whether the direct or recursive version is more
efficient.
I think I can safely assume that n is the size of the input. Let a(n)
be the number of operations required by the recursive algorithm.
a(1) = 0 and for n > 1,
a(n) = (n+1)lg n + 2 lg (n/2) if n is even, and
a(n) = (n+1)lg n + lg [(n+1)/2] + lg [(n-1)/2] if n is odd.
which seems to be O(n lg n) (at least, for n = 2^k, k > 0), so the
recursive algorithm is faster right? Or perhaps I'm overcomplicating.
Maybe the author of the problem meant to say that the recursive
algorithm takes (n + 1)lg n operations. What do you think?
.
- Follow-Ups:
- Re: Which Algorithm is Faster?
- From: eKo1
- Re: Which Algorithm is Faster?
- From: Proginoskes
- Re: Which Algorithm is Faster?
- Prev by Date: Re: Analog = digital?
- Next by Date: Re: I need help with some algorithm
- Previous by thread: I need help with some algorithm
- Next by thread: Re: Which Algorithm is Faster?
- Index(es):
Relevant Pages
|