Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
http://www.janaganamana.net/onedefault.aspx?bid=276

did not get it


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Tue, Jan 10, 2012 at 1:15 PM, Ashish Goel  wrote:

> this is a single island, sorry for that
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Tue, Jan 10, 2012 at 9:24 AM, atul anand wrote:
>
>> @Ashish Goel : didnt get it :(
>>
>>
>> 1 1 0 0
>> 1 1 0 0
>> 0 0 1 1
>>
>>
>> 1-1-1 diagonal is one island ...where is another??
>>
>> 1 1 0 0
>> 1 1 0 0
>> 0 0 1 1
>>
>> these 1 will be considered one island of 2 island.??
>>
>>
>>
>> On Tue, Jan 10, 2012 at 7:36 AM, Ashish Goel  wrote:
>>
>>> row, col, diag all
>>>
>>> 1-1-1 is a single island :)
>>>
>>>
>>> 1 1 0 0
>>> 1 1 0 0
>>> 0 0 1 1
>>>
>>> this has only 2 islands
>>>
>>>
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>>
>>>
>>> On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg wrote:
>>>
 Can you give an example

 Say  matrix is

 1 1 0 0
 1 1 0 0
 0 0 1 1

 Has it got 3 islands i.e 1-1 be in same row or they can be column wise
 also i.e. 5



 On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel  wrote:

> there is a matrix of 1 and 0
> 1 is a island and 0 is water
> 1-1 together makes one island
> calculate total no of islands
>
> Best Regards
>
> Ashish Goel
> "Think positive and find fuel in failure"
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

  --
 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...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> 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...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
this is a single island, sorry for that
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Tue, Jan 10, 2012 at 9:24 AM, atul anand  wrote:

> @Ashish Goel : didnt get it :(
>
>
> 1 1 0 0
> 1 1 0 0
> 0 0 1 1
>
>
> 1-1-1 diagonal is one island ...where is another??
>
> 1 1 0 0
> 1 1 0 0
> 0 0 1 1
>
> these 1 will be considered one island of 2 island.??
>
>
>
> On Tue, Jan 10, 2012 at 7:36 AM, Ashish Goel  wrote:
>
>> row, col, diag all
>>
>> 1-1-1 is a single island :)
>>
>>
>> 1 1 0 0
>> 1 1 0 0
>> 0 0 1 1
>>
>> this has only 2 islands
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>>
>> On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg  wrote:
>>
>>> Can you give an example
>>>
>>> Say  matrix is
>>>
>>> 1 1 0 0
>>> 1 1 0 0
>>> 0 0 1 1
>>>
>>> Has it got 3 islands i.e 1-1 be in same row or they can be column wise
>>> also i.e. 5
>>>
>>>
>>>
>>> On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel  wrote:
>>>
 there is a matrix of 1 and 0
 1 is a island and 0 is water
 1-1 together makes one island
 calculate total no of islands

 Best Regards

 Ashish Goel
 "Think positive and find fuel in failure"

  --
 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...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> 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...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread Ramakant Sharma
@atul:
no..my approach was wrongwe have to check recursively...as sravan said

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c output ??

2012-01-09 Thread Kartik Sachan
@amol I think  it is not the behaviour of printf

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Piyush Grover
How to create the lookup table?
say if I have W = {2, 4, 6, 8} and Wmax = 3

0   1   2   3
0  1   0   0   0
1  1   1   1   0
2  1   1   1   1
3  1   1   1   1
4  1   1   1   1

Is this correct???

On Mon, Jan 9, 2012 at 2:55 PM, Lucifer  wrote:

> @All
>
> The same algo will work for both +ve and -ve nos.. no need for
> modification..
>
> For ex-
> Say the sum is 4 and the set is { 1, 2, 3, -2 }
>
> Now if u include -2 as part of ur solution then for the rest 3
> elements the sum would be 4-(-2) = 6, which is correct...
>
>
> On Jan 9, 2:20 pm, Siddhartha  wrote:
> > yup...that was what i was thinking... i guess for negative nos, we can
> > define Wmax= sum of modulus of weights,and then the  same algo works...
>
> --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@Ramakant : i guess you shud include diagonal case also 

for each arr[i][j]
if(arr[i][j]==1)
{
if (!(arr[i-1][j]==1 || arr[i][j-1]==1 || arr[i-1][j-1]))
count++;
}




On Tue, Jan 10, 2012 at 9:33 AM, Ramakant Sharma wrote:

