liveBook · Manning

Tree

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A connected acyclic data structure consisting of nodes linked by hierarchical edges.

A tree is a connected graph with no cycles or self-loops. Its nodes are linked by hierarchical edges, so every node belongs to one connected, cycle-free structure. section 3.1

Trees are a specialized case of graphs. Distinguish them from directed graphs, multigraphs, weighted graphs, and general acyclic graphs by checking connectivity, cycles, and self-loops. section 3.1

Listing 3.4 Creating an acyclic graph using NetworkX
import networkx as nx
import matplotlib.pyplot as plt
 
graph = nx.DiGraph()
nodes = list(range(5))
edges = [(0,1), (0,2),(4,1),(1,2),(2,3)]
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
 
nx.draw_networkx(graph, nx.kamada_kawai_layout(graph), with_labels=True,
 font_color='w')
plt.show()
 
nx.is_directed_acyclic_graph(graph)    #1
#1 Check if the graph is acyclic.

Inspect a NetworkX acyclic-graph construction and its directed-cycle check as a nearby comparison for tree structure. section 3.1

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Provides a concise definition and classification, but stops short of tree operations, traversal algorithms, and complexity analysis.
Examples
Uses NetworkX code for undirected, directed, multigraph, acyclic, and weighted graph examples.
What you can do after
Evaluate whether a graph fits the defining connected, cycle-free, self-loop-free structure of a tree.
How it connects
Connects trees with graphs, acyclic graphs, directed graphs, multigraphs, weighted graphs, and NetworkX.

Also explained in

Compare how 11 books explain tree →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.