For each row we wont be traversing all elements from right to left, the
total number of comparisons we make for all rows will be equal to n or worst
case 2n. So it will be O(m+n)

On Sat, Aug 20, 2011 at 3:34 PM, Sanjay Rajpal <srn...@gmail.com> wrote:

> Got it in the worst case also it will be O(m+n)
> Worst case will be
> 00000001
> 00000011
> 00000111
> 00001111
> 00011111
> 00111111
> 01111111
> 11111111
>
> at each step just make one comparison and one step towards left, which in
> worst case is
> m comparisons and n increments, so final solution is O(m+n).
>
> Correct me if I am wrong.
> Sanju
> :)
>
>
>
> On Sat, Aug 20, 2011 at 3:00 AM, Shashank Gupta 
> <s.sha2nkgu...@gmail.com>wrote:
>
>> In worst case it would be O(m*n)..
>>
>>
>>
>> On Sat, Aug 20, 2011 at 3:27 PM, shady <sinv...@gmail.com> wrote:
>>
>>> @Sanjay awesome solution
>>> it won't be O(n^2) in worst case, it will be O(m+n) only
>>>
>>> On Sat, Aug 20, 2011 at 3:22 PM, Sanjay Rajpal <srn...@gmail.com> wrote:
>>>
>>>>  Yes, thats right.
>>>> I think we can do the following also :
>>>>
>>>> Lets us assume rows are sorted in increasing order.
>>>>
>>>> start from first row say i. Traverse the array from the end of the row
>>>> towards the beginning till 0 occurs say at position j.
>>>> now proceed to the next row i+1, check the value at i+1,j  if it is 0,
>>>> go to next row i+2,j
>>>> else if its 1, then go to left till 0 occurs and store that index of 0
>>>> and follow to the next row.
>>>>
>>>> In the worst case, it will be O(n^2), but in general its a good approach
>>>> i guess. what do u say guys ?
>>>>
>>>> Average Case O(m+n) ?
>>>>
>>>>
>>>> Sanju
>>>> :)
>>>>
>>>>
>>>>
>>>> On Sat, Aug 20, 2011 at 2:47 AM, shady <sinv...@gmail.com> wrote:
>>>>
>>>>> binary search on every row which will give solution in O(m*(logn))
>>>>>
>>>>>  On Sat, Aug 20, 2011 at 3:13 PM, Sanjay Rajpal <srn...@gmail.com>wrote:
>>>>>
>>>>>>  Sorry I forgot to mention that.
>>>>>>
>>>>>> Sanju
>>>>>> :)
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> -----------------------------------------
>> $hashank Gupta
>> -----------------------------------------
>> Let not a man guard his dignity, but let his dignity guard him.
>>
>>
>> --
>> 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.

Reply via email to