Re: [algogeeks] BIG O

2012-10-31 Thread jai gupta
is O(long n!) n! is O(n^n) by sterling approximation hence it is O(log n^n) = O(nlogn) On Sun, Oct 28, 2012 at 11:14 PM, Pralay Biswas pralaybiswas2...@gmail.comwrote: @ Siddharth : Well, here is how you may understand it: 1) There is an outer loop that runs n times. (k) 2) Then there is an

Re: [algogeeks] AllBinomialCoefficients

2012-03-03 Thread jai gupta
use pascal's triangle -- 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,

Re: [algogeeks] Reading till EOF using cin

2012-02-07 Thread jai gupta
string str; while(cin str) { cout str endl; } -- 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

Re: [algogeeks] MICROSOFT WRITTEN QUESTION-2010

2011-09-13 Thread jai gupta
@bharat: When each step of nishant's algo is O(n) how can it sum up to O(nlogn)??? On Tue, Sep 13, 2011 at 9:18 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @nishant : your algo takes O(nlogn) time with higher constant behind this. can't we write better than this ? @sairam

Re: [algogeeks] Algorithm to find two numbers in an array that sum up to a given number

2011-08-31 Thread jai gupta
With hashing.. make a hash table of elements from 0 to sum/2 if an element k is in sum/2 to sum then check if sum-k is in the hashtable. take care of the case when sum is even and sum/2 occurs only once. TC: O(n) Space complexity: O(sum) Method2: Sort the elements. Now maintain to pointers one at

Re: [algogeeks] maximum XOR

2011-08-26 Thread jai gupta
@Neha take 42, 21 and 1 42 ^ 1 =43 while 42 ^21 =63 On Fri, Aug 26, 2011 at 10:28 PM, Neha Singh neha.ndelhi.1...@gmail.comwrote: Sort the nos., which can be done in O(nlogn) Now the 1st and the last integers are the required integers. -- You received this message because you are

Re: [algogeeks] Re: Square of Large integer

2011-04-28 Thread jai gupta
Hi hary, when do you think that there can be problem? The sq is never made to store a value 10^9 (for previous sq) +9*10^9 (for new sum) hence the sum never exceeds 10^10 which is under the range of int. Correct me if i go wrong somewhere. On Thu, Apr 28, 2011 at 12:26 PM, hary rathor

Re: [algogeeks] ThreeListSum

2011-01-11 Thread jai gupta
sort two of the list and pick one number in C(unsorted) to find if there exists a pair with the sum. This can be done in linear time by maintaining two pointers. Hence O(n^2). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] amazon c questn

2011-01-11 Thread jai gupta
amazom needs 7*4=28 bytes -- 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] Re: probability

2011-01-03 Thread jai gupta
@Dave: Sorry It was a typo but for the probability figures, When C shoots B then if he is successful then A will shoot C Hence he must be unsuccessful and then if B is unsuccessful then A must will Kill B and then C must kill A if B is successful then C must kill B now Hence P(when C shoots at

Re: [algogeeks] puzzle

2011-01-02 Thread jai gupta
@swayambhoo: ofcourse a cubical room must me symmetrical at allcorners, Hence, neway it will reach in min_dis=sqrt((4+3)^2+5^2)=8.6 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Find a specific number in a special matrix.

2011-01-02 Thread jai gupta
For n x m take first element of all the rows and insert in a min heap. Now take the smallest element and and if we have a track of from which row it belongs, we can take an element out of that row and insert in the heap. this will be done n x m times. Hence we have a time complexity of O(nmlog(m))

Re: [algogeeks] Re: arrays

2010-12-28 Thread jai gupta
for each element in the second array apply binary search in first array. ie, For X[1] find 1 in first array with binary search. Time Complexity=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

Re: [algogeeks] Re: difference x

2010-12-22 Thread jai gupta
make another array(B) from (A) with all elements negated now find one element from B and one from A whose sum is x or -x. This can ofcourse be done in 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

Re: [algogeeks] Valid Array

2010-12-09 Thread jai gupta
Algo: In first traverse find the min and the max values. if (max-min) not equals (N-1) return false In next traverse map each in a hashtable of size N where index=key-min. Now in case of collision return false return true -- You received this message because you are subscribed to the Google

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: 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

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] Longest interval with maximum sum

2010-12-05 Thread jai gupta
@fenghuang: the last step will take O(n logn ) . Or there is some better way? -- 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] k nearest points

2010-12-04 Thread jai gupta
will O(n) work or u wish something lesser dependent on k or log(n) ? -- 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: Learn

2010-11-12 Thread jai gupta
result=((n ((128)/3))1)|((n ((129)/3))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 email to algogeeks+unsubscr...@googlegroups.com.