liveBook · Manning

Tree

As explained in Object-Oriented Software Design in C++

A hierarchical data structure composed of nodes connected by parent-child relationships without cycles.

A tree organizes hierarchical data as nodes connected through levels. The top node is the root, intermediate nodes group lower-level nodes, and leaves occupy the bottom. A node can hold a different datatype from another node. section 11.2

A practical tree design commonly includes:

  • Parent or composite nodes aggregate objects at the next level, while leaf nodes represent individual data objects. section 11.2.2
  • A traversal begins at the root and visits nodes downward, allowing multiple algorithms to process the same collection. section 11.2
  • A tree can support operations such as printing hierarchical data, counting items, or calculating totals. section 11.2
  • When different operations change more often than the hierarchy, Visitor separates report algorithms from the node classes. section 11.3

Intramural reports

An Intramural root contains Sport nodes; each Sport contains Game nodes; and Hall objects serve as leaves or separately tracked referenced objects. Traversing the tree produces scores, activity counts, and winnings reports. Each node accepts a visitor, which dispatches to the appropriate operation for that node type. section 11.2.2 section 11.3

Figure 11.4 An example tree data structure of hierarchical data for a store. Store is the root node. The intermediate tree nodes are store departments Produce, Soups, and Soaps; categories Vegetables and Fruits in the Produce Department; and categories Bar, Dish, and Laundry in the Soaps Department. The leaf nodes at the bottom (shaded in gray) are the products.

Use the store hierarchy to see a root, departments, categories, and product leaves arranged as one tree. section 11.2

How Object-Oriented Software Design in C++ covers it

How deep it goes
Defines roots, intermediate nodes, leaves, aggregation, traversal, and Visitor-based operations, but does not formalize tree variants.
Examples
Uses store departments and products plus intramural sports, games, residence halls, and generated reports.
What it assumes
Assumes basic classes, vectors, pointers, inheritance, and polymorphism; teaches the hierarchy through concrete application models.
What you can do after
Build it from scratch by modeling nodes, aggregation, traversal, and operations over a hierarchical collection.
How it connects
Ties tree structures to Visitor, Composite, polymorphism, aggregation, and hierarchical data.

Also explained in

Compare how 11 books explain tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.