i feel binary search idea is the best.... guys i am having problem in finding out complexity...here is my solution to the above problem...whats the complexity...
sort the 2 arrays....a and b l=0,i=0,flag=0; while(a[i]<b[0]) // to start comparing from the value that is slightly greater than the first i++; //element of second array for(i;i<n;i++) { j=l; while(a[i]>=b[j]) { if(a[i]==b[j]) { printf("Common element is %d",a[i]); flag=1 break; } j++; l=j; } if(flag==1) break; } On Sun, Aug 14, 2011 at 6:55 PM, shady <sinv...@gmail.com> wrote: > @sagar suppose numbers are very large( > 10^9) , how will you hash then ? > can you please state the hashing function in this case > > On Sun, Aug 14, 2011 at 6:50 PM, sagar pareek <sagarpar...@gmail.com> wrote: >> >> Hashing >> O(n+m) >> >> On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro <dip10c...@gmail.com> >> wrote: >>> >>> how about binary search of each element from array 1 on array 2? >>> overall complexity : O(nlogn) >>> >>> On 14 August 2011 18:46, mohit verma <mohit89m...@gmail.com> wrote: >>>> >>>> example: >>>> array 1 :: 1 2 3 4 5 6 7 8 9 10 15 >>>> array 2:: 23 34 56 13 "15" 57 432 348 >>>> >>>> On Sun, Aug 14, 2011 at 6:44 PM, shady <sinv...@gmail.com> wrote: >>>>> >>>>> meaning ? what is a common element ? example ??????????????????????? >>>>> >>>>> On Sun, Aug 14, 2011 at 6:37 PM, mohit verma <mohit89m...@gmail.com> >>>>> wrote: >>>>>> >>>>>> given two arrays : with all distinct elements but one element in >>>>>> common. Find the common element in optimal time. >>>>>> >>>>>> -- >>>>>> ........................ >>>>>> MOHIT VERMA >>>>>> >>>>>> -- >>>>>> 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. >>>> >>>> >>>> >>>> -- >>>> ........................ >>>> MOHIT VERMA >>>> >>>> -- >>>> 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. >>> >>> >>> >>> -- >>> >>> ___________________________________________________________________________________________________________ >>> >>> Please do not print this e-mail until urgent requirement. Go Green!! >>> Save Papers <=> Save Trees >>> >>> -- >>> 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. >> >> >> >> -- >> Regards >> SAGAR PAREEK >> COMPUTER SCIENCE AND ENGINEERING >> NIT ALLAHABAD >> >> -- >> 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.