Up: Balancing a rope [Contents][Index]
The balancing algorithm given in Boehm et al (1995) is described as follows. We have an infinite sequence of bins, each labeled with Fibonacci number corresponding to its index. We process the leaves of the rope from left-to-right: A leaf of length ℓ is placed into the bin with index d such that Fib(d) ≤ ℓ < Fib(d+1) if the bin is empty, and if not, all the contents of the bin and the bins with smaller indices are concatenated into a single rope, that is then concatenated with the leaf; finally the resulting rope has a new length ℓ', and the process repeats with this new rope: find the corresponding bin indexed by d' for which Fib(d') ≤ ℓ' < Fib(d' + 1) and so on. At some point this process will stop, and we can move on to the next leaf of the rope. In the end, we concatenate all contents of the bins into a single rope, which will be balanced!
To understand why that is true, we present a few invariant properties that hold in between each iteration of the algorithm described above.
Critically, in order to prove the second point, we need the Fibonacci function to be involved!
Up: Balancing a rope [Contents][Index]