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 125: Line 125:
 
<p>For certain types of segment trees, ''range updates'' are possible. Consider, for example, a variation in the range minimum query problem in which we can not only update individual elements but also request that every element in a given range be set to the same specified value. This would be known as a ''range update''. ''Lazy propagation'' is a technique that allows range updates to be carried out with the same asymptotic time complexity, <math>\mathcal{O}(\lg N)</math>, as individual updates.</p>
 
<p>For certain types of segment trees, ''range updates'' are possible. Consider, for example, a variation in the range minimum query problem in which we can not only update individual elements but also request that every element in a given range be set to the same specified value. This would be known as a ''range update''. ''Lazy propagation'' is a technique that allows range updates to be carried out with the same asymptotic time complexity, <math>\mathcal{O}(\lg N)</math>, as individual updates.</p>
 
<p>The technique works as follows: each node contains an additional ''lazy'' field, which will be used for temporary storage. When this field is not being used, its value will be set to <math>+\infty</math>. When updating a range, we select the same set of nodes that we would select if querying that range, and update their lazy fields to the desired value (that is, we set them to the new value if the new value is lower), except for leaf nodes, whose values are immediately set to the new value. When a query or update operation requires us to access a proper descendant of any node whose ''lazy'' field is set (''i.e.'' not <math>+\infty</math>), we "push" the lazy field onto the two children: that is, we update the children's lazy fields according to the parent's and reset the parent's to <math>+\infty</math>. If, however, we access the node without accessing any of its proper descendants, and the lazy field is set, we simply use the value of the lazy field as the minimum for that node's associated interval.</p>
 
<p>The technique works as follows: each node contains an additional ''lazy'' field, which will be used for temporary storage. When this field is not being used, its value will be set to <math>+\infty</math>. When updating a range, we select the same set of nodes that we would select if querying that range, and update their lazy fields to the desired value (that is, we set them to the new value if the new value is lower), except for leaf nodes, whose values are immediately set to the new value. When a query or update operation requires us to access a proper descendant of any node whose ''lazy'' field is set (''i.e.'' not <math>+\infty</math>), we "push" the lazy field onto the two children: that is, we update the children's lazy fields according to the parent's and reset the parent's to <math>+\infty</math>. If, however, we access the node without accessing any of its proper descendants, and the lazy field is set, we simply use the value of the lazy field as the minimum for that node's associated interval.</p>
 
[[Category:Data structures]]
 

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)