User:Shoseini89/sandbox

hi, this is for test.

Properties of Segment Trees
$$. Its length is $$l_{l,k} = t_{l,k}-s_{l,k}+1$$. Clearly, the root node interval equals to the segment tree range and leaf node interval is one. \bigcup^{k=2^l -1}_{k=0} [s_{l,k},t_{l,k}] = L$$ for all $$l \in [0, \log L]$$.
 * The segment tree representing the range of length $$L$$ has a height $$H = log L + 1.$$
 * Each node on a segment tree represents a node interval $$[s_{l,k}, t_{l,k}], (l \in [0, \ L] \ and \ k \in [0,2^l-1])
 * Each internal node has two children. The left child and the right child represent the intervals $$[s_{l,k}, \lfloor\frac{s_{l,k} +t_{l,k}}{2}\rfloor]$$and $$[\lceil\frac{s_{l,k} +t_{l,k}}{2}\rceil+1,t_{l,k}]$$, respectively. The union of the two children covers the same interval (same as their parent).
 * In order to ensure the continuity of the segment tree, neighboring nodes on the same layer have $$s_{l,k}=t_{l,k-1}+1$$ for any $$k\in[1, 2^l - 1]$$.
 * All the nodes on the same layer span the whole segment tree range. That is, $$

Query for Sum
Summation over range of objects stored in segment tree is important in many application. For example, in computational geometry, one might be interested to find number of transistors on a PCB board bounded by a square box of a given coordinate. A segment tree can facilitate an efficient computation of such summation over a range: GET_SUM(node, left_child, right_child) if the range of the node is within left_child and right_child return value in the node else if the range of the node is completely outside left_child and right_child return 0 else return GET_SUM(node's left child, left_child, right_child) + GET_SUM(node's right child, left_child, right_child)

Distributed Segment Tree (DST)
There are important applications in distributed computing environments that requires range and cover queries which are efficiently handled using distributed segment tree. In peer-to-peer file sharing protocols such as BitTorrent, a file is divided into a large number of slices among peers. Given a slice or a range of slices to download, a user needs to lookup for some other peers who has that slice or range of slices to download from. Note that a slice is typically represented by a range between a starting bit position and an ending bit position. The information regarding the distribution of file slices among peers can be stored in a distributed segment tree (DST) for fast query and peer selection for faster download of a given file.

Similar to prefix hash tree (PHT), a segment tree structure is distributed onto distributed hash table (DHT) by assigning  the node interval $$[s, t]$$ to the DHT node associated with the key $$Hash([s, t])$$. Thus, information about any node of the segment tree can be located via a DHT lookup operation in $$O(1)$$.

Insertion and Removal
Insertion of a key (i.e., a segment) is done by inserting the key to all nodes whose interval covers it. Moreover, every node in the distributed system should be able to reconstruct the segment tree locally by only knowing the range of the segment tree. Therefore, it is possible for $$2 \log L$$ peers concurrently insert a leaf node and update all of its ancestors which achieves an overall $$O(1)$$complexity.

Removing a key from a DST is done in a similar fashion as insertion: the key is removed from the leaf node and all of its ancestors in parallel using the helps of other peers in the network.

Range Query
For querying a range $$[s,t]$$, the user must split the range into a union of minimum node intervals supported by the segment tree. Then, it would uses DHT's get operation to find all the keys maintained on the corresponding DST nodes. Finally, the union of the returned values if the result of the range query. Similar to insertion, range query can be executed in parallel against different participating nodes in the peer-to-peer network.