Re: [algogeeks] Array problem

2011-05-16 Thread anuj agarwal
How about create a BST and then, for each node find the difference between the node and its child and do this for all except leaf nodes. If u want i will write the code for the same. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at

Re: [algogeeks] Array problem

2011-05-16 Thread Piyush Sinha
how about this?? *int maxinterval(int a[],int i,int j) { if(i==j) return 0; int max1 = 0,max2; max2 = maxinterval(a,i+1,j); while(ij) { if(a[i]a[j]) { if(j-i)max1) max1 =j-i; } i++; } return(max1max2?max1:max2); } * On Mon, May 16, 2011 at 11:36 AM, anuj agarwal

[algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread Lavesh Rawat
*W Riddle * * * ** *George Washington's wife was sweeping when George Washington's wife slipped and got wet. How many w's in all? * *Update Your Answers at* : Click Herehttp://dailybrainteaser.blogspot.com/2011/05/w-riddle-16-may.html?lavesh=lavesh Solution: Will be updated after 1 day --

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread vivek kumar pandey
only one On Mon, May 16, 2011 at 1:03 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *W Riddle * * *** * * ** *George Washington's wife was sweeping when George Washington's wife slipped and got wet. How many w's in all? * *Update Your Answers at* : Click

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread Piyush Sinha
10 On Mon, May 16, 2011 at 1:03 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *W Riddle * * * ** *George Washington's wife was sweeping when George Washington's wife slipped and got wet. How many w's in all? * *Update Your Answers at* : Click

Re: [algogeeks] Re: Extract Top K elements from a List of N elements based on frequency

2011-05-16 Thread Piyush Sinha
Can't we do this using map library function..mapping the integer with their frequency count?? On Sun, May 15, 2011 at 10:15 PM, Dave dave_and_da...@juno.com wrote: @Akshata: Yes. In my response of May 7, I proposed an algorithm using hashing. On May 9, Apoorve asked if there was an in-place

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread Piyush Sinha
@vivek...how come only one?? I think its 8... On Mon, May 16, 2011 at 1:03 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *W Riddle * * * ** *George Washington's wife was sweeping when George Washington's wife slipped and got wet. How many w's in all? * *Update Your Answers at* :

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread Anders Ma
I‘v no idea, please give detail analysis, thanks! On Mon, May 16, 2011 at 5:26 PM, Piyush Sinha ecstasy.piy...@gmail.com wrote: @vivek...how come only one?? I think its 8... On Mon, May 16, 2011 at 1:03 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: W Riddle George Washington's wife was

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread nishaanth
only 1... its w's that we have to count not w :P On Mon, May 16, 2011 at 11:26 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: @vivek...how come only one?? I think its 8... On Mon, May 16, 2011 at 1:03 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *W Riddle * * * ** *George

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread Balaji S
0, ther are no w's in all :P -- 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

Re: [algogeeks] Print Subsets

2011-05-16 Thread anshu mishra
its DP problem can be solved in O(m*n) where m is number of elements in array and n is value of the given number. -- 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

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread radha krishnan
^like :P :P :P ALL :P :P On Mon, May 16, 2011 at 4:22 PM, Balaji S balaji.ceg...@gmail.com wrote: 0, ther are no w's in all :P -- 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: first fit bin packing

2011-05-16 Thread anshu
we can use BIT or segment trees. algorithm using segment tree 1. intialize all node wid zeros 2. read the array element according their index update the node value. void update(int s, int e, int k, int node) { if (tree[node] ar[k]) tree[node] = ar[k]; if (s==e) return; mid = (s+e) 1; if (k =

[algogeeks] Re: prim problem

2011-05-16 Thread Don
No idea. It would help to tell us what it is intended to do and what it is actually doing, and maybe include the main function so we can see how it is called and how the global variables are initialized. On May 15, 1:45 pm, Edu edu.cv...@gmail.com wrote: Hi, this should be working, where is the

Re: [algogeeks] Array problem

2011-05-16 Thread anuj agarwal
Kunal, Your solution runs in O(n) time but it is a wrong solution. It will run fine if the array is sorted. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at 7:17 PM, Kunal Patil kp101...@gmail.com wrote: @Piyush Sinha: I doubt

Re: [algogeeks] Print Subsets

2011-05-16 Thread anuj agarwal
Correct. Its a variant of Knapsack problem. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at 4:53 PM, anshu mishra anshumishra6...@gmail.comwrote: its DP problem can be solved in O(m*n) where m is number of elements in array and n

Re: [algogeeks] Re: Google Q

2011-05-16 Thread Anand
Your sliding window should not be small enough to get the median. For a free running stream, your window should be of size not less than 100. On Sun, May 15, 2011 at 7:35 PM, Akshata Sharma akshatasharm...@gmail.comwrote: @Anand: if the stream is let 1,2,3,4,6,7,9 and let we choose k=3

Re: [algogeeks] Re: first fit bin packing

2011-05-16 Thread Akshata Sharma
@Anuj: I have a doubt. I am not getting how to update all the nodes up the leaf node which we found in the query for our value. The biggest capacity bin for all the above nodes will change once we modify the leaf value. How to propagate this upwards? After each query, do we again need to run the

Re: [algogeeks] Re: first fit bin packing

2011-05-16 Thread Akshata Sharma
sorry, above mail is addressed to Anshu. :P On Mon, May 16, 2011 at 10:08 PM, Akshata Sharma akshatasharm...@gmail.comwrote: @Anuj: I have a doubt. I am not getting how to update all the nodes up the leaf node which we found in the query for our value. The biggest capacity bin for all the

Re: [algogeeks] Array problem

2011-05-16 Thread Piyush Sinha
@kunal.. anuj is right..ur code works only for sorted array...and I missed the part of doing it in O(n) time...I don't think there is way of doing it in O(n) time...if its there and if amit knows the solution, he should provide some hints... On 5/16/11, anuj agarwal coolbuddy...@gmail.com wrote:

Re: [algogeeks] Array problem

2011-05-16 Thread Kunal Patil
@Anuj Piyush: You didn't get the algo. It works on unsorted array also. You might have missed the statement *else // next element is smaller than or equal to current element reset curr_max to 1;* Here, the comment itself shows unsorted elements have been taken into consideration. If you

Re: [algogeeks] Array problem

2011-05-16 Thread Piyush Sinha
@kunal i think we both understood the problem differently...thats what i asked from amit..that whether in the window is it neccessary the elements in between should also be in increasing order or only the end elements should have the relation of one being greater than the other...I too

[algogeeks] nearest neighbour

2011-05-16 Thread Piyush Sinha
Say you have an array containing information regarding n people. Each person is described using a string (their name) and a number (their position along a number line). Each person has three friends, which are the three people whose number is nearest their own. Describe an algorithm to identify

[algogeeks] siemen star

2011-05-16 Thread Arun Vishwanathan
hi all, Does anyone have an algorithm to detect siemens star(s) in an image?? -- 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] Re: nearest neighbour

2011-05-16 Thread Dave
@Piyush. The simplest algorithm is to sort the array entries by the number. Then the three friends of each person will be the closest three of the set comprising the closest three on the left and the closest three on the right. This algorithm has running time O(n log n). Usually, we regard being

[algogeeks] Error

2011-05-16 Thread Akshata Sharma
can someone please tell me why I am getting this error? #includeiostream #includestack #includeconio.h using namespace std; int main() { stackpairint,int stk; stk.push(make_pair(2,1)); stk.push(make_pair(3,2)); pairint,int p = stk.pop(); //at this line I am getting error conversion from

Re: [algogeeks] Error

2011-05-16 Thread rahul
pop op doesn't return anything...use top.something like that op. Rahul. On Tue, May 17, 2011 at 9:29 AM, Akshata Sharma akshatasharm...@gmail.comwrote: can someone please tell me why I am getting this error? #includeiostream #includestack #includeconio.h using namespace std; int main()

Re: [algogeeks] Error

2011-05-16 Thread Akshata Sharma
ya.. sorry my mistake! On Tue, May 17, 2011 at 9:31 AM, rahul rahulr...@gmail.com wrote: pop op doesn't return anything...use top.something like that op. Rahul. On Tue, May 17, 2011 at 9:29 AM, Akshata Sharma akshatasharm...@gmail.com wrote: can someone please tell me why I am getting

Re: [algogeeks] Error

2011-05-16 Thread rahul
it happens, v learn by making mistakes... keep coding. On Tue, May 17, 2011 at 9:35 AM, Akshata Sharma akshatasharm...@gmail.comwrote: ya.. sorry my mistake! On Tue, May 17, 2011 at 9:31 AM, rahul rahulr...@gmail.com wrote: pop op doesn't return anything...use top.something like that

Re: [algogeeks] Re: first fit bin packing

2011-05-16 Thread anshu mishra
void query(int w, int s, int e, int node) { if (s==e) { tree[node] -= w; prpogateNewMax(node); return; } mid = (s+e)1; if (tree[(node1)+1] = w) query(w, s, mid, (node1)+1); else query(w, mid+1, e, (node1)+2); } void prpogateNewMax(int node) { if (node == 0) return; int par = (node-1)1; int a =

Re: [algogeeks] Re: nearest neighbour

2011-05-16 Thread Piyush Sinha
thanks Dave :) This is a standard Google question On 5/17/11, Dave dave_and_da...@juno.com wrote: @Piyush. The simplest algorithm is to sort the array entries by the number. Then the three friends of each person will be the closest three of the set comprising the closest three on the

Re: [algogeeks] [brain teaser ] W Riddle 16 may

2011-05-16 Thread hary rathor
9 -- 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