Re: [algogeeks] Re: Median of two arrays..
Check this code int med1,med2; void func(int a[], int x1, int x2, int b[], int y1, int y2){ int midx,midy; if((y2-y1+1)==2) { med1=max(a[x1],b[y1]); med2=min(a[x2],b[y2]); return; } midx=(x1+x2)/2; midy=(y1+y2)/2; if(a[midx]>b[midy]){ x2=x2-(midy-y1); y1=midy; }else{y2=y2-(midx-x1); x1=midx; } func(a,x1,x2,b,y1,y2); } med1 and med2 are two medians. On Fri, Aug 13, 2010 at 6:32 PM, Raj N wrote: > Can someone tell me what do you mean by median of 2 arrays ? Is it that the > sorted arrays are merged and finding the median of resulting one? > > On Fri, Aug 13, 2010 at 1:32 AM, sachin wrote: > >> If the ranges of the arrays are 1..n & 1..m, then we can solve it this >> way >> >> if ((m+n)&1){ >> we can go with the method same as rahul patil's and in the condition >> we can use count<=(m+n)/2+1, the median will be stored in res. >> } >> else{ >> we can go with the method same as rahul patil's and in the condition >> we can use count<=(m+n)/2+1 and the median in this case will be the >> average of elements at count (m+n)/2 & at count (m+n)/2+1.So, we will >> have to store the last element in this case. >> } >> >> On Aug 11, 5:25 pm, rahul patil wrote: >> > is there any time complexity? >> > >> > the also can be like this >> > >> > char *res; >> > char *ptr1 =arr1; >> > char *ptr2 =arr2; >> > int count =0, n= len(arr1) ,m=len(arr2); >> > while(1){ >> > while(*ptr1 > *ptr2){ >> > ptr2++; >> > count ++; >> > if( count == (n+m)/2 ){ >> >res=ptr1; >> >break out of outer while loop; >> > } >> > } >> > >> > while(*ptr1 < *ptr2){ >> > ptr1++; >> > count ++; >> > if( count == (n+m)/2 ){ >> >res=ptr2; >> >break out of outer while loop; >> > } >> > } >> > >> > } >> > >> > On Aug 6, 7:20 pm, Manjunath Manohar wrote: >> > >> > > will this work in two sorted arrays of equal length.. >> >> -- >> 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, 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 algoge...@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. > -- Thanks & Regards Nikhil Agarwal Senior Undergraduate Computer Science & Engineering, National Institute Of Technology, Durgapur,India http://tech-nikk.blogspot.com http://beta.freshersworld.com/communities/nitd -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] System.out.println(2.0-1.10)
On Friday 13 August 2010 16:40:41 navin wrote: > this statement System.out.println(2.0-1.10); > produces 0.8999 > can anyone explain. > Mathematically result has to be 0.9 but it gives 0.8999 > why? > Thanks. A classic floating point problem. A quick search in Google gave me this: http://blogs.msdn.com/b/excel/archive/2008/04/10/understanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers.aspx -- Mihai Donțu -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Generate all bit strings of length n
consider a link list l which can contain nodes representing the bits GenerateBitStrings(int length) { if (length == 0) { //print all values in link list l } Add 1 to l call GenerateBitString(length-1) Remove the 1 that was added. Add 0 to l call GenerateBitString(length-1) Remove the 0 that was added. return; } call this function GenerateBitString(length) passing n as length. On Aug 12, 1:30 pm, Raj N wrote: > Hi, > Can someone gimme the code to generate all possible bit strings of > length n recursively ? -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Copy Constructor
This has already been discussed a lot many times. Please check older posts !! On Thu, Aug 12, 2010 at 3:44 AM, amit wrote: > why copy constructor must pass by reference? > > -- > 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, 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 algoge...@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: Median of two arrays..
Can someone tell me what do you mean by median of 2 arrays ? Is it that the sorted arrays are merged and finding the median of resulting one? On Fri, Aug 13, 2010 at 1:32 AM, sachin wrote: > If the ranges of the arrays are 1..n & 1..m, then we can solve it this > way > > if ((m+n)&1){ > we can go with the method same as rahul patil's and in the condition > we can use count<=(m+n)/2+1, the median will be stored in res. > } > else{ > we can go with the method same as rahul patil's and in the condition > we can use count<=(m+n)/2+1 and the median in this case will be the > average of elements at count (m+n)/2 & at count (m+n)/2+1.So, we will > have to store the last element in this case. > } > > On Aug 11, 5:25 pm, rahul patil wrote: > > is there any time complexity? > > > > the also can be like this > > > > char *res; > > char *ptr1 =arr1; > > char *ptr2 =arr2; > > int count =0, n= len(arr1) ,m=len(arr2); > > while(1){ > > while(*ptr1 > *ptr2){ > > ptr2++; > > count ++; > > if( count == (n+m)/2 ){ > >res=ptr1; > >break out of outer while loop; > > } > > } > > > > while(*ptr1 < *ptr2){ > > ptr1++; > > count ++; > > if( count == (n+m)/2 ){ > >res=ptr2; > >break out of outer while loop; > > } > > } > > > > } > > > > On Aug 6, 7:20 pm, Manjunath Manohar wrote: > > > > > will this work in two sorted arrays of equal length.. > > -- > 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, 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 algoge...@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] Generate all bit strings of length n
Start with number 1. It will have a binary representation of 00...1 (Total of n-bits) Keeping adding 1 to it until you reach a number with all 1's in its binary representation. On Thu, Aug 12, 2010 at 2:00 PM, Raj N wrote: > Hi, > Can someone gimme the code to generate all possible bit strings of > length n recursively ? > > -- > 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, 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 algoge...@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] System.out.println(2.0-1.10)
this statement System.out.println(2.0-1.10); produces 0.8999 can anyone explain. Mathematically result has to be 0.9 but it gives 0.8999 why? Thanks. -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: codechef problem
first k digits (unsigned long) floor (pow(10.0,modf(n*log((double)n),&dummy)+k-1) log is on d base 10 last k digits int func(int n,int k){ int m=1; for(;k>0;k--) m*=10; r=1; t=n%m; while(n){ if(n%2) r=r * t%m; t=t * t%m; n>>=1; } return r; } -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Line Seprating the points
Pick a random point (x0,y0) in the plane that is not equal to any of the given points (x_i,y_i). For each i, calculate the slope m_i of the line that passes through (x0,y0) and (x_i,y_i). Find the median M of the slopes. If there are two or more slopes equal to M, start over with a new random (x0,y0). The line through (x0,y0) with slope M separates the given points in the desired way. Dave On Aug 12, 6:12 am, amit wrote: > Within a 2D space, there is a batch of points(no duplicate) in the > region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide > the region to 2 parts with half points in each .the input will be an > array of points and the length of the array. > struct point{ > int x; > int y; > > > > };- Hide quoted text - > > - Show quoted text - -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Median of two arrays..
If the ranges of the arrays are 1..n & 1..m, then we can solve it this way if ((m+n)&1){ we can go with the method same as rahul patil's and in the condition we can use count<=(m+n)/2+1, the median will be stored in res. } else{ we can go with the method same as rahul patil's and in the condition we can use count<=(m+n)/2+1 and the median in this case will be the average of elements at count (m+n)/2 & at count (m+n)/2+1.So, we will have to store the last element in this case. } On Aug 11, 5:25 pm, rahul patil wrote: > is there any time complexity? > > the also can be like this > > char *res; > char *ptr1 =arr1; > char *ptr2 =arr2; > int count =0, n= len(arr1) ,m=len(arr2); > while(1){ > while(*ptr1 > *ptr2){ > ptr2++; > count ++; > if( count == (n+m)/2 ){ > res=ptr1; > break out of outer while loop; > } > } > > while(*ptr1 < *ptr2){ > ptr1++; > count ++; > if( count == (n+m)/2 ){ > res=ptr2; > break out of outer while loop; > } > } > > } > > On Aug 6, 7:20 pm, Manjunath Manohar wrote: > > > will this work in two sorted arrays of equal length.. -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Generate all bit strings of length n
Hi, Can someone gimme the code to generate all possible bit strings of length n recursively ? -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Line Seprating the points
Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide the region to 2 parts with half points in each .the input will be an array of points and the length of the array. struct point{ int x; int y; }; -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Dynamic Programming Problem on Strings
what about printing these strings onto terminal. can printing of the string is also similar. I tried to develop the algo but got messed up.can some one help? On Aug 8, 2:53 am, Amir hossein Shahriari wrote: > @ankur: dp[i][j] number of (prefix) strings that have i As and j Bs is: > dp[i-1][j] number of (prefix) strings that have i-1 As and j Bs appended by > "A" > + > dp[i][j-1] number of (prefix) strings that have i As and j-1 Bs appended by > "B" > > @ashish: wikipedia has some nice proofs for catalan number formula: > en.wikipedia.org/wiki/Catalan_number -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Copy Constructor
why copy constructor must pass by reference? -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: New Generation Lossless Data Representations
On Aug 11, 6:30 am, LawCounsels wrote: > Warm Greetings : here is link to download a 'mathematics structure' encoding of a complete random 4,074 bits long file (a random chosen part of Mark Nelson's AMillionRandomDigits.bin challenge) www dot box dot net/shared/eyy2v28dbf download link's new discovered 'mathematics structure' endoded file's details . in a file with N bits (sufficient large like 8Kbits onwards to 1Mbits) , assume the distributions of unique prefix '0's or '10' or '110' or '1110' ... or '111...10' (always ends with a '0') is standard binomial power (ie random) , BUT with added constraints/ restriction that the maximum length of '11110' at any time could only be at most log(base2)[R] where R is the total # of bits from present bit position to the end Least Significant Bit position [ eg if bits_string is 0 10 0 10 0 10 110 10 0 10 0 10 0 0 ' then here 110 is the 13th bits , there can be no unique prefix of total# of bits length > log(base2)[R] at any time, where R is the bit position # of the unique prefix counting from end Least Significant position bit ] so this is not simple regular usual normal binomial power series/ random distributions [ usual normal binomial power series/ random distributions is 'god gifted' not to be compressible] , but here there is added constraint/ restriction that eg '1110' ( of length 4 bits long) could not occur at position R = 15 or smaller (since log(base2) [R=15 or smaller value of R] will not allow unique prefix of total# of bits >= 4 to occur at position R < 16 .. THIS IS IMMEDIATE APPARENT READY COMPRESSIBLE 4,073 bits 'constraint' 'mathematics structures' encoded (1 bit smaller) file , from input random 4,074 bits 'random' file -- 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, visit this group at http://groups.google.com/group/algogeeks?hl=en.