Main Page: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(269 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
{{One source|date=November 2007}}
This is a preview for the new '''MathML rendering mode''' (with SVG fallback), which is availble in production for registered users.


In [[computer science]], a '''segment tree''' is a [[Tree (data structure)|tree]] [[data structure]] for storing [[Interval (mathematics)|intervals]], or segments. It allows querying which of the stored segments contain a given point. It is, in principle, a static structure; that is, its content cannot be modified once the structure is built.  A similar data structure is the [[interval tree]].
If you would like use the '''MathML''' rendering mode, you need a wikipedia user account that can be registered here [[https://en.wikipedia.org/wiki/Special:UserLogin/signup]]
* Only registered users will be able to execute this rendering mode.
* Note: you need not enter a email address (nor any other private information). Please do not use a password that you use elsewhere.


A segment tree for a set ''I'' of ''n'' intervals uses [[Big O notation|O]](''n'' log ''n'') storage and can be built in O(''n'' log ''n'') time. Segment trees support searching for all the intervals that contain a query point in O(log ''n'' + ''k''), ''k'' being the number of retrieved intervals or segments.<ref name="Schwarzkopf1">{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|p=227}}</ref>
Registered users will be able to choose between the following three rendering modes:


Applications of the segment tree are in the areas of [[computational geometry]], and [[geographic information systems]].
'''MathML'''
:<math forcemathmode="mathml">E=mc^2</math>


The segment tree can be generalized to higher [[dimension]] spaces as well.
<!--'''PNG'''  (currently default in production)
:<math forcemathmode="png">E=mc^2</math>


==Structure description==
'''source'''
''This section describes the structure of a segment tree in a one-dimensional space.''
:<math forcemathmode="source">E=mc^2</math> -->


Let ''S'' be a set of intervals, or segments. Let ''p''<sub>1</sub>, ''p''<sub>2</sub>, ..., ''p<sub>m</sub>'' be the list of distinct interval endpoints, sorted from left to right. Consider the partitioning of the real line induced by those points. The regions of this partitioning are called ''elementary intervals''. Thus, the elementary intervals are, from left to right:
<span style="color: red">Follow this [https://en.wikipedia.org/wiki/Special:Preferences#mw-prefsection-rendering link] to change your Math rendering settings.</span> You can also add a [https://en.wikipedia.org/wiki/Special:Preferences#mw-prefsection-rendering-skin Custom CSS] to force the MathML/SVG rendering or select different font families. See [https://www.mediawiki.org/wiki/Extension:Math#CSS_for_the_MathML_with_SVG_fallback_mode these examples].


:<math>(-\infty, p_1), [p_1,p_1], (p_1, p_2), [p_2, p_2], ..., (p_{m-1}, p_m), [p_m, p_m], (p_m, +\infty)</math>
==Demos==


That is, the list of elementary intervals consists of open intervals between two consecutive endpoints ''p<sub>i</sub>'' and ''p''<sub>''i''+1</sub>, alternated with closed intervals consisting of a single endpoint. Single points are treated themselves as intervals because the answer to a query is not necessarily the same at the interior of an elementary interval and its endpoints.<ref>{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|p=224}}</ref>
Here are some [https://commons.wikimedia.org/w/index.php?title=Special:ListFiles/Frederic.wang demos]:


[[Image:Segment tree instance.gif|frame|Graphic example of the structure of the segment tree. This instance is built for the segments shown at the bottom.]]


Given a set ''I'' of intervals, or segments, a segment tree ''T'' for ''I'' is structured as follows:
* accessibility:
* ''T'' is a [[binary tree]].
** Safari + VoiceOver: [https://commons.wikimedia.org/wiki/File:VoiceOver-Mac-Safari.ogv video only], [[File:Voiceover-mathml-example-1.wav|thumb|Voiceover-mathml-example-1]], [[File:Voiceover-mathml-example-2.wav|thumb|Voiceover-mathml-example-2]], [[File:Voiceover-mathml-example-3.wav|thumb|Voiceover-mathml-example-3]], [[File:Voiceover-mathml-example-4.wav|thumb|Voiceover-mathml-example-4]], [[File:Voiceover-mathml-example-5.wav|thumb|Voiceover-mathml-example-5]], [[File:Voiceover-mathml-example-6.wav|thumb|Voiceover-mathml-example-6]], [[File:Voiceover-mathml-example-7.wav|thumb|Voiceover-mathml-example-7]]
* Its [[Leaf node|leaves]] correspond to the elementary intervals induced by the endpoints in ''I'', in an ordered way: the leftmost leaf corresponds to the leftmost interval, and so on. The elementary interval corresponding to a leaf ''v'' is denoted Int(''v'').
** [https://commons.wikimedia.org/wiki/File:MathPlayer-Audio-Windows7-InternetExplorer.ogg Internet Explorer + MathPlayer (audio)]
* The [[internal node]]s of ''T''  correspond to intervals that are the [[Union (set theory)|union]] of elementary intervals: the interval Int(''N'') corresponding to node ''N'' is the union of the intervals corresponding to the leaves of the tree rooted at ''N''. That implies that Int(''N'') is the union of the intervals of its two children.
** [https://commons.wikimedia.org/wiki/File:MathPlayer-SynchronizedHighlighting-WIndows7-InternetExplorer.png Internet Explorer + MathPlayer (synchronized highlighting)]
* Each node or leaf ''v'' in ''T'' stores the interval Int(''v'') and a set  of intervals, in some data structure. This canonical subset of node ''v'' contains the intervals [''x'', ''x&prime;''] from ''I'' such that [''x'', ''x&prime;''] contains Int(''v'') and does not contain Int(parent(''v'')). That is, each segment in ''I'' stores the segments that span through its interval, but do not span through the interval of its parent.<ref>{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|pp=225&ndash;226}}</ref>
** [https://commons.wikimedia.org/wiki/File:MathPlayer-Braille-Windows7-InternetExplorer.png Internet Explorer + MathPlayer (braille)]
** NVDA+MathPlayer: [[File:Nvda-mathml-example-1.wav|thumb|Nvda-mathml-example-1]], [[File:Nvda-mathml-example-2.wav|thumb|Nvda-mathml-example-2]], [[File:Nvda-mathml-example-3.wav|thumb|Nvda-mathml-example-3]], [[File:Nvda-mathml-example-4.wav|thumb|Nvda-mathml-example-4]], [[File:Nvda-mathml-example-5.wav|thumb|Nvda-mathml-example-5]], [[File:Nvda-mathml-example-6.wav|thumb|Nvda-mathml-example-6]], [[File:Nvda-mathml-example-7.wav|thumb|Nvda-mathml-example-7]].
** Orca: There is ongoing work, but no support at all at the moment [[File:Orca-mathml-example-1.wav|thumb|Orca-mathml-example-1]], [[File:Orca-mathml-example-2.wav|thumb|Orca-mathml-example-2]], [[File:Orca-mathml-example-3.wav|thumb|Orca-mathml-example-3]], [[File:Orca-mathml-example-4.wav|thumb|Orca-mathml-example-4]], [[File:Orca-mathml-example-5.wav|thumb|Orca-mathml-example-5]], [[File:Orca-mathml-example-6.wav|thumb|Orca-mathml-example-6]], [[File:Orca-mathml-example-7.wav|thumb|Orca-mathml-example-7]].
** From our testing, ChromeVox and JAWS are not able to read the formulas generated by the MathML mode.


==Storage requirements==
==Test pages ==
''This section analyzes the storage cost of a segment tree in a one-dimensional space.''


A segment tree ''T'' on a set ''I'' of ''n'' intervals uses O(''n''log''n'') storage.
To test the '''MathML''', '''PNG''', and '''source''' rendering modes, please go to one of the following test pages:
*[[Displaystyle]]
*[[MathAxisAlignment]]
*[[Styling]]
*[[Linebreaking]]
*[[Unique Ids]]
*[[Help:Formula]]


:''Proof:''
*[[Inputtypes|Inputtypes (private Wikis only)]]
 
*[[Url2Image|Url2Image (private Wikis only)]]
:''Lemma'': Any interval [''x'', ''x&prime;''] of ''I'' is stored in the canonical set for at most two nodes at the same depth.
==Bug reporting==
 
If you find any bugs, please report them at [https://bugzilla.wikimedia.org/enter_bug.cgi?product=MediaWiki%20extensions&component=Math&version=master&short_desc=Math-preview%20rendering%20problem Bugzilla], or write an email to math_bugs (at) ckurs (dot) de .
::''Proof'': Let ''v''<sub>1</sub>, ''v''<sub>2</sub>, ''v''<sub>3</sub> be the three nodes at the same depth, numbered from left to right; and let p(''v'') be the parent node of any given node ''v''. Suppose [''x'', ''x&prime;''] is stored at ''v''<sub>1</sub> and ''v''<sub>3</sub>. This means that [''x'', ''x&prime;''] spans the whole interval from the left endpoint of Int(''v''<sub>1</sub>) to the right endpoint of Int(''v''<sub>3</sub>). Note that all segments at a particular level are non-overlapping and ordered from left to right: this is true by construction for the level containing the leaves, and the property is not lost when moving from any level to the one above it by combining pairs of adjacent segments. Now either p(''v''<sub>2</sub>) = p(''v''<sub>1</sub>), or the former is to the right of the latter (edges in the tree do not cross). In the first case, Int(p(''v''<sub>2</sub>))'s leftmost point is the same as Int(''v''<sub>1</sub>)'s leftmost point; in the second case, Int(p(''v''<sub>2</sub>))'s leftmost point is to the right of Int(p(''v''<sub>1</sub>))'s rightmost point, and therefore also to the right of Int(''v''<sub>1</sub>)'s rightmost point. In both cases, Int(p(''v''<sub>2</sub>)) begins at or to the right of Int(''v''<sub>1</sub>)'s leftmost point. Similar reasoning shows that Int(p(''v''<sub>2</sub>)) ends at or to the left of Int(''v''<sub>3</sub>)'s rightmost point. Int(p(''v''<sub>2</sub>)) must therefore be contained in [''x'', ''x&prime;'']; hence, [''x'', ''x&prime;''] will not be stored at ''v''<sub>2</sub>.
 
:The set ''I'' has at most 4''n'' + 1 elementary intervals. Because ''T'' is a binary balanced tree with at most 4''n'' + 1 leaves, its height is O(log''n''). Since any interval is stored at most twice at a given depth of the tree, that the total amount of storage is O(''n''log''n'').<ref name="Schwarzkopf2">{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|p=226}}</ref>
 
==Construction==
''This section describes the construction of a segment tree in a one-dimensional space.''
 
A segment tree from the set of segments ''I'', can be built as follows. First, the endpoints of the intervals in ''I'' are sorted. The elementary intervals are obtained from that. Then, a balanced binary tree is built on the elementary intervals, and for each node ''v'' it is determined the interval Int(''v'') it represents. It remains to compute the canonical subsets for the nodes. To achieve this, the intervals in ''I'' are inserted one by one into the segment tree. An interval ''X'' = [''x'', ''x&prime;''] can be inserted in a subtree rooted at ''T'', using the following procedure:<ref>{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|pp=226&ndash;227}}</ref>
* If Int(''T'') is contained in ''X'' then store ''X'' at ''T'', and finish.
* Else:
* If ''X'' intersects the canonical subset of the left child of ''T'', then insert ''X'' in that child, recursively.
* If ''X'' intersects the canonical subset of the right child of ''T'', then insert ''X'' in that child, recursively.
The complete construction operation takes O(''n''log''n'') time, ''n'' being the number of segments in ''I''.
:''Proof''
 
:Sorting the endpoints takes O(''n''log''n''). Building a balanced binary tree from the sorted endpoints, takes linear time on ''n''.
:The insertion of an interval ''X'' = [''x'', ''x&prime;''] into the tree, costs O(log''n'').
::''Proof:'' Visiting every node takes constant time (assuming that canonical subsets are stored in a simple data structure like a [[linked list]]). When we visit node ''v'', we either store ''X'' at ''v'', or Int(''v'') contains an endpoint of ''X''. As proved above, an interval is stored at most twice at each level of the tree. There is also at most one node at every level whose corresponding interval contains ''x'', and one node whose interval contains ''x&prime;''. So, at most four nodes per level are visited. Since there are O(log''n'') levels, the total cost of the insertion is ''O(''log''n'').<ref name="Schwarzkopf1"/>
 
==Query==
''This section describes the query operation of a segment tree in a one-dimensional space.''
 
A query for a segment tree, receives a point ''q<sub>x</sub>'', and retrieves a list of all the segments stored which contain the point ''q<sub>x</sub>''.
 
Formally stated; given a node (subtree) ''v'' and a query point ''q<sub>x</sub>'', the query can be done using the following algorithm:
* Report all the intervals in I(''v'').
* If ''v'' is not a leaf:
** If ''q<sub>x</sub>'' is in Int(left child of ''v'') then
*** Perform a query in the left child of ''v''.
** If ''q<sub>x</sub>'' is in Int(right child of ''v'') then
*** Perform a query in the right child of ''v''.
 
In a segment tree that contains ''n'' intervals, those containing a given query point can be reported in O(log''n'' + ''k'') time, where ''k'' is the number of reported intervals.
:''Proof:'' The query algorithm visits one node per level of the tree, so O(log''n'') nodes in total. In the other hand, at a node ''v'', the segments in ''I'' are reported in O(1 + ''k<sub>v</sub>'') time, where ''k<sub>v</sub>'' is the number of intervals at node ''v'', reported. The sum of all the ''k<sub>v</sub>'' for all nodes ''v'' visited, is ''k'', the number of reported segments.<ref name="Schwarzkopf2"/>
 
==Generalization for higher dimensions==
The segment tree can be generalized to higher dimension spaces, in the form of multi-level segment trees. In higher dimension versions, the segment tree stores a collection of axis-parallel (hyper-)rectangles, and can retrieve the rectangles that contain a given query point. The structure uses O(''n''log<sup>''d''</sup>''n'') storage, and answers queries in O(log''<sup>d</sup>''n'').
 
The use of [[fractional cascading]] lowers the query time bound by a logarithmic factor. The use of the [[interval tree]] on the deepest level of associated structures lowers the storage bound with a logarithmic factor.<ref name="Schwarzkopf3">{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|p=230}}</ref>
 
==Notes==
The query that asks for all the intervals containing a given point, is often referred as ''stabbing query''.<ref name="Schwarzkopf4" />
 
The segment tree is less efficient than the interval tree for range queries in one dimension, due to its higher storage requirement: O(''n''log''n'') against the O(''n'') of the interval tree. The importance of the segment tree is that the segments within each node’s canonical subset can be stored in any arbitrary manner.<ref name="Schwarzkopf4">{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|p=229}}</ref>
 
For ''n'' intervals whose endpoints are in a small integer range (e.g., in the range [1,...,O(''n'')]), optimal data structures{{which|date=February 2014}} exist with a linear preprocessing time and query time O(1+''k'') for reporting all ''k'' intervals containing a given query point.
 
Another advantage of the segment tree is that it can easily be adapted to counting queries; that is, to report the number of segments containing a given point, instead of reporting the segments themselves. Instead of storing the intervals in the canonical subsets, it can simply store the number of them. Such a segment tree uses linear storage, and requires an O(log ''n'') query time, so it is optimal.<ref>{{Harv |de Berg, van Kreveld, Overmars, Schwarzkopf|2000|pp=229&ndash;230}}</ref>
 
A version for higher dimensions of the interval tree and the [[priority search tree]] does not exist, that is, there is no clear extension of these structures that solves the analogous problem in higher dimensions. But the structures can be used as associated structure of segment trees.<ref name="Schwarzkopf3"/>
 
==History==
{{Expand section|date=November 2007}}
The segment tree was discovered by J. L. Bentley in 1977; in "Solutions to Klee’s rectangle problems".<ref name="Schwarzkopf4"/>
 
==References==
{{reflist}}
----
{{cite book
| last1=de Berg
| first1=Mark
| last2=van Kreveld
| first2=Marc
| last3=Overmars
| first3=Mark
| last4=Schwarzkopf
| first4=Otfried
| publication-date=2000
| year=2000
| title=Computational Geometry: algorithms and applications
| edition=2nd
| publisher=Springer-Verlag Berlin Heidelberg New York
| isbn=3-540-65620-0
| chapter = More Geometric Data Structures
| doi = 10.1007.2F978-3-540-77974-2 10
}}
 
http://www.cs.nthu.edu.tw/~wkhon/ds/ds10/tutorial/tutorial6.pdf
 
{{CS-Trees}}
 
{{DEFAULTSORT:Segment Tree}}
[[Category:Trees (data structures)]]
[[Category:Binary trees]]
[[Category:Computer graphics data structures]]

Latest revision as of 22:52, 15 September 2019

This is a preview for the new MathML rendering mode (with SVG fallback), which is availble in production for registered users.

If you would like use the MathML rendering mode, you need a wikipedia user account that can be registered here [[1]]

  • Only registered users will be able to execute this rendering mode.
  • Note: you need not enter a email address (nor any other private information). Please do not use a password that you use elsewhere.

Registered users will be able to choose between the following three rendering modes:

MathML

E=mc2


Follow this link to change your Math rendering settings. You can also add a Custom CSS to force the MathML/SVG rendering or select different font families. See these examples.

Demos

Here are some demos:


Test pages

To test the MathML, PNG, and source rendering modes, please go to one of the following test pages:

Bug reporting

If you find any bugs, please report them at Bugzilla, or write an email to math_bugs (at) ckurs (dot) de .