Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve asymptotic performance of binary treemap #44
The current algorithm for computing partitions in a binary treemap performs a lot of redundant prefix sums and therefore has sub-optimal asymptotic performance.
In the worst-case, where each call to
The asymptotic performance can be improved by pre-computing the prefix sums of all the children and performing a binary search at each call to
Here are some results of a benchmark that measures execution times for 1,000 iterations of three trees with 1,000 children on my machine (Macbook Pro with Node v5.3.0).
There is of course some overhead for creating the prefix sum array, but the performance is consistent across different value distributions. In particular, the worst-case has improved by almost 20X, while the best-case has degraded by less than 25%.
The fix currently uses an inline implementation of binary search, but Lines 22-30 can be replaced with the following if