> Scan the matrix row wise left to right
> for each arr[i][j]
> if(arr[i][j]==1)
> {
> if (!(arr[i-1][j]==1||arr[i][j-1]==1))
> count++;
> }
> ///also chk for baundary values accordingly
>
>
>
>
> 1 1 0 0
> 1 1 0 0
> 0 0 1 1
>
>
> i think it should work..
>
> --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: finding subarray

2012-01-09 Thread priyanka jaggi
@ankur : in this question, the elements of the array are continuous

i think the solution of shravan reddy is correct and works for negative nos
too.

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread Ramakant Sharma
Scan the matrix row wise left to right
for each arr[i][j]
if(arr[i][j]==1)
{
if (!(arr[i-1][j]==1||arr[i][j-1]==1))
count++;
}
///also chk for baundary values accordingly



1 1 0 0
1 1 0 0
0 0 1 1

i think it should work..

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@sravanreddy001 : got it ..thanks :)

On Tue, Jan 10, 2012 at 9:33 AM, sravanreddy001 wrote:

> @atul: given a matrix just like above, (usually an image) the pixel values
> with similar can be searched for around the current pixel, and they all can
> be marked in one go,
>
> think of an algorithm, which does the following
>
> 1) when a one is replaced by '2' manually, then algorithm changes every
> '1' that is adjacent to '2' in a recursive fashion.
> 2) now, how many times the manual involvement is needed.
>
> assuming the algorithm spreads across diagonals too, then the below
> example has only one island, or as per my example, changing any one 1 to 2,
> will do the trick,
>
> 1100
> 1100
> 0011
>
> --> 1 islands, or 1 manual changes
>
> 1100
> 1100
> 0001
>
> --> 2 islands, or 2 manual changes
>
> 1101
> 1101
> 1100
> 0001
>
> --> 3 islands, or 3 manual changes
>
> (if you didn't understand what a pixel filler is.. you can leave that for
> now.. its just one application of BFS)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/DLCoXlVhNccJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread sravanreddy001
@atul: given a matrix just like above, (usually an image) the pixel values 
with similar can be searched for around the current pixel, and they all can 
be marked in one go,

think of an algorithm, which does the following

1) when a one is replaced by '2' manually, then algorithm changes every '1' 
that is adjacent to '2' in a recursive fashion.
2) now, how many times the manual involvement is needed.

assuming the algorithm spreads across diagonals too, then the below example 
has only one island, or as per my example, changing any one 1 to 2, will do 
the trick, 

1100
1100
0011

--> 1 islands, or 1 manual changes

1100
1100
0001

--> 2 islands, or 2 manual changes

1101
1101
1100
0001

--> 3 islands, or 3 manual changes

(if you didn't understand what a pixel filler is.. you can leave that for 
now.. its just one application of BFS)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/DLCoXlVhNccJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@Ashish Goel : didnt get it :(

1 1 0 0
1 1 0 0
0 0 1 1


1-1-1 diagonal is one island ...where is another??

1 1 0 0
1 1 0 0
0 0 1 1

these 1 will be considered one island of 2 island.??


On Tue, Jan 10, 2012 at 7:36 AM, Ashish Goel  wrote:

> row, col, diag all
>
> 1-1-1 is a single island :)
>
>
> 1 1 0 0
> 1 1 0 0
> 0 0 1 1
>
> this has only 2 islands
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
>
> On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg  wrote:
>
>> Can you give an example
>>
>> Say  matrix is
>>
>> 1 1 0 0
>> 1 1 0 0
>> 0 0 1 1
>>
>> Has it got 3 islands i.e 1-1 be in same row or they can be column wise
>> also i.e. 5
>>
>>
>>
>> On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel  wrote:
>>
>>> there is a matrix of 1 and 0
>>> 1 is a island and 0 is water
>>> 1-1 together makes one island
>>> calculate total no of islands
>>>
>>> Best Regards
>>>
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>>
>>>  --
>>> 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...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@sravanreddy001 : Pixel fill algorithm ..what is the exact name of that
algo ???

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread sravanreddy001
this is similar to the Pixel fill algorithm usually used in photo editing 
softwares (photoshop or paint )

