[algogeeks] Re: a question about pseudo random integers

2010-12-08 Thread pfb
Hi Gene, and thanks for your reply! Yes, I had thought of something like that. However, it seems sort of cumbersome to me: I guess I would want to split the 32-bit integer by means of 32 bitwise ands... Or probably there's a smarter way. Anyway, if the random integers come in bunches of 16 I'd

[algogeeks] The best multiply matrix algorithms ?

2010-12-08 Thread Luciano Junior
What is best multiply matrix algorithm for: -multiply a n x n matrix by another n x n matrix -multiply a m x n matrix by a n x p matrix I need a best performance cpu algorithm. Note: it can use a parallel programming concept. Thankfully. Luciano. --

[algogeeks] program for evaluation of remainders

2010-12-08 Thread ankit sablok
Q) can anyboy find me the solution to this problem Given an integer N and an another integer n we have to write a program to find the remainder of the following problems (1! + 2! + 3! + 4! + . + N!)mod(n) N=100 n=1000; please help me write a program for this problem

[algogeeks] Largest rectangle in a binary matrix

2010-12-08 Thread Prims
Hi Given a binary matrix containing 0s and 1s as elements in it. I need to find efficiently the largest rectangle containing all 1s. For example: in case of 4x4 matrix 1 0 0 1 0 1 1 0 1 1 1 0 0 1 1 1 The largest rectangle is 1 1 1 1 1 1 -Prims -- You received this message because

Re: [algogeeks] Largest rectangle in a binary matrix

2010-12-08 Thread GOBIND KUMAR
Hi, Solution is available at http://geeksforgeeks.org/?p=6257 -- 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

Re: [algogeeks] Largest rectangle in a binary matrix

2010-12-08 Thread ravi teja
Use kadane's 3D algorithm -- 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,

[algogeeks] Re: Largest rectangle in a binary matrix

2010-12-08 Thread Prims
Hello Gobind The link contains the solution for finding the largest square in a binary matrix which is not valid in case of largest rectangle. -Prims On Dec 8, 6:38 pm, GOBIND KUMAR gobind@gmail.com wrote: Hi,     Solution is available athttp://geeksforgeeks.org/?p=6257 -- You received

[algogeeks] Re: program for evaluation of remainders

2010-12-08 Thread Dave
@Ankit: Try this: x = 0; for( i = N ; i 0 ; --i ) x = (i * x + i) % n; Dave On Dec 8, 7:19 am, ankit sablok ankit4...@gmail.com wrote: Q) can anyboy find me the solution to this problem Given an integer N and an another integer n we have to write a program to find the remainder of the

Re: [algogeeks] Re: Largest rectangle in a binary matrix

2010-12-08 Thread Aditya Agrawal
ravi is right .. http://alexeigor.wikidot.com/kadane On Wed, Dec 8, 2010 at 7:31 PM, Prims topcode...@gmail.com wrote: Hello Gobind The link contains the solution for finding the largest square in a binary matrix which is not valid in case of largest rectangle. -Prims On Dec 8, 6:38 pm,

Re: [algogeeks] Re: program for evaluation of remainders

2010-12-08 Thread jai gupta
rem=1; for(j=3;j=N+1;j++) rem=(rem*j)%n; return rem; -- 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

Re: [algogeeks] Re: Amazon Interview Question

2010-12-08 Thread Nikhil Agarwal
@gene: can you do dry run a test case: a[0]-a[n-1] 0 1 2 31 34 135 and if u c On Tue, Dec 7, 2010 at 8:55 AM, Gene gene.ress...@gmail.com wrote: I should have mentioned that this problem only makes sense if the array values must be unique. On Dec 6, 8:20 pm, Gene gene.ress...@gmail.com

[algogeeks] qsort

2010-12-08 Thread ANUJ KUMAR
how can i use qsort a structure. please give me the code if possibe -- 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

Re: [algogeeks] valid paranthesis

2010-12-08 Thread vamsee marpu
Hi, You can use Recursion logic of Catalan Numbers. M. Vamsee -- 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

Re: [algogeeks] Re: convert binary matrix to zero matrix

2010-12-08 Thread Terence
As Amir pointed out: convert the first row and first column to all zeros In details: 1. choose operations on first row and first column to make up-left element 0. * There are 2 cases, 2 choices for each case: 1. If the up-left element is 0, then

Re: [algogeeks] Longest interval with maximum sum

2010-12-08 Thread Amir hossein Shahriari
@jai : since sum of all values in C is between -n and n the last step can be done in O(n) time and O(n) space On Sun, Dec 5, 2010 at 12:44 PM, jai gupta sayhelloto...@gmail.com wrote: @fenghuang: the last step will take O(n logn ) . Or there is some better way? -- You received this message

Re: [algogeeks] program for evaluation of remainders

2010-12-08 Thread Ashim Kapoor
Let me try. Any thing involving n would leave no remainder. so (1 + 2 ! + ... + n ! + + N !) mod n = (1 + 2 ! + ... + (n-1)! ) mod n This should be computed from a loop. I don't know how to reduce it further. Ashim. On Wed, Dec 8, 2010 at 6:49 PM, ankit sablok ankit4...@gmail.com wrote:

Re: [algogeeks] program for evaluation of remainders

