Labeling all layers in Linearithmic O(n log n) time

Let's first look at the structure of any layer.