Nested Sets
Let's see how Nested Sets can solve the Naive Trees antipattern.
We'll cover the following
The Nested Sets solution stores information with each node that pertains to the set of its descendants rather than the node’s immediate parent. This information can be represented by encoding each node in the tree with two numbers, which we can call nsleft
and nsright
.
Creating Comments
table with nsleft
and nsright
Let’s create the Comments
table, with nsright
and nsleft
as its columns.
Get hands-on with 1400+ tech skills courses.