The basic idea is to store paths to all ancestors and all descendants in a separate table. This makes a lot of actions very fast at the cost of space. Many of the basic modifications of the tree are covered in the slides, but some of them took me some thought to work out.

When we bring it into our language of choice, the first thing to do it sort the list by number of ancestors.Top level nodes will only have themselves as an ancestor, and any node with two ancestors is dependant solely on a node with one ancestor. After we have sorted our ancestor list, we either create the first node with the first item in the list, or we create an empty node to start as $tree. I used an empty node, as I have many top level nodes. If you have only one node without ancestors other than itself, use it for the first node.

To traverse the tree, the next node will always be the intersection between the list of ancestors, and the available ancestors.

If there is only one ancestor left, it is to be a new child of whatever node you end up on.

Moving a segment of the tree is probably the most painful task. It is divided into two parts.1) Remove all the links from the node and its descendants to all of its ancestors2) Insert all the links from the knode and its descendants to the new ancestors

So, if we want to move node 4 under node 3, first we:delete these descendants:SELECT descendant FROM closure WHERE ancestor=4;from these ancestors:SELECT ancestor FROM closure WHERE descendant=4 AND ancestor != 4;

First we get the ancestors of the new node (3)SELECT ancestor FROM closure WHERE descendant=3;Then we get the descendants of the old node (4)SELECT descendant FROM closure WHERE ancestor=4;Then we cross join them.