Re: [algogeeks] Multiplication of two numbers

2010-09-20 Thread Baljeet Kumar
If a and b are the numbers then dig = log10(a) + log10(b); if dig has some fractional part then number of digits is dig + 1 else dig. On Mon, Sep 20, 2010 at 11:19 AM, sumant hegde sumant@gmail.com wrote: Adding to the partial solution, if x, y are first digits, and x*y + x + y 10, the

Re: [algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread LG JAYARAM .
Just tell me wats the answer for thissequence 1, 3 ,5, -1, -2 ,0, 7 . On 9/20/10, Dave dave_and_da...@juno.com wrote: Krunal: If the array contains only negative numbers, shouldn't the subsequence with the largest sum be the empty subsequence? Dave On Sep 19, 5:45 am, Krunal Modi

Re: [algogeeks] recursion to remove duplicate characters in a string

2010-09-20 Thread LG JAYARAM .
Yes ur correct...it will require some extra spacebst can be represented in the array form ritelet me think in tht logic. On 9/19/10, Umer Farooq the.um...@gmail.com wrote: creating a bst would require extra space. You can do this with an array of char dude. On Sun, Sep 19, 2010 at

Re: [algogeeks] Multiplication of two numbers

2010-09-20 Thread rahul patil
On Mon, Sep 20, 2010 at 1:15 PM, Baljeet Kumar baljeetk...@gmail.comwrote: If a and b are the numbers then dig = log10(a) + log10(b); if dig has some fractional part then number of digits is dig + 1 else dig. found this correct onw On Mon, Sep 20, 2010 at 11:19 AM, sumant hegde

[algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread Krunal Modi
@Dave : We have to find any element. So whichever is larger has to be the answer.Hence, -1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send

[algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread Krunal Modi
@LG JAYARAM: It is 7. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] Multiplication of two numbers

2010-09-20 Thread Baljeet Kumar
@Naveen: Yes you are right, the answer is not fully correct. ans = integral part of ((log10(a)+log10(b) +1) {floor not ceiling}. On Mon, Sep 20, 2010 at 4:11 PM, Naveen Agrawal nav.coo...@gmail.comwrote: @Baljeet I think your Answer is not fully correct It should be :

Re: [algogeeks] Re: print largest continue subsequent in int array

2010-09-20 Thread LG JAYARAM .
@Krunal: can u explain hwz 7 On Mon, Sep 20, 2010 at 6:02 PM, Krunal Modi krunalam...@gmail.com wrote: @LG JAYARAM: It is 7. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Multiplication of two numbers

2010-09-20 Thread Dave
@Rahul. No. Considering your example 33*30, x*y + x + y = 3*3 + 3 + 3 = 15 is not 10, so, as specified by Sumant, u will need a complex logic to solve. Dave On Sep 20, 5:31 am, rahul patil rahul.deshmukhpa...@gmail.com wrote: On Mon, Sep 20, 2010 at 1:15 PM, Baljeet Kumar

[algogeeks] Re: number of inversion pairs

2010-09-20 Thread vikas kumar
use a bst and insert in it reverse of array. use a count in bst node and incr count at each right child insertion On Sep 14, 11:00 am, Shiv ... shivsinha2...@gmail.com wrote: A pseudo code-   int n; //= number of inputs.   cin*a; // the inputs.   int ** invArr;   *inVArr[n-1] =

[algogeeks] point lies inside or outside of triangle..

2010-09-20 Thread umesh kewat
Initially we have given three point A , B, C in plane represent three nodes of triangle, now given another point Z which lies in same plane, find out whether that point lies on/inside the triangle or outside of triangletry to get in min time and space complexity -- Thanks Regards Umesh

[algogeeks] Point lies inside or outside of triangle?

2010-09-20 Thread umesh
Initially we have given three point A , B, C in plane represent three nodes of triangle, now given another point Z which lies in same plane, find out whether that point lies on/inside the triangle or outside of triangletry to get in minimum time and space complexity -- Thanks Regards

Re: [algogeeks] Point lies inside or outside of triangle?

2010-09-20 Thread Praveen Baskar
here is the hint we can easily solve this draw a triangle draw a point is inside the triangle connect the three vertices of the triangle with this point you will get three small triangle if ( area(big triangle)== sum of area of small triangles) then the point is inside the triangle else it is

Re: [algogeeks] Point lies inside or outside of triangle?

2010-09-20 Thread saurabh singh
One way would be : Create equation of three sides of the triangle Now check for this point if it lies on left/right of the line (do it for each of the lines)... On Mon, Sep 20, 2010 at 9:06 PM, Praveen Baskar praveen200...@gmail.comwrote: here is the hint we can easily solve this draw a

[algogeeks] Re: Multiplication of two numbers

2010-09-20 Thread abhiram_n
Wonder if this works: x = A / 10^(a-1) // take it as a decimal value itself y = B / 10^(b-1) // take it as a decimal value itself if x * y = 10.0 return (a+b) else return (a+b-1) One advantage of the above method is that it can be done mentally. On Sep 20, 10:47 am, Dave

[algogeeks] Arrays

2010-09-20 Thread Anand
Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers and B contains n+1 integers of which n are same as in array B but in different order and one extra element x. Write an optimized algorithm to find the value of element x. Use only one pass of both arrays A and B. -- You

[algogeeks] Re: point lies inside or outside of triangle..

2010-09-20 Thread Gene
This is okay, but does more math than necessary. Here's another approach: // Return 0 if p is left of a-b, 2 if right of a-b, and 1 if on a- b. int side(PT *p, PT *a, PT *b) { float d = (p.x-a.x) * (b.y-a.y) - (p.y-a.y) * (b.x-a.x); return d 0 ? 0 : d 0 ? 2 : 1; } // This table treats

Re: [algogeeks] Arrays

2010-09-20 Thread vishal raja
add up all the elements in array A say sumA and array B say sumB ,substract the sumA from sumB... You'll get the element. On Tue, Sep 21, 2010 at 5:36 AM, Anand anandut2...@gmail.com wrote: Two unsorted arrays are given A[n] and B[n+1]. Array A contains n integers and B contains n+1 integers

[algogeeks] Re: Point lies inside or outside of triangle?

2010-09-20 Thread Dave
Following up two of my postings. Sorry, but I gave the wrong system of equations in my first posting, and then solved that incorrect system in my second. The system of equations should be xa * a + xb * b + xc * c = xz ya * a + yb * b + yc * c = yz a + b + c = 1 Then the following

Re: [algogeeks] Arrays

2010-09-20 Thread Baljeet Kumar
There can be overflow in case of adding up all the elements. Use Xor instead. int result = 0; for (int i = 0; i n ;i++){ result ^= A[i]^B[i]; } result ^= B[i]; result is the number we need. On Tue, Sep 21, 2010 at 9:48 AM, vishal raja vishal.ge...@gmail.com wrote: add up all the

Re: [algogeeks] Arrays

2010-09-20 Thread Baljeet Kumar
There can be overflow in case of adding up all the elements. Use Xor instead. int result = 0; for (int i = 0; i n ;i++){ result ^= A[i]^B[i]; } result ^= B[n]; === (correction) result is the number we need. On Tue, Sep 21, 2010 at 9:48 AM, vishal raja vishal.ge...@gmail.comwrote:

Re: [algogeeks] Re: point lies inside or outside of triangle..

2010-09-20 Thread kartheek muthyala
@gene i didn't understand the boolean thing in your algo, Say triangle is ABC, say Point is p Algo goes like this, for side AB 1. calculate cross product of(p-A)*(B-A)[ Which is nothing but the side function in gene algo] See the sign. 2. calculate the cross product of (C-A)*(B-A) . See the sign