My bad but it can be made recursive :)
On Aug 9, 8:17 pm, Dave wrote:
> @Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative.
>
> Dave
>
> On Aug 9, 9:56 am, Ankuj Gupta wrote:
>
>
>
>
>
>
>
> > we can do it in logn by using binary search approach found
> > n is the number w
@Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative.
Dave
On Aug 9, 9:56 am, Ankuj Gupta wrote:
> we can do it in logn by using binary search approach found
> n is the number whose square root has to be
>
> if(n==1)
> return 1;
> if(n==0)
>
we can do it in logn by using binary search approach found
n is the number whose square root has to be
if(n==1)
return 1;
if(n==0)
return 0;
int low=0,high=n/2,mid,temp;
while(1)
{
mid = (low+high)/2;
@dave:Ma mistake should have been nearest square root :)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@goo
Find_Nearest(i , prev , n)
{
int sqr=n*n;
if(sqr > i)
{
if((sqr-i)>(i-prev))
return sqr ;
else
return prev;
}
Find_Nearest(i,sqr,n+1);
}
initial call value : Find_Nearest(27, 0, 1);
prev= previous square value.
Thanks
Venkat
http://cloud-computation.blogspot.com/
On Aug 7
@Nikhil: Your example shows a strange use of the phrase "nearest
square". It would seem that the nearest square to 27 would be 25, not
sqrt(25). But anyway
If n = 0 return 0
Else
recursively find k = the nearest square to n/4
return 2*k-1, 2*k, or 2*k+1, whichever one squared is closer to
why recursive?
On Aug 7, 7:41 am, Nikhil Veliath wrote:
> write a recursive code to print the nearest square of a number
>
> eg if no is 27
>
> the nearest square is 5
>
> it should also take care of large nos...
--
You received this message because you are subscribed to the Google Grou
Doesn't the solution without queue look very inefficient?
The tree is being traversed till level n-1 for every Nth level
printing.
Thus if the tree has height h, then h^2 tree traversals are there.
Nodes being accessed at level l (assuming fully balanced tree): 1 + 2
+ 4 + 2^l = 2^(l+1) - 1 which
yes. You should be able to convert any recursive function/method to a
non-recursive one by just simulating what the language does to do the
recursion.
This usually involves using stack (recursion stack) to store function
local variables before doing another call.
Haven't looked at this closely but
understood thanks for ur concern
On 6/7/08, Ashesh <[EMAIL PROTECTED]> wrote:
>
>
> Recursion is so cool. If you're willing to practice, I'd recommend you
> to try SML.
>
> On Jun 6, 10:40 pm, "zee 99" <[EMAIL PROTECTED]> wrote:
> > hi
> >
> > learnt that a tail recursive algorithm can be convert
Recursion is so cool. If you're willing to practice, I'd recommend you
to try SML.
On Jun 6, 10:40 pm, "zee 99" <[EMAIL PROTECTED]> wrote:
> hi
>
> learnt that a tail recursive algorithm can be converted to a non recursive
> one by merely using a while and a goto
>
> is it true for all class of r
On Jun 6, 1:40 pm, "zee 99" <[EMAIL PROTECTED]> wrote:
> hi
>
> learnt that a tail recursive algorithm can be converted to a non recursive
> one by merely using a while and a goto
>
> is it true for all class of recursive algorithms or just the tail recursive
> ones ...
All. In fact there are s
Thanks for the suggestions Adak but I've since managed to achieve what
I was looking for. I didn't give more indepth information as I was
looking to solve the remainder myself.
Much appreciated,
Cosmo
--~--~-~--~~~---~--~~
You received this message because you
Hi again, Cosmo
I was re-reading your original post, and I'm a bit stuck on the
ambiguities of English contained therein.
[BEGIN QUOTE]
I'm trying write a recursive divide and conquer function that will keep
splitting 2 arrays of int[] in half until a single element exists in
each array. A com
OK, you're getting let's say, to the last element in the array. Way
deep.
you test it with if (a.length == 1) and yep, we're at the last element,
so you set the change to "true".
Now it's time to EXIT the program. If I understand your code, it's ONLY
designed to recurse DOWN, so
if you go back U
Thanks for the prompt reply Adak. I've looked at some of the quicksort
examples and I know they use recursion and divide & conquer for
implementation but I'm having difficulty extracting the pieces relevent
to me. Here is what I have so far, it currently generates a stack
overflow error so it's n
Let the recursive call stack keep track of that, just take a look at
demo's of Quicksort, and you'll see what I'm talking about. You'll
probably want a left and right index or pointer, (or call them low and
high, whatever you like).
Adak
--~--~-~--~~~---~--~~
You
17 matches
Mail list logo