And Integers too.... :P On Fri, Mar 4, 2011 at 12:03 AM, nishaanth <[email protected]> wrote:
> @Gunjan....i made a mistake...u r right...but there is one more hidden > assumption that the numbers are positive integers. > > > On Thu, Mar 3, 2011 at 10:57 PM, sukhmeet singh <[email protected]>wrote: > >> he already pointed out that there are no repetations..!! >> >> >> On Thu, Mar 3, 2011 at 9:40 PM, Vipin Agrawal >> <[email protected]>wrote: >> >>> take an example >>> >>> 3 3 3 5 5 5 7 8 >>> >>> I think this would fail >>> >>> On Mar 3, 8:22 pm, Ankit Sinha <[email protected]> wrote: >>> > It is funny but right input is as mentioned earlier to rahul. 0,2,3,8, >>> > 10, 12, 14., 15 :).. Sorry for unnecessarily flooding your mail >>> > accounts. Please ignore previous post >>> > >>> > thanks, >>> > ankit!! >>> > >>> > On Thu, Mar 3, 2011 at 8:15 PM, rajul jain <[email protected]> >>> wrote: >>> > > i think he is wrong bcoz this array in not sorted one. >>> > > so solution of Ankit is right. >>> > >>> > > On Thu, Mar 3, 2011 at 7:33 PM, nishaanth <[email protected]> >>> wrote: >>> > >>> > >> Ignore the previous post..there is a small error in the code.. >>> > >> @Ankit..your algm is O(n)...you should split the problem size to n/2 >>> at >>> > >> every stage...rather you are again computing both the subarrays.. >>> > >> Here is the correct code... >>> > >> int BsearchElemEqualIndex (int *a, int start, int end) >>> > >> { >>> > >> int mid = (((end - start) >> 1) + start); >>> > >> if (a[mid] == mid) >>> > >> return a[mid]; >>> > >> else if (a[mid] != mid) >>> > >> { >>> > >> if (mid == start || mid == end) >>> > >> { >>> > >> return -1; >>> > >> } >>> > >> else >>> > >> { >>> > >> if(a[mid] < mid ) >>> > >> BsearchElemEqualIndex (a, start, mid); >>> > >> else >>> > >> BsearchElemEqualIndex (a, mid + 1, end); >>> > >> } >>> > >> } >>> > >> } >>> > >>> > >> int _tmain(int argc, _TCHAR* argv[]) >>> > >> { >>> > >> int a[SIZE] = {5,9,3,8,1,2,6,7}; >>> > >> int x = BsearchElemEqualIndex (a, 0, SIZE); >>> > >> printf ("%d", x); >>> > >> system ("PAUSE"); >>> > >> return 0; >>> > >> } >>> > >> S.Nishaanth, >>> > >> Computer Science and engineering, >>> > >> IIT Madras. >>> > >>> > >> -- >>> > >> You received this message because you are subscribed to the Google >>> Groups >>> > >> "Algorithm Geeks" group. >>> > >> To post to this group, send email to [email protected]. >>> > >> To unsubscribe from this group, send email to >>> > >> [email protected]. >>> > >> 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 [email protected]. >>> > > To unsubscribe from this group, send email to >>> > > [email protected]. >>> > > 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 [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > S.Nishaanth, > Computer Science and engineering, > IIT Madras. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Gunjan Sharma Chairman IEEE Students Chapter IIT Roorkee B.Tech IV year CSE Contact No- +91 9997767077 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
