The Cusp of Helix

Fertile Forest Model
[C.2: Conventional Models]

Adjacency List Model

Adjacency List Model is the simplest designed model in conventional models.

Model Design

I am going to express the following tree structure data indicated in Adjacency List Model. [A], [B], ... indicated in figure means nodes.

        [A]-+-[B]-+-[D]
            |     |
            |     +-[E]
            |
            +-[C]-+-[F]
                  |
                  +-[G]-+-[H]
                        |
                        +-[I]

I am going to consider the table that has columns of id and name of each node, as a minimum of information about the node. Because of the table has no columns for hierarchical structure, can not restore tree data from the records in the table.

id1234 56789
nameABCD EFGHI

"Parent" column is added as a hierarchical structure column in Adjacency List Model. Save null for root node, because it has no parent of tree structure.

id123 456789
nameABC DEFGHI
tree_parentnull11 223377
CREATE TABLE `adjacency_list_models` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(225) DEFAULT NULL, `tree_parent` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `parent_index` (`tree_parent`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; INSERT INTO `adjacency_list_models` (`id`, `name`, `tree_parent`) VALUES (1, 'A', NULL), (2, 'B', 1), (3, 'C', 1), (4, 'D', 2), (5, 'E', 2), (6, 'F', 3), (7, 'G', 3), (8, 'H', 7), (9, 'I', 7);