Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    Technically this is O(n^2). On average the inner loop will iterate over half of n each time it is run. So it could be written as O(n*(n/2)), and that can be simplified to O(n^2) Commented Oct 14, 2009 at 11:31
  • Hm, looks like you're right. This is not a simple problem, just to find all the 1 takes O(n), not much room for any further search/comparision with O(logn) complexity. Commented Oct 14, 2009 at 11:55