Editing Segment tree

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 21: Line 21:
 
==Structure==
 
==Structure==
 
[[File:Segtree_92631507.png|200px|thumb|right|This segment tree.]]
 
[[File:Segtree_92631507.png|200px|thumb|right|This segment tree.]]
Suppose that we use the function defined above to evaluate <math>f(1,N)</math>, where <math>N</math> is the number of elements in the array. When <math>N</math> is large, this recursive call has two "children", one of which is the recursive call <math>f\left(1,\left\lfloor\frac{N+1}{2}\right\rfloor\right)</math>, and the other one of which is <math>f\left(\left\lfloor\frac{N+1}{2}\right\rfloor+1,N\right)</math>. Each of these children will then have two children of its own, and so on, down until the base case is reached. If we represent these recursive calls with a tree structure, the call <math>f(1,N)</math> would be the root, it would have two children, each child would have two more children, and so on; the base cases would be the leaves of the tree. We are now ready to specify the structure of the segment tree:
+
Suppose that we use the function defined above to evaluate <math>f(1,N)</math>, where <math>N</math> is the number of elements in the array. When <math>N</math> is large, this recursive call has two "children", one of which is the recursive call <math>f\left(1,\lfloor\frac{N+1}{2}\rfloor\right)</math>, and the other one of which is <math>f\left(\lfloor\frac{N+1}{2}\rfloor+1,N\right)</math>. Each of these children will then have two children of its own, and so on, down until the base case is reached. If we represent these recursive calls with a tree structure, the call <math>f(1,N)</math> would be the root, it would have two children, each child would have two more children, and so on; the base cases would be the leaves of the tree. We are now ready to specify the structure of the segment tree:
 
* it is a binary tree which represents some underlying array;
 
* it is a binary tree which represents some underlying array;
 
* each node is associated with some interval of the array and contains the value(s) of one or more functions of the elements in that interval;
 
* each node is associated with some interval of the array and contains the value(s) of one or more functions of the elements in that interval;

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)