Ciro Santilli OurBigBook.com $£ Sponsor €¥ 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
This is particularly important in SQL: Nested set model in SQL, as it is an efficient way to transverse trees there, since querrying parents every time would require multiple disk accesses.
The ASCII art visualizations from stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree/194031#194031 are worth reproducing.
As a tree:
  • Root 1
    • Child 1.1
      • Child 1.1.1
      • Child 1.1.2
    • Child 1.2
      • Child 1.2.1
      • Child 1.2.2
As the sets:
 __________________________________________________________________________
|  Root 1                                                                  |
|   ________________________________    ________________________________   |
|  |  Child 1.1                     |  |  Child 1.2                     |  |
|  |   ___________    ___________   |  |   ___________    ___________   |  |
|  |  |  C 1.1.1  |  |  C 1.1.2  |  |  |  |  C 1.2.1  |  |  C 1.2.2  |  |  |
1  2  3___________4  5___________6  7  8  9___________10 11__________12 13 14
|  |________________________________|  |________________________________|  |
|__________________________________________________________________________|
Consider the following nested set:
0, 8, root
  1, 7, mathematics
    2, 3, geometry
      3, 6, calculus
        4, 5, derivative
        5, 6, integral
      6, 7, algebra
  7, 8, physics
When we want to insert one element, e.g. limit, normally under calculus, we have to specify:
  • parent
  • index within parent
so we have a method:
insert(parent, previousSibling)

Ancestors

  1. Tree representation
  2. Tree
  3. Type of graph
  4. Graph
  5. Discrete mathematics
  6. Area of mathematics
  7. Mathematics
  8. Ciro Santilli's Homepage