8.5 Trees

Abstract structures such as lists, stacks, and queues are linear in nature. Only one relationship in the data is being modeled. Items are next to each other in a list or are next to each other in terms of time in a stack or queue. Depicting more complex relationships requires more complex structures. Take, for example, an animal hierarchy. General classification occurs at higher levels and the labels get more specific as you move down. Each node could have many below it (FIGURE 8.5).

In animal hierarchical structure, the mammals are branched into three as horse, dog, and whale. Further, the dogs are sub-branched into hound and terrier.

FIGURE 8.5 An animal hierarchy forms a tree

Such hierarchical structures are called trees, and there is a rich mathematical theory relating to them. ...

Get Computer Science Illuminated, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.