BFS would be best approach to start with ( and check 4-adjacent or 
8-includeing diagonal elements for a '1' and include that to queue. When 
the queue becomes empty, increase the count by 1. repeat until all the 
elements are processed and return "count"

http://ideone.com/OUYpd

NOTE: This is a similar code, but logic is a same, certain terminology is 
different, and the example discussed above will have only 1 island 
according to the below code. If two islands is expected (diagonals not 
considered, 4 condition in the while have to be removed)


#include#include #include 
 using namespace std;
 struct POS{
int row_no;
int col_no;};
 
queue Q;
 
POS get_POS(int row,int col){
POS p;
p.row_no = row;
p.col_no = col;
return p;}
 void FILL_PIXELS(char filename[10]){
FILE *p = fopen(filename,"r");
if(p==NULL)
exit(1);
//while()
int rows=0,cols=0;
fscanf(p,"%d %d\n",&rows,&cols);
char array[rows][cols+1];
//fflush(stdin);
int i=0;
for(;i0 && y>0 && array[x-1][y-1] == 
'0'){
Q.push(get_POS(x-1,y-1));
array[x-1][y-1] = '1';
}
if(x>0 && array[x-1][y]=='0'){
Q.push(get_POS(x-1,y));
array[x-1][y] = '1';
}
if(x>0 && y<(cols-1) && 
array[x-1][y+1]=='0'){
Q.push(get_POS(x-1,y+1));
array[x-1][y+1] = '1';
}
if(y>0 && array[x][y-1]=='0'){
Q.push(get_POS(x,y-1));
array[x][y-1] = '1';
}
if(y<(cols-1) && array[x][y+1]=='0'){
Q.push(get_POS(x,y+1));
array[x][y+1] = '1';
}
if(y>0 && x<(rows-1) && 
array[x+1][y-1]=='0'){
Q.push(get_POS(x+1,y-1));
array[x+1][y-1] = '1';
}
if(x<(rows-1) &&  array[x+1][y]=='0'){
Q.push(get_POS(x+1,y));
array[x+1][y] = '1';
}
if(x<(rows-1) && y<(cols-1) && 
array[x+1][y+1]=='0'){
Q.push(get_POS(x+1,y+1));
array[x+1][y+1] = '1';
}
}
}
}
}
/*p = fopen("a.out","w");fprintf(p,"%d",no_of_fills);
fclose(p);*/
printf("%d\n",no_of_fills);}
 
 int main(int argc,char **argv){
FILL_PIXELS(argv[1]);}


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/YTHGgaxrPy0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: finding subarray

