The Douglas-Peucker line simplification algorithm has a worst-case time complexity of O(n²). However, for a line to actually trigger this worst-case, two things have to go "wrong" at once:
- the threshold must be set so low that most vertices are kept
- in each recursion step, the vertex with the largest deviation from the line between the current endpoints must be close (in terms of its index on the line, not in terms of its euclidean position) to one of the endpoints. (If instead the index of the vertex with the largest deviation from the line was close enough to the middle between the current endpoints, the algorithm should cause a recursive binary subdivision of depth
log(n)
, resulting in an overall time complexity ofO(n log(n))
.)
While the first criterion is easy to trigger (just set the tolerance threshold to 0.0), I have not yet found a line that fulfils the second criterion.
So is there a simple example line that results in the worst-case behavior (preferably one that triggers the obvious worst-case where the point with the highest deviation in each recursion step is directly connected to one of the line's endpoints; but any other example is fine as well)?