What you are suggesting will lead to the worst case of o(n) in cases like
{1,1,1,1,1,1,1} searching for number of occurences of 1.
On Sun, Jun 19, 2011 at 12:47 PM, kumar vr <[email protected]> wrote:

> Doing binary search for index of first and last occurrences? I guess it is
> complex.
>
> My suggestion is: Do a binary search to find x, once the location of x is
> found say at i.
> Do a check at  ... i-2, i-1,i+1,i+2 .. until those values are equal to x.
>
>
>
> On Sun, Jun 19, 2011 at 12:11 PM, Harshal <[email protected]> wrote:
>
>> :D
>>
>>
>> On Sun, Jun 19, 2011 at 12:09 PM, aanchal goyal <[email protected]
>> > wrote:
>>
>>> oops!! I am feeling like banging my head on wall now :( . thanks nyways!
>>>
>>>
>>> On Sun, Jun 19, 2011 at 12:07 PM, Harshal <[email protected]> wrote:
>>>
>>>> its simple. binary search for index of first and last occurence and
>>>> return its difference
>>>>
>>>>
>>>> On Sun, Jun 19, 2011 at 12:04 PM, aanchal goyal <
>>>> [email protected]> wrote:
>>>>
>>>>> given a sorted array, how to find number of occurences of a number x in
>>>>> it in O(logn)?
>>>>>
>>>>> --
>>>>> Regards,*
>>>>> Aanchal Goyal*.
>>>>>
>>>>>  --
>>>>> 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Harshal Choudhary,
>>>> Final Year B.Tech CSE,
>>>> NIT Surathkal, Karnataka, India.
>>>>
>>>>
>>>>
>>>>  --
>>>> 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,*
>>> Aanchal Goyal*.
>>>
>>>  --
>>> 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.
>>>
>>
>>
>>
>> --
>> Harshal Choudhary,
>> Final Year B.Tech CSE,
>> NIT Surathkal, Karnataka, India.
>>
>>
>>  --
>> 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.
>



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

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

Reply via email to