2012-01-09 Thread sravanreddy001
and.. yes for this example,
-2, 8, -6 it results in "No solution." (or doesn't print anything.)

but works if its -2, 8, 6 where (-2+8 == 6)

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/D9_xTy-LQkAJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: finding subarray

2012-01-09 Thread sravanreddy001
The question mentions of Subarray (which is like a substring in the string)

I think you are assuming it to be any subset, in that case even O(n^3) time 
will not be sufficient and its an exponential time algorithm.

with the subarray like my assumption, the bruteforce approach will be to 
find all the n^2 sub array's and for each find if satisfies in O(n) time, 
using the similar logic, 
maintain left, right & start adding the ends and coming towards the center. 
which results in O(n^3) time.

let me know if my understanding is wrong.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/BRDRMATaJo8J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: finding subarray

2012-01-09 Thread Ankur Garg
I think this wont work for cases with negetive nos

Ex

-2,8,-6

On Tue, Jan 10, 2012 at 6:51 AM, sravanreddy001 wrote:

>
> solution at this link:
> http://ideone.com/ifVIv
>
> for every position, (iteration)
> maitain left, right for the sums,
> keep adding elements towards the begenning to left, and towards the end to
> right, (based on the conditions in the code)
>
> Complexity: outer forloop : O(n)
> inner while loop O(n)
> total O(n^2) and O(1) space.
>
> its currently printing all the position, & center is included to the left
> side,
>
> Left : 3, Right: 9, Center: 6
> this reads as.. sum(elements at 3,4,5,6) == sum(elements at 7,8,9)
>
> let me know if it needs more explanantion.
>
>
>
>
> for(int i=0;i int left=0,right=0;
> int p1 = i;
> int p2 = i+1;
> left = left + a[p1];
> right = right + a[p2];
> while(p1>=0 && p2< len){
> if( left == right){
> printf("Left : %d, Right: %d, Center: %d 
> \n",p1,p2,i);
> break;
> //return 0;
> }
> else if(left > right && p2 < len-1){
> p2++;
> right = right+ a[p2];
> }
> else if(left < right && p1 > 0){
> p1--;
> left = left + a[p1];
> }
> else{
> //printf("Left : %d, Right: %d, Center: %d 
> \n",p1,p2,i);
> //printf("Not Possible\n");
> break;
> //return 0;
> }
> }
>
> }
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/GoJEA73v8dcJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Binary Search Problem

2012-01-09 Thread Gene
Exactly.  And note that if pointers and unsigned integers have the
same number of bits, overflow can't be a problem as long as the array
elements are 2 bytes or more long.  I.e. if you have an n-bit machine,
the last 2-byte array element can't have index more than 2^n/2 - 1 =
2^(n-1) - 1.  Consequently when doing the addition in (lo+hi)/2,  the
numerator can't be more than 2*[2^(n-1)-1] = 2^n - 2, which isn't an
overflow, though you do have to be careful to use unsigned arithmetic
in this case.

On Jan 9, 4:48 pm, Don  wrote:
> The intermediate value of start+end may be too large to store in an
> integer, even though start and end by themselves are in the valid
> range. If you know this to not be the case, you can use the simpler
> form.
> Don
>
> On Jan 8, 5:04 am, Sanjay Rajpal  wrote:
>
>
>
> > In binary search,
>
> > mid = start + (end-start)/2 is used to avoid overflow, as said by a book.
>
> > why can't we use mid = (start + end)/2, it says this statement may result
> > in overflow ?
> > *
> > Sanjay Kumar
> > B.Tech Final Year
> > Department of Computer Engineering
> > National Institute of Technology Kurukshetra
> > Kurukshetra - 136119
> > Haryana, India
> > Contact: +91-8053566286
> > *

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
row, col, diag all

1-1-1 is a single island :)

1 1 0 0
1 1 0 0
0 0 1 1

this has only 2 islands


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg  wrote:

> Can you give an example
>
> Say  matrix is
>
> 1 1 0 0
> 1 1 0 0
> 0 0 1 1
>
> Has it got 3 islands i.e 1-1 be in same row or they can be column wise
> also i.e. 5
>
>
>
> On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel  wrote:
>
>> there is a matrix of 1 and 0
>> 1 is a island and 0 is water
>> 1-1 together makes one island
>> calculate total no of islands
>>
>> Best Regards
>>
>> Ashish Goel
>> "Think positive and find fuel in failure"
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MS Q

2012-01-09 Thread Ankur Garg
Can you give an example

Say  matrix is

1 1 0 0
1 1 0 0
0 0 1 1

Has it got 3 islands i.e 1-1 be in same row or they can be column wise also
i.e. 5



On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel  wrote:

> there is a matrix of 1 and 0
> 1 is a island and 0 is water
> 1-1 together makes one island
> calculate total no of islands
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] MS Q

2012-01-09 Thread Ashish Goel
there is a matrix of 1 and 0
1 is a island and 0 is water
1-1 together makes one island
calculate total no of islands

Best Regards
Ashish Goel
"Think positive and find fuel in failure"

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: finding subarray

2012-01-09 Thread sravanreddy001

solution at this link:
http://ideone.com/ifVIv 

for every position, (iteration)
maitain left, right for the sums,
keep adding elements towards the begenning to left, and towards the end to 
right, (based on the conditions in the code)

Complexity: outer forloop : O(n)
inner while loop O(n) 
total O(n^2) and O(1) space.

its currently printing all the position, & center is included to the left 
side,

Left : 3, Right: 9, Center: 6 
this reads as.. sum(elements at 3,4,5,6) == sum(elements at 7,8,9)

let me know if it needs more explanantion.




for(int i=0;i=0 && p2< len){
if( left == right){
printf("Left : %d, Right: %d, Center: %d 
\n",p1,p2,i);
break;
//return 0;
}
else if(left > right && p2 < len-1){
p2++;
right = right+ a[p2];
}
else if(left < right && p1 > 0){
p1--;
left = left + a[p1];
}
else{
//printf("Left : %d, Right: %d, Center: %d 
\n",p1,p2,i);
//printf("Not Possible\n");
break;
//return 0;
}
}

}


-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/GoJEA73v8dcJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] finding subarray

2012-01-09 Thread Ankur Garg
@Priyanka ...Do the elements of the subarray need to be continuous ..The
example considers it continuous but still just for clarity ?

On Tue, Jan 10, 2012 at 12:50 AM, surender sanke wrote:

