Title
Unclear complexity for algorithms such as binary search
Status
nad
Section
[alg.binary.search]
Submitter
Nico Josuttis

Created on 1999-10-10.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The complexity is expressed in terms of comparisons, and that complexity can be met even if the number of iterators accessed is linear. Paragraph 1 already says exactly what happens to iterators.

Date: 1999-10-10.00:00:00

The complexity of binary_search() is stated as "At most log(last-first) + 2 comparisons", which seems to say that the algorithm has logarithmic complexity. However, this algorithms is defined for forward iterators. And for forward iterators, the need to step element-by-element results into linear complexity. But such a statement is missing in the standard. The same applies to lower_bound(), upper_bound(), and equal_range(). 

However, strictly speaking the standard contains no bug here. So this might considered to be a clarification or improvement.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1811
1999-10-10 00:00:00admincreate