The Bucketmethod is a method of dividing a row of objects or planes into buckets, each of which maintains its own internal information to achieve the purpose of efficient computation.
where the square partition (sqrtdecomposition) is a row of n elements each square root n points in a bucket to maintain the method of the collectively. Such a segmentation method can reduce the complexity of the operation of the interval to O (square root n).
Like segment trees, square partitioning can support many different operations, depending on the data being maintained. Next, as with the segment tree, we take RMQ as an example to explain the square division.
1. RMQ based on square partition
Given a sequence of a1,a2,..., an, the goal is to achieve two functions within the O (square root N) complexity
* Given s,t, the minimum value of as,as+1,..., at is obtained.
* Given t, X, change the AI value to x.
2. Preprocessing based on square partition RMQ
Make B=floor (square root n), divide the elements in a into a bucket per B, and calculate the minimum value within each bucket.
3. Query of RMQ based on square partition
As shown, the query
* If the bucket is fully contained within the interval, the minimum value of the query bucket
* If the bucket where the element is located is not completely enclosed by a range, check the minimum value individually
Their minimum value is the minimum value of the interval.
4. Updating the value of the RMQ based on the square partition
When updating the value of an element, you need to update the minimum value of the bucket where the element resides. Just walk through the elements in the bucket again.
5. Square segment and line segment tree
Therefore, in the Square division, for any interval, the number of buckets completely contained in it and the number of remaining elements are O (square root n), so can be in O (square root N) time to complete a variety of operations.
In the above example of RMQ, the complexity of the line tree for various operations is O (LOGN), which is faster than the square division. In general, if the segment tree and the square partition can achieve a function, in most cases the segment tree will be faster than the square division. However, because the square partition is simpler to implement than the segment tree, it is also possible to consider using square tessellation if the run time limit is not too tight. In addition, there are some functions that the segment tree is not efficient to maintain but the square partition can do.
Split-bucket method and square Division