> using extra space of O(n) we can do it in O(n^2)
> take an array for storing cumulative sums from index i till 0,
> then from i+1 till n-1 find summing each array value find whether it
> exists in array.
> if its so display indexes
> eg
> Array: 2,2,13,4,7,3,8,12,9,1,5
> i = 3   ^
> temp array:  4, 17, 19, 21
> finding for cumulative sums from i+1 till i<=(any of values in temp array)
> i = 6   ^
> temp array:  8, 11, 18, 22
> finding for cumulative sums from i+1 till i<=(any of values in temp array)
> found values from i+1 till i+3
> Repeating for every i,
>
> surender
>
>
> On Mon, Jan 9, 2012 at 11:22 PM, priyanka jaggi 
> wrote:
>
>> Given an array (length n), we need to find the subarray (length k) such
>> that the sum of the first j elements of the subarray equals the sum of the
>> remaining (k-j) elements of the subarray.
>> For e.g.
>> Array: 2,2,13,4,7,3,8,12,9,1,5
>> Output: 4,7,3,8,12,9,1 [4+7+3+8=12+9+1]
>> Could this be done with a complexity better than O(n^3)
>> k is not given .
>>
>> --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Binary Search Problem

2012-01-09 Thread Don
The intermediate value of start+end may be too large to store in an
integer, even though start and end by themselves are in the valid
range. If you know this to not be the case, you can use the simpler
form.
Don

On Jan 8, 5:04 am, Sanjay Rajpal  wrote:
> In binary search,
>
> mid = start + (end-start)/2 is used to avoid overflow, as said by a book.
>
> why can't we use mid = (start + end)/2, it says this statement may result
> in overflow ?
> *
> Sanjay Kumar
> B.Tech Final Year
> Department of Computer Engineering
> National Institute of Technology Kurukshetra
> Kurukshetra - 136119
> Haryana, India
> Contact: +91-8053566286
> *

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] finding subarray

2012-01-09 Thread surender sanke
using extra space of O(n) we can do it in O(n^2)
take an array for storing cumulative sums from index i till 0,
then from i+1 till n-1 find summing each array value find whether it exists
in array.
if its so display indexes
eg
Array: 2,2,13,4,7,3,8,12,9,1,5
i = 3   ^
temp array:  4, 17, 19, 21
finding for cumulative sums from i+1 till i<=(any of values in temp array)
i = 6   ^
temp array:  8, 11, 18, 22
finding for cumulative sums from i+1 till i<=(any of values in temp array)
found values from i+1 till i+3
Repeating for every i,

surender


On Mon, Jan 9, 2012 at 11:22 PM, priyanka jaggi wrote:

> Given an array (length n), we need to find the subarray (length k) such
> that the sum of the first j elements of the subarray equals the sum of the
> remaining (k-j) elements of the subarray.
> For e.g.
> Array: 2,2,13,4,7,3,8,12,9,1,5
> Output: 4,7,3,8,12,9,1 [4+7+3+8=12+9+1]
> Could this be done with a complexity better than O(n^3)
> k is not given .
>
> --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] finding subarray

2012-01-09 Thread priyanka jaggi
Given an array (length n), we need to find the subarray (length k) such
that the sum of the first j elements of the subarray equals the sum of the
remaining (k-j) elements of the subarray.
For e.g.
Array: 2,2,13,4,7,3,8,12,9,1,5
Output: 4,7,3,8,12,9,1 [4+7+3+8=12+9+1]
Could this be done with a complexity better than O(n^3)
k is not given .

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 similar
else we follow frequency based tests to find out if two array are
similar or not.

Time and space Complexity = O(n)
This approach assumes that even after adding that most negative number
each number in both arrays will be inside the limits of their data
types (long long etc)
Any counter test case(s)?

On Jan 5, 5:35 pm, saurabh singh  wrote:
> 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 still be O(N) (Much simpler and immune to problems such as
> finite word size)
>
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT
> blog:geekinessthecoolway.blogspot.com
>
>
>
>
>
>
>
> On Thu, Jan 5, 2012 at 5:17 PM, atul anand  wrote:
> > @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 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...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c output ??

2012-01-09 Thread Amol Sharma
According to K&R the behavior of printf is undefined if u do not use
correct format specifiers for the variables.
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 








On Mon, Jan 9, 2012 at 11:01 AM, atul anand  wrote:

