Re: [algogeeks] Re: check Similar array

2012-01-17 Thread WgpShashank
@atul.. let me tell you ., i told that we can send u took two array arr[]={2,0,0,0} arr2[]={2,-2,1,0}; take 2 as a base in 1st array , calculate sum (exclduing 2 ), calculate base^arr[i] that gives sum1= 3 sorting not allowed , just search linearly 2 in 2nd array e.g. search the same elem

Re: [algogeeks] Re: check Similar array

2012-01-17 Thread atul anand
@ WgpShashank : considering your latest comment abt you algo... /* i didn't get how my approach will fail , can u check for the exmple u said ? if u sum the 1st array using 2 as base then sum will be 3 (*exculding 2 , although it won't metter* ) , then u search that elemnt in 2nd array , u won;

[algogeeks] Re: check Similar array

2012-01-17 Thread sravanreddy001
@Shashank: can you look at the first post from you? you are calculating 3^a[i] & adding it to the sum, can you write a pseudocode so that none of gets confused. (also, if you are saying this. for each element, raise element to the power of 2 (2^a[i]), (like you said in above post), or 3, like

[algogeeks] Re: check Similar array

2012-01-17 Thread WgpShashank
@sravan . u missed man ..read again what i said , u r calculating 3^a[i] , where is 3 comes in to picture , no array has has 3 ?? correct , its should be 2^a[i] , then we search 2 in 2nd array if found 2 the go ahead, read the algo suggested above , its should work . let me know whats your con

[algogeeks] Re: check Similar array

2012-01-09 Thread Anurag Gupta
What about this approach: First we will scan the first array and find the smallest number. if it is -ve then we increment all numbers in both the arrays by that number . This ensures that every integer in first array is >= 0 some integers in 2nd one maybe -ve if it is,then two arrays are not

[algogeeks] Re: check Similar array

2012-01-09 Thread sravanreddy001
@Shashank: from your code, i looked at this part. for j=0 to m sum2+=3^b[j] i assumed 3^b[j] as power(3,b[j]); ==> (2,0,0,0) -> 9+1+1+1 && (1,1,1,1) => 3+3+3+3 & both equals 12. and.. i didn't understand what you meant by base here. did you mean anything else? or did I miss anything? (how can w

[algogeeks] Re: check Similar array

2012-01-09 Thread WgpShashank
@sravan i didn't get how my approach will fail , can u check for the exmple u said ? if u sum the 1st array using 2 as base then sum will be 3 (exculding 2 , although it won't metter ) , then u search that elemnt in 2nd array , u won;t find & u return -1 , say these array are not similer . c

Re: [algogeeks] Re: check Similar array

2012-01-09 Thread Siddhartha Banerjee
create AVL tree using elements of array 1... with each node of AVL tree maintain a count variable... if an element occurs more than once,increment the count... (this step is not compulsory though,we can simply insert the new element in tree) go through the second array,for each element in array, fi

Re: [algogeeks] Re: check Similar array

2012-01-08 Thread SAMM
But the Previous post is not the correct solution as it is similar to hash table of storing the frequency counts .. I was thinking a some Statictical Approach here . We are dealing with some points which scattered in a space and we need to find that the points are at same points or not . That mea

Re: [algogeeks] Re: check Similar array

2012-01-08 Thread SAMM
@All Sry for late reply .. I was offline for sometime . Just wanted to brief why I had come up of having a cummulative sum of each elements of the array . As I mentioned the Frequency distribution of the numbers .. I meant that to the frequency the elements of the array starting from 1 to elemen

[algogeeks] Re: check Similar array

2012-01-07 Thread sravanreddy001
@shashank: your approach fails for (2,0,0,0) & (1,1,1,1) but.. from any of the above approaches seen, we couldn't be 100% sure of the solution, but, from shashank's approach, the probability of finding correct soultion can be improved by using some random prime numbers. (running tests for more

Re: [algogeeks] Re: check Similar array

2012-01-05 Thread WgpShashank
@atul..no need to sorting , complexity will be O(nlogn) only , sorting makes searching easy so said to sort , u can linearly search that elemnt in 2nd array it will take O(m) in above case . finally complexity will be O(nlogn) only Let me know if anything wrong or missed something ? Thanks

Re: [algogeeks] Re: check Similar array

2012-01-05 Thread saurabh singh
Some very nice approaches have been presented but I still feels for practical situations its better to sort and compare..All other algorithms presented above restricts the max value for an element in the array.In case the maximum value is small,we can simply count sort,and the algorithm will st

Re: [algogeeks] Re: check Similar array

2012-01-05 Thread atul anand
@Shashank : as i have mentioned in the question , no sorting allowed. if question would have allowed sorting then why not sort both array and compare it would be much simpler and no need of doing costlier operation like finding power. complexity = O(nogn) + O(mlogm) + O(n) -- You received this

[algogeeks] Re: check Similar array

2012-01-05 Thread WgpShashank
1st of all "Happy New Year to All" :) Must be both have same length also test some other test cases, :) Let me share things striking in mind , if you calculate the sum of power of 1st array by taking any number as base , remaining all the numbers as exponent so if take 3 as base & calculate

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread atul anand
@Ankur : i guess this would work but to your test add one more sizeof(arr); On Wed, Jan 4, 2012 at 10:00 PM, Ankur Garg wrote: > sorry it shud be > sum of squares and xor and sumof elements > > I think this shud work > > Regards > Ankur > > > > > On Wed, Jan 4, 2012 at 9:52 PM, atul anand wrote:

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Ankur Garg
sorry it shud be sum of squares and xor and sumof elements I think this shud work Regards Ankur On Wed, Jan 4, 2012 at 9:52 PM, atul anand wrote: > @ Karthikeyan : > > sum of cubes fails:- > > arr1={2,3,0,-3} = 4 > arr2={1,1,1,1} = 4 > > On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wro

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread atul anand
@ Karthikeyan : sum of cubes fails:- arr1={2,3,0,-3} = 4 arr2={1,1,1,1} = 4 On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote: > Hi, > > Consider, arr1={1,2,3} and arr2={-1,-2,-3} > > using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since > square of 1 and -1 is 1) > > so

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread atul anand
@ankur : arr1={0,2,0,2); arr2={1,1,1,1}; xor ans sum condition satisfy. -- 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 algogeek

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Ankur Garg
What if we check these 2 conditions XOR and sum of elements and sizeof array same I cudnt find any counter example Regards Ankur On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote: > Hi, > > Consider, arr1={1,2,3} and arr2={-1,-2,-3} > > using sum of squares method sum(arr1) = 14 ans sum

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Karthikeyan V.B
Hi, Consider, arr1={1,2,3} and arr2={-1,-2,-3} using sum of squares method sum(arr1) = 14 ans sum(arr2) = 14 (since square of 1 and -1 is 1) so it won work with this case 1.better take the square and negate it before adding or 2.take sum of cubes pls correct me if i'm wrong Regards, Karthike

[algogeeks] Re: check Similar array

2012-01-04 Thread shiv narayan
can't be use squares of no's as said by rahul patil as said in previous comment?? On Jan 4, 10:57 am, atul anand wrote: > @sharad : after checking the link provided by u...it seem like complexity > will be O(n^2) { not sure } + saurabh point is also valid. -- You received this message because y

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread atul anand
@sharad : after checking the link provided by u...it seem like complexity will be O(n^2) { not sure } + saurabh point is also valid. -- 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.c

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread atul anand
Btw an array can have both positive and negative number. On 4 Jan 2012 11:00, "rahul patil" wrote: > > @samm: Rather than adding numbers could we add squares(or cube) of numbers > which could also be done in linear time? > > On Wed, Jan 4, 2012 at 10:56 AM, rahul patil < > rahul.deshmukhpa...@gma

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread saurabh singh
@sharad Your approach limits the size of array to be very small(as well as the elements of the array to be small).Else the product will become too big to be held in an array.Same applies with samm's solution too though in his case we can be more liberal with element's value.. Saurabh Singh B.

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread sharad dixit
Can we use concept of prime number as fundamental theorem of arithmetic i.e every number has a unique factorization into primes ( http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic) and then multiply them together. e.g A1[3] = { 2,3,4} => secondprime*thirdprime*forthprime = 2 * 3 *

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread rahul patil
@samm: Rather than adding numbers could we add squares(or cube) of numbers which could also be done in linear time? On Wed, Jan 4, 2012 at 10:56 AM, rahul patil wrote: > @samm: Ur solution is great. It could be used to tell that arrays are not > similar, in linear time. But cant tell that they ar

Re: [algogeeks] Re: check Similar array

2012-01-03 Thread rahul patil
@samm: Ur solution is great. It could be used to tell that arrays are not similar, in linear time. But cant tell that they are 100% similar ur solution fails for the simple case. arr1: 3,4 arr2: 5,1 On Wed, Jan 4, 2012 at 10:49 AM, SAMMM wrote: > No it's not if u use the AP series mathematical f

[algogeeks] Re: check Similar array

2012-01-03 Thread SAMMM
No it's not if u use the AP series mathematical formula n(n+1)/2.. Then it will be of O(n). -- 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