Editing All nearest smaller values

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 26: Line 26:
  
 
==Applications==
 
==Applications==
A theoretically important application of ANSV is the construction of the [[Cartesian tree]] for a given list of numbers; a node's parent in a Cartesian tree is either its NSV or its NSV in the reversed array (that is, the nearest smaller value on the right rather than on the left), whichever one is larger. (Proof is given in the other article.)
+
A theoretically important application of ASNV is the construction of the [[Cartesian tree]] for a given list of numbers; a node's parent in a Cartesian tree is either its NSV or its NSV in the reversed array (that is, the nearest smaller value on the right rather than on the left), whichever one is larger. (Proof is given in the other article.)
  
 
Running ANSV twice, once on an array and once on its reverse, can be used to find, for each element <math>A_i</math>, the range <math>[j,k]</math> such that <math>A_m \geq A_i</math> for each <math>m \in [j,k]</math>. Geometrically, if the array is taken to represent a histogram in which <math>A_i</math> is the height of the ''i''<sup>th</sup> bar, then this range gives how large a rectangle can be that just touches the top of the ''i''<sup>th</sup> bar while staying contained within the histogram. This can then trivially be used to find the largest rectangle contained entirely within the histogram.
 
Running ANSV twice, once on an array and once on its reverse, can be used to find, for each element <math>A_i</math>, the range <math>[j,k]</math> such that <math>A_m \geq A_i</math> for each <math>m \in [j,k]</math>. Geometrically, if the array is taken to represent a histogram in which <math>A_i</math> is the height of the ''i''<sup>th</sup> bar, then this range gives how large a rectangle can be that just touches the top of the ''i''<sup>th</sup> bar while staying contained within the histogram. This can then trivially be used to find the largest rectangle contained entirely within the histogram.

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)