> take care when ever you use %d and %f
>
> %d is not flexible in handling float varibaledo not expect it to
> typecast itself.
> reason could be , you are trying to fit large data type i.e float to  the
> int whose range is less.
>
> whereas in second case float can incorporate int type , so automatic
> typecasting is done.
>
>
> On Mon, Jan 9, 2012 at 10:17 AM, HARSHIT PAHUJA 
> wrote:
>
>> *#include
>> int main()
>> {
>> float f=25.25;
>> printf("%d\n",f);
>> long int x=90;
>> printf("%f",x);
>> return 0;
>> }
>> *
>>
>> above program gives output
>> *0
>> 25.25*
>>
>> shudn it be :
>> *25
>> 90.*
>>  ??
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 we prove mathematically in case if we don't find any example. and 
link will be highly appreciated.)

another point. the size of array in function in n.  O(n)
and the values in b[j] are not function of n. the values in b[j] could be 
some 2^n, meaning it takes O(N) time to calculate the power.
(2^n may not be practical.. but this should not be ruled out)

@Siddhardh: your solution works.. but
AVL tree is a self-balancing binary search tree right? and it implecitly 
does sort elements. 
and the questions asks us not to use any sorting.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/sYximOXWEz0J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 .


correct me if i got wrong ?

Thanks
Shashank Mani 
Computer Science
Birla Institute of Technology,Mesra

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/6DQ6oKWebh4J.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Lucifer
@All

The same algo will work for both +ve and -ve nos.. no need for
modification..

For ex-
Say the sum is 4 and the set is { 1, 2, 3, -2 }

Now if u include -2 as part of ur solution then for the rest 3
elements the sum would be 4-(-2) = 6, which is correct...


On Jan 9, 2:20 pm, Siddhartha  wrote:
> yup...that was what i was thinking... i guess for negative nos, we can
> define Wmax= sum of modulus of weights,and then the  same algo works...

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Siddhartha
yup...that was what i was thinking... i guess for negative nos, we can
define Wmax= sum of modulus of weights,and then the  same algo works...

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread atul anand
@Siddhartha : i dont think so this will work for -ve number because we are
doing A[ i - 1, j - W[i] ] so if W[i] is -ve number then it would increases
Wmax which is the number of column.

i guess same algo can be modified so as to make it work for -ve number.


On Mon, Jan 9, 2012 at 2:23 PM, Siddhartha  wrote:

> @lucifer and others: does this work for negative elements? What to do
> then???
>
> --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Facebook interview question.

2012-01-09 Thread atul anand
@Piyush : yes it works ... please check the link again ..Lucifer has added
more details to the same post for better explanation.
follow that link and if you have any queries post your queries on that old
link.

On Mon, Jan 9, 2012 at 1:04 PM, Piyush Grover wrote:

> Hi Atul
>
> Yes, I posted it earlier but couldn't keep track of it, thanks for the
> link. I still have a doubt, does it give all the maximal subsets
> or all the subsets. I couldn't get it from the algo posted by Lucifer.
>
> On Mon, Jan 9, 2012 at 9:45 AM, atul anand wrote:
>
>> @Piyush :
>> you are re-posting same problem which you had posted on 5 dec 2011.
>>
>> check this link :-
>>
>>
>> http://groups.google.com/group/algogeeks/browse_thread/thread/8a58ea05c96f811b/ee74f8a4d7b68561?lnk=gst&q=Maximal+possible+subsets+Algorithm#ee74f8a4d7b68561
>>
>>
>> On Mon, Jan 9, 2012 at 3:27 AM, Piyush Grover 
>> wrote:
>>
>>> Given a set S, find all the maximal subsets whose sum <= k. For example,
>>> if S = {1, 2, 3, 4, 5} and k = 7
>>> Output is: {1, 2, 3} {1, 2, 4} {1, 5} {2, 5} {3, 4}
>>>
>>> Hint:
>>> - Output doesn't contain any set which is a subset of other.
>>> - If X = {1, 2, 3} is one of the solution then all the subsets of X {1}
>>> {2} {3} {1, 2} {1, 3} {2, 3} are omitted.
>>> - Lexicographic ordering may be used to solve it
>>>
>>>  --
>>> 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...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Maximal possible subsets Algorithm

2012-01-09 Thread Siddhartha
@lucifer and others: does this work for negative elements? What to do
then???

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Facebook interview question.

2012-01-09 Thread Siddhartha Banerjee
does this work if array elements are negative???

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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, find the element in
AVL tree (if not found then arrays are not same)
delete the corresponding node (or decrement the count if maintianing
it)...finally the AVL tree should not have any element left..

O(nlogn)

-- 
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...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.