2010-12-08 Thread sunny agrawal
@Ashim with a check that N =n N can also be less than n On Wed, Dec 8, 2010 at 6:57 PM, Ashim Kapoor ashimkap...@gmail.com wrote: Let me try. Any thing involving n would leave no remainder. so (1 + 2 ! + ... + n ! + + N !) mod n = (1 + 2 ! + ... + (n-1)! ) mod n This should be

[algogeeks] Re: program for evaluation of remainders

2010-12-08 Thread Dave
Using this idea makes my solution into x = 0; for( i = (n N ? n : N) ; i 0 ; --i ) x = (i * x + i) % n; Dave On Dec 8, 7:27 am, Ashim Kapoor ashimkap...@gmail.com wrote: Let me try. Any thing involving n would leave no remainder. so (1  + 2 ! + ... + n ! + + N !) mod n = (1 + 2 !

Re: [algogeeks] Re: k nearest points

2010-12-08 Thread jai gupta
@coolfrog the question never asked u to find thm in order of thier distances. Correct me if i m wrong! find the distances in O(n) now using the partitioning process of quicksort. Dividing the array into two parts: Now if the Length of the first part is less than or equal to i we have to now make

[algogeeks] help me reduce the time limit

2010-12-08 Thread ankit sablok
please help mewritea program for this problem to reduce the time limit http://www.codechef.com/problems/FLIPCOIN/ thnx in advance i have ben banging my head on this for a full day -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: program for evaluation of remainders

2010-12-08 Thread ankit sablok
@ all the authors thanx for the suggestions actually wt i know about the problem is i think we can solve the problem mathematically if we know about congruences for instance if N=100 1! + 2! + . + 100! and n=12 we find that 4!mod24=0 hence the above equation reduces to the (1!+2!+3!)mod

Re: [algogeeks] Re: k nearest points

2010-12-08 Thread haxxpop
I like Your algorithm; it's the same as I think. -- 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

Re: [algogeeks] qsort

2010-12-08 Thread fenghuang
you mean the function qsort() in crt? here is a sample struct foostruct{ int key; int value1; int value2; }; int compare(const void* a1, const void* a2){ return ((foostruct*)a1)-key - ((const foostruct*)a2)-key; } void bar(){ foostruct s[] ={ {3, 2, 3}, {5, 2, 1}, {2, 6, 5} }; qsort(s,

Re: [algogeeks] help me reduce the time limit

2010-12-08 Thread radha krishnan
see TC forums : On Wed, Dec 8, 2010 at 10:44 PM, ankit sablok ankit4...@gmail.com wrote: please help mewritea program for this problem to reduce the time limit http://www.codechef.com/problems/FLIPCOIN/ thnx in advance i have ben banging my head on this for a full day -- You received this

[algogeeks] Re: program for evaluation of remainders

2010-12-08 Thread Dave
@Ankit: So how does that work with, e.g., N = n = 997? I.e., what is the calculation? Dave On Dec 8, 11:33 am, ankit sablok ankit4...@gmail.com wrote: @ all the authors thanx for the suggestions actually wt i know about the problem is i think we can solve the problem mathematically if we know

Re: [algogeeks] The best multiply matrix algorithms ?

2010-12-08 Thread Rakib Ansary Saikot
Try using Strassen's Matrix Multiplication Algorithm. Regards, Rakib On 12/8/10, Luciano Junior luciano@gmail.com wrote: What is best multiply matrix algorithm for: -multiply a n x n matrix by another n x n matrix -multiply a m x n matrix by a n x p matrix I need a best performance

Re: [algogeeks] The best multiply matrix algorithms ?

2010-12-08 Thread Luciano Junior
But Strassen's Matrix Multiplication Algorithm take a performance near O(n^2,7)! Is there some other algorithm that take less time ? 2010/12/8 Rakib Ansary Saikot ansaryfantas...@gmail.com: Try using Strassen's Matrix Multiplication Algorithm. Regards, Rakib On 12/8/10, Luciano Junior

[algogeeks] Re: The best multiply matrix algorithms ?

2010-12-08 Thread Dave
Are you interested in actual computation speed or are you interested in theoretical big-O speed? If you want the fastest computation for a specific, reasonable-sized problem with no particular structure (i.e., non-sparse), then using the ordinary matrix multiply algorithm that is coded the best

[algogeeks] Re: k nearest points

2010-12-08 Thread Dave
There is an O(n) worst case algorithm for finding the kth smallest element. See http://en.wikipedia.org/wiki/Select_kth_element#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm. Dave On Dec 8, 10:26 am, jai gupta sayhelloto...@gmail.com wrote: @coolfrog the question never

Re: [algogeeks] help me reduce the time limit

2010-12-08 Thread jai gupta
#includestdio.h int main() { int arr[11]={0},sum2[1001]={0}; int type[1001]={0};//0 for tails int N,Q,i,j,sum; int a,b,c; scanf(%d,N); scanf(%d,Q); for(i=0;iQ;i++) { scanf(%d%d%d,a,b,c); if(a==0) { j=b; int

Re: [algogeeks] Google questions

2010-12-08 Thread sahil gujral
explain the 1st one again On Thu, Dec 9, 2010 at 11:16 AM, Anand anandut2...@gmail.com wrote: One of my friend recently had a telephonic interview and he got two question to program. 1. Given a binary search tree. Write a function which takes any given node from the binary tree and a

[algogeeks] help me find a solution

2010-12-08 Thread ankit sablok
can anyone suggest me how to go about this problem i m finding it quite tough http://www.codechef.com/problems/TEAMSEL/ thanx in advance -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to