Re: [algogeeks] Re: MS Q

2012-01-15 Thread Umer Farooq
Here is my solution. Please have a look at it. Any kind of positive criticism will be highly appreciated. bool isConnected(int **space, int x, int y) { if (x == 0 y == 0) { return false; } if (y 0) { if (space[x][y-1] == 1) return true; } if (x 0) { if (space[x-1][y] == 1) return true; } if (x

Re: [algogeeks] Binary Index Tree

2012-01-15 Thread saurabh singh
search problem japan Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sun, Jan 15, 2012 at 4:23 AM, Mad Coder imamadco...@gmail.com wrote: Hi all, I was going through Binary Index Tree (BIT) tutorial through topcoder , although the concept is clear to

Re: [algogeeks] Binary Index Tree

2012-01-15 Thread Amol Sharma
also try http://www.spoj.pl/problems/DQUERY/ -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/

[algogeeks] Time Complexity Ques

2012-01-15 Thread Ankur Garg
Hello I was going through this link http://www.geeksforgeeks.org/archives/3187 Wonder what is the time complexity for this..?Can anyone explain Regards Ankur -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] Re: Time Complexity Ques

2012-01-15 Thread Gene
To find sqrt(a), this is equivalent to Newton's Method with f(x)=x^2 - a. Newton is: x_{i+1} = x_i + f'(x_i) / f'(x_i). So you have x_{i+1} = x_i + (x_i^2 - a) / (2 x_i) = (x + a/x) / 2, which is just what the Babylonian method says to do. Newton's method roughly doubles the number of

[algogeeks] rectangle of max sum MS Q

2012-01-15 Thread Ashish Goel
given a m*n matrix, find the subset rectangle with max sum (any other rectangle taken would have lesser sum) Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: Sorting for large data

2012-01-15 Thread Gene
If the interviewer actually said 10^80 data items, he/she was expecting you to say it's a silly question. Do you realize how much 10^80 is? A terabyte is 10^12 bytes. So we are talking about 10^68 1 Tb disk drives just to hold 1 byte records. The number of grains of sand that would make up the

[algogeeks] Re: hextoint program MS Q

2012-01-15 Thread Gene
Which language? On Jan 15, 8:23 pm, Ashish Goel ashg...@gmail.com wrote: Hi, given a string in hex, convert it into int. Write test cases for the same. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you

Re: [algogeeks] Re: hextoint program MS Q

2012-01-15 Thread Ashish Goel
i would assume C or C++ Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Jan 16, 2012 at 7:40 AM, Gene gene.ress...@gmail.com wrote: Which language? On Jan 15, 8:23 pm, Ashish Goel ashg...@gmail.com wrote: Hi, given a string in hex,

Re: [algogeeks] Re: hextoint program MS Q

2012-01-15 Thread Ashish Goel
a 0x should come as a negative number Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Jan 16, 2012 at 8:19 AM, Gene gene.ress...@gmail.com wrote: Okay. Normally you want to use a library that someone else has tested. So:

[algogeeks] Re: hextoint program MS Q

2012-01-15 Thread Gene
And it ought to. Did you try it? On Jan 15, 9:55 pm, Ashish Goel ashg...@gmail.com wrote: a 0x should come as a negative number Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Jan 16, 2012 at 8:19 AM, Gene

[algogeeks] Re: hextoint program MS Q

2012-01-15 Thread Gene
More detail: For nearly all compilers, int is 32 bits. So I think you mean should return a negative number. I just ran the code, and it does this as expected. To stop parsing prior to overflow, say something like int hex_to_int(char *s) { int i = 0; while (*s) { if ('0' = *s

[algogeeks] Re: Time Complexity Ques

2012-01-15 Thread Dave
@Gene: Actually, Newton's Method for sqrt(a), where a 0, also sometimes called Heron's Method, converges for every initial guess x_0 0. This is not true generally for Newton's Method, but it is true for Newton's Method applied to f(x) = x^2 - a. Dave On Jan 15, 5:39 pm, Gene

[algogeeks] Re: Time Complexity Ques

2012-01-15 Thread Gene
To find sqrt(a), this is equivalent to Newton's Method with f(x)=x^2 - a. Newton is: x_{i+1} = x_i + f'(x_i) / f'(x_i). So you have x_{i+1} = x_i + (x_i^2 - a) / (2 x_i) = (x + a/x) / 2, which is just what the Babylonian method says to do. Newton's method roughly doubles the number

[algogeeks] Re: Time Complexity Ques

2012-01-15 Thread Gene
I'm sorry for not being specific. I meant it doesn't converge for all roots, e.g. cube root. On Jan 15, 10:18 pm, Dave dave_and_da...@juno.com wrote: @Gene: Actually, Newton's Method for sqrt(a), where a 0, also sometimes called Heron's Method, converges for every initial guess x_0 0. This