Categorized | News

Modeling Trees: Nested Sets and Adjacency Lists

Posted on 13 November 2003 by Demian Turner

We’re thinking of using PEAR‘s NestedSet library on the Seagull project as an improvement on the current MySQL-only tree manipulations offered by HTML_TreeMenu.

Nested sets are more complex to setup than the simple id-parent id paradigm of the adjacent list method, but running typical queries to determine leaf nodes, paths, etc are much easier.

This article on modeling trees has a good overview of the difference between the two approaches, thanks to Andy Crain for pointing it out.

update: the quoted link has since been pulled, but check out this article on modified preorder tree traversal which gives similar background info on the subject.

Bookmark and Share

1 Comments For This Post

  1. tariquesani Says:

    At the end of the day you more often than not end up storing infromation in nested as well parent id format.

    The main reason is that while nested tree logic is seductive it is incredebly difficult to handle some task which are trivial in parent – child trees (or whatever they are called )

    Like in a nested tree try getting just the next level childs OR inserting a node…

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook