({{, (RefLink[TreeGraph, paclet:ref/TreeGraph])[{(Subscript[v, 1]),(Subscript[v, 2]),…},{(Subscript[u, 1]),(Subscript[u, 2]),…}] 
yields a tree where (Subscript[u, i]) is the predecessor of (Subscript[v, i]).}, {, (RefLink[TreeGraph, paclet:ref/TreeGraph])[{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields a tree with edges (Subscript[e, j]).}, {, (RefLink[TreeGraph, paclet:ref/TreeGraph])[{(Subscript[v, 1]),(Subscript[v, 2]),…},{(Subscript[e, 1]),(Subscript[e, 2]),…}]
yields a tree with vertices (Subscript[v, i]) and edges (Subscript[e, j]).}, {, (RefLink[TreeGraph, paclet:ref/TreeGraph])[{…,(Subscript[w, i])[(Subscript[v, i]),…],…},{…,(Subscript[w, j])[(Subscript[e, j]),…],…}]
yields a tree with vertex and edge properties defined by the symbolic wrappers (Subscript[w, k]).}, {, (RefLink[TreeGraph, paclet:ref/TreeGraph])[{(Subscript[v, i])->(Subscript[v, j]),…}]
uses rules (Subscript[v, i])->(Subscript[v, j]) to specify a tree.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[TreeGraph, paclet:ref/TreeGraph]) generates a (RefLink[Graph, paclet:ref/Graph]) object.

(RefLink[TreeGraph, paclet:ref/TreeGraph]) supports the same vertices, edges, wrappers, and options as (RefLink[Graph, paclet:ref/Graph]).

A tree is a connected graph with no cycles.

(RefLink[TreeGraph, paclet:ref/TreeGraph]) can only represent trees.

OpenersPrimaryExamplesSection(Spacer1)Examples  (121)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

A tree from pairs of children and parents:

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4}]

A tree from a list of vertices and edges:

TreeGraph[{1,2,3,4},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

OpenersExampleSection1(Spacer1)Scope  (25)

OpenersExampleSubsection0(Spacer1)Connectivity  (6)

Create an undirected graph using <-> characters; enter the character as (Key0[esc]) ue (Key0[esc]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Create a directed graph using -> characters; enter the character as (Key0[esc]) de (Key0[esc]):

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4}]

Create a directed graph from a list of rules:

TreeGraph[{1->2,1->3,1->4}]

Create an undirected graph from a list of rules:

TreeGraph[{1->2,1->3,1->4},DirectedEdges->False]

Use (RefLink[VertexList, paclet:ref/VertexList]) and (RefLink[EdgeList, paclet:ref/EdgeList]) to get vertices and edges:

{g1,g2}={TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}],TreeGraph[{1\[UndirectedEdge]3,1\[UndirectedEdge]2,1\[UndirectedEdge]4}]}

The ordering for edges is the order in which they were entered:

EdgeList/@{g1,g2}

The ordering for vertices is the order in which they were entered in the edges:

VertexList/@{g1,g2}

Use an explicit vertex list to control the ordering used by (RefLink[VertexList, paclet:ref/VertexList]):

{g1,g2}={TreeGraph[{1,2,3,4},{1\[UndirectedEdge]3,1\[UndirectedEdge]2,1\[UndirectedEdge]4}],TreeGraph[{3,2,1,4},{1\[UndirectedEdge]3,1\[UndirectedEdge]2,1\[UndirectedEdge]4}]}

The input vertex list controls the resulting vertex order:

VertexList/@{g1,g2}

Any expression can be used as vertices:

{TreeGraph[{a\[UndirectedEdge]b,a\[UndirectedEdge]c}],TreeGraph[{"foo"\[UndirectedEdge]"bar","foo"\[UndirectedEdge]"gnu"}],
TreeGraph[{\[UndirectedEdge],\[UndirectedEdge]}]}

VertexList/@%

OpenersExampleSubsection1(Spacer1)Wrappers  (5)

Use wrappers on vertices or edges:

{TreeGraph[{Style[1,Red],2,3,4},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}],TreeGraph[{1,2,3,4},{Style[1\[UndirectedEdge]2,Red],1\[UndirectedEdge]3,1\[UndirectedEdge]4}]}

Wrappers can be nested:

{TreeGraph[{Labeled[Style[1,Red],"hello"],2,3,4},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}],TreeGraph[{1,2,3,4},{Style[Labeled[1\[UndirectedEdge]2,"hello"],Red],1\[UndirectedEdge]3,1\[UndirectedEdge]4}]}

Add interactive behavior by wrappers such as (RefLink[Tooltip, paclet:ref/Tooltip]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Tooltip[Style[1\[UndirectedEdge]4,Red],"hello"]}]

Any object can be used in the tooltip:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Tooltip[Style[1\[UndirectedEdge]4,Red],Plot[Sin[x],{x,0,2Pi}]]}]

Use (RefLink[Button, paclet:ref/Button]) to trigger actions when clicking an edge or vertex:

{TreeGraph[{1\[UndirectedEdge]2,Button[Style[1\[UndirectedEdge]3,Red],Speak["Edge from 1 to 3"]]}],TreeGraph[{1,2,Button[Style[3,Red],Speak["Vertex 3"]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3},VertexSize->Medium]}

Use (RefLink[PopupWindow, paclet:ref/PopupWindow]) to provide information drilldown:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,PopupWindow[Style[1\[UndirectedEdge]4,Red],DateListPlot[FinancialData["IBM","Jan. 1, 2004"]]]}]

OpenersExampleSubsection2(Spacer1)Styling  (8)

Set the style for all vertices or edges:

{TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->Green],TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->Green]}

Style individual vertices or edges using options:

{TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->{1->Green,Orange}],TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->{1\[UndirectedEdge]2->Green,Orange}]}

Use wrappers for individual styling:

{TreeGraph[{Style[1,Green],2,3},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->Orange],TreeGraph[{Style[1\[UndirectedEdge]2,Green],1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->Orange]}

Adjust the size of vertices using symbolic sizes:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Or use sizes in terms of the smallest distance between vertex centers:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,PlotLabel->s],{s,{0.1,0.2,0.5,1}}]

Use built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->s,VertexSize->0.2,PlotLabel->s],{s,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Rounded shapes:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->s,VertexSize->0.2,PlotLabel->s],{s,GraphElementData["Vertex","Rounded"]}]

Concave shapes:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->s,VertexSize->0.2,PlotLabel->s],{s,GraphElementData["Vertex","Concave"]}]

Draw individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Combine with a default vertex function:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square","Triangle"},VertexSize->0.2]

Use any (RefLink[Graphics, paclet:ref/Graphics]), (RefLink[Image, paclet:ref/Image]), or (RefLink[Graphics3D, paclet:ref/Graphics3D]) as a vertex shape:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShape->s,VertexSize->Medium],{s,{,,}}]

Use built-in collections for (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]):

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,{"BoxLine","DiamondLine","DotLine"}}]

Directed edges including solid arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","FilledArrow"]}]

Line arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","UnfilledArrow"]}]

Open arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","CarvedArrow"]}]

Specify an edge function for an individual edge:

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"UnfilledArrow"}]

Combine with a different default edge function:

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArrow","CarvedArrow"}]

OpenersExampleSubsection3(Spacer1)Labeling  (6)

Label any edge or vertex:

{TreeGraph[{Labeled[1\[UndirectedEdge]2,"hello"],1\[UndirectedEdge]3,1\[UndirectedEdge]4}],TreeGraph[{Labeled[1,"hello"],2,3},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]}

Use any expression as a label:

Table[TreeGraph[{1,2,Labeled[3,l]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}],{l,{Sin[x],,}}]

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Labeled[1\[UndirectedEdge]4,l]}],{l,{Sin[x],,}}]

Control the placement of vertex labels using (RefLink[Placed, paclet:ref/Placed]), including symbolic inside positions:

Table[TreeGraph[{1,2,Labeled[3,Placed["■■",p]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3},PlotLabel->p,VertexSize->0.25,VertexShapeFunction->"Square"],{p,{Left,Right,Top,Bottom}}]

Symbolic outside positions:

Table[TreeGraph[{1,2,Labeled[3,Placed["■■",p]]},{1\[UndirectedEdge]2,2\[UndirectedEdge]3},PlotLabel->p,VertexSize->Small,VertexShapeFunction->"Square"],{p,{Before,After,Below,Above}}]

Coordinate-based positions:

Table[TreeGraph[{1,2,Labeled[3,Placed["■",p]]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3},VertexSize->0.25,VertexShapeFunction->"Square",PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

TreeGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2"},{Above,Below}]]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Any number of labels can be used:

TreeGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2","lbl3","lbl4"},{Above,After,Below,Before}]]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Place multiple labels using (RefLink[VertexLabels, paclet:ref/VertexLabels]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->{4->Placed[{"lbl1","lbl2"},{Above,Below}]}]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement along an edge:

Table[TreeGraph[{Labeled[1\[UndirectedEdge]2,Placed["■■",p]],1\[UndirectedEdge]3},PlotLabel->p,VertexSize->Small],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[TreeGraph[{Labeled[1\[UndirectedEdge]2,Placed["■■",p]],1\[UndirectedEdge]3},PlotLabel->p,VertexSize->Small,BaselinePosition->Bottom],{p,{0,1/4,1/3}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Labeled[1\[UndirectedEdge]4,Placed[{"lbl1","lbl2"},{"Start","End"}]]}]

Any number of labels can be used:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Labeled[1\[UndirectedEdge]4,Placed[{"lbl1","lbl2","lbl3"},{"Start","Middle","End"}]]}]

Place multiple labels using (RefLink[EdgeLabels, paclet:ref/EdgeLabels]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]4->Placed[{"lbl1","lbl2"},{"Start","End"}]}]

OpenersExampleSection2(Spacer1)Options  (82)

OpenersExampleSubsection4(Spacer1)DirectedEdges  (2)

By default, a directed tree is generated when giving a list of rules:

TreeGraph[{1->2,1->3,1->4},EdgeStyle->Arrowheads[Medium],EdgeShapeFunction->"Arrow"]

Use (RefLink[DirectedEdges, paclet:ref/DirectedEdges])->(RefLink[False, paclet:ref/False]) to interpret rules as undirected edges:

TreeGraph[{1->2,1->3,1->4},DirectedEdges->False]

Use (RefLink[DirectedEdge, paclet:ref/DirectedEdge]) or (RefLink[UndirectedEdge, paclet:ref/UndirectedEdge]) to directly specify whether a graph is directed or not:

{TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeStyle->Arrowheads[Medium],EdgeShapeFunction->"Arrow"],TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]}

OpenersExampleSubsection5(Spacer1)EdgeLabels  (7)

Label the edge 1<->2:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]2->"Hello"}]

Label all edges:

el={1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4};

TreeGraph[el,EdgeLabels->Table[el[[i]]->(Subscript["e", i]),{i,Length[el]}]]

Use any expression as a label:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]2->,1\[UndirectedEdge]3->,1\[UndirectedEdge]4-> }]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement along an edge:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]2->Placed["■■■",p]},PlotLabel->p],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]2->Placed["■■■",p]},PlotLabel->p,BaselinePosition->Bottom],{p,{0,1/3,1/4}}]

Vary positions within the label:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]2->Placed["■■■",{1/2,p}]},PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Labeled[1\[UndirectedEdge]4,Placed[{"lbl1","lbl2"},{"Start","End"}]]}]

Any number of labels can be used:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,Labeled[1\[UndirectedEdge]4,Placed[{"lbl1","lbl2","lbl3"},{"Start","Middle","End"}]]}]

Place multiple labels using (RefLink[EdgeLabels, paclet:ref/EdgeLabels]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->{1\[UndirectedEdge]4->Placed[{"lbl1","lbl2"},{"Start","End"}]}]

Use automatic labeling by values through (RefLink[Tooltip, paclet:ref/Tooltip]) and (RefLink[StatusArea, paclet:ref/StatusArea]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->Placed["Name",Tooltip]]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeLabels->Placed["Name",StatusArea]]

OpenersExampleSubsection6(Spacer1)EdgeShapeFunction  (6)

Get a list of built-in settings for (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]):

GraphElementData["Edge"]

Undirected edges including the basic line:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeShapeFunction->"Line"]

Lines with different glyphs on the edges:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,{"BoxLine","DiamondLine","DotLine"}}]

Directed edges including solid arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","FilledArrow"]}]

Line arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","UnfilledArrow"]}]

Open arrows:

Table[TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","CarvedArrow"]}]

Specify an edge function for an individual edge:

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArcArrow"}]

Combine with a different default edge function:

TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1\[DirectedEdge]4},EdgeShapeFunction->{1\[DirectedEdge]2->"FilledArcArrow","CarvedArrow"}]

Draw edges by running a program:

ef[pts_List,e_]:=
Block[{s=0.015,g=},{Arrowheads[{{s,0.33,g},{s,0.67,g}}],Arrow[pts]}]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeShapeFunction->ef]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) can be combined with (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->Blue,EdgeShapeFunction->(Line[#1]&)]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) has higher priority than (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->Blue,EdgeShapeFunction->({Red,Line[#1]}&)]

OpenersExampleSubsection7(Spacer1)EdgeStyle  (2)

Style all edges:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->style,PlotLabel->style],{style,{Gray,Dashed,Thick}}]

Style individual edges:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeStyle->{1\[UndirectedEdge]2->Blue,1\[UndirectedEdge]3->Dashed}]

OpenersExampleSubsection8(Spacer1)EdgeWeight  (2)

Specify the weight for all edges:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeWeight->RandomInteger[5,3]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use any numeric expression as a weight:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},EdgeWeight->{a,b,c}]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSubsection9(Spacer1)GraphHighlight  (3)

Highlight the vertex 1:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->Medium,GraphHighlight->{1}]

Highlight the edge 1<->3:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->Tiny,GraphHighlight->{1\[UndirectedEdge]3}]

Highlight vertices and edges:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->Tiny,GraphHighlight->{1,2,1\[UndirectedEdge]2,1\[UndirectedEdge]3}]

OpenersExampleSubsection10(Spacer1)GraphHighlightStyle  (2)

Get a list of built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

GraphElementData["GraphHighlightStyle"]

Use built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},GraphHighlight->{1,1\[UndirectedEdge]3},VertexSize->Small,GraphHighlightStyle->#,PlotLabel->#]&/@Select[GraphElementData["GraphHighlightStyle"],#=!=Automatic&]

OpenersExampleSubsection11(Spacer1)GraphLayout  (5)

By default, the layout is chosen automatically:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},GraphLayout->Automatic]

Specify layouts on special curves:

Table[TreeGraph[Table[i\[UndirectedEdge]i+1,{i,20}],GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Specify layouts that satisfy optimality criteria:

el=EdgeList@CompleteKaryTree[4,5];

Table[TreeGraph[el,GraphLayout->l,PlotLabel->l],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) overrides (RefLink[GraphLayout, paclet:ref/GraphLayout]) coordinates:

{TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},GraphLayout->"SpringElectricalEmbedding"],
TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Table[{i,i},{i,0,3}]]}

Use (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]) to extract (RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) computed using a layout algorithm:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

AbsoluteOptions[%,VertexCoordinates]

OpenersExampleSubsection12(Spacer1)PlotTheme  (4)

OpenersExampleSubsubsection0(Spacer1)Base Themes  (2)

Use a common base theme:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},PlotTheme->"Business"]

Use a monochrome theme:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},PlotTheme->"Monochrome"]

OpenersExampleSubsubsection1(Spacer1)Feature Themes  (2)

Use a large graph theme:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},PlotTheme->"LargeGraph"]

Use a classic diagram theme:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},PlotTheme->"ClassicDiagram"]

OpenersExampleSubsection13(Spacer1)Properties  (3)

Specify a property for vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},Properties->{3->{VertexLabels-> "hello"}}]

Edges:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},Properties->{1\[UndirectedEdge]3->{EdgeLabels-> "hello"}}]

Graph itself:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},Properties->{"GraphProperties"->{"Message"-> "hello"}}]

PropertyValue[%,"Message"]

OpenersExampleSubsection14(Spacer1)VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Extract the resulting vertex coordinates using (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]):

AbsoluteOptions[%,VertexCoordinates]

Specify a layout function along an ellipse:

ellipseLayout[n_,{a_,b_}]:=Table[{a Cos[2Pi/n u],b Sin[2Pi/n u]},{u,1,n}]

Graphics[Point[ellipseLayout[20,{2,1}]]]

Use it to generate vertex coordinates for a graph:

TreeGraph[Table[1\[UndirectedEdge]i,{i,2,20}],VertexCoordinates->ellipseLayout[20,{2,1}]]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) has higher priority than (RefLink[GraphLayout, paclet:ref/GraphLayout]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexCoordinates->Table[{i,i},{i,4}],GraphLayout->"CircularEmbedding"]

OpenersExampleSubsection15(Spacer1)VertexLabels  (13)

Use vertex names as labels:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->"Name"]

Label individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->{2->"one"}]

Label all vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Table[i->(Subscript[v, i]),{i,4}]]

Use any expression as a label:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3},VertexLabels->{1->,2->,3->},ImagePadding->30]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement, including outside positions:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,4}],PlotLabel->p],{p,{Before,After,Below,Above}}]

Symbolic outside corner positions:

pl={{Before,Below},{After,Below},{Before,Above},{After,Above}};

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,4}],PlotLabel->p],{p,pl}]

Symbolic inside positions:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.35,VertexLabels->Table[i->Placed["■■■",p],{i,4}],VertexShapeFunction->"Square",PlotLabel->p],{p,{Left,Top,Right,Bottom}}]

Symbolic inside corner positions:

pl={{Left,Bottom},{Right,Bottom},{Left,Top},{Right,Top}};

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.35,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,4}],PlotLabel->p],{p,pl}]

Use explicit coordinates to place the center of labels:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.25,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,4}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.35,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,{{1,1},p}],{i,4}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels using (RefLink[Placed, paclet:ref/Placed]) in a wrapper:

TreeGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2"},{Above,Below}]]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Any number of labels can be used:

TreeGraph[{1,2,3,Labeled[4,Placed[{"lbl1","lbl2","lbl3","lbl4"},{Above,After,Below,Before}]]},{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4}]

Place multiple labels using (RefLink[VertexLabels, paclet:ref/VertexLabels]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->{4->Placed[{"lbl1","lbl2"},{Above,Below}]}]

Use the argument to (RefLink[Placed, paclet:ref/Placed]) to control formatting including (RefLink[Tooltip, paclet:ref/Tooltip]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Placed["Name",Tooltip]]

Or (RefLink[StatusArea, paclet:ref/StatusArea]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Placed["Name",StatusArea]]

Use more elaborate formatting functions:

rotateLabel[lab_]:=Rotate[lab,45Degree]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Table[i->Placed["xxx",Below,rotateLabel],{i,4}]]

panelLabel[lab_]:=Panel[lab,FrameMargins->0,Background->Lighter[Yellow,0.7]]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Table[i->Placed["xxx",Center,panelLabel],{i,4}]]

hyperlinkLabel[lab_]:=Hyperlink[lab,"http://www.wolfram.com"]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexLabels->Table[i->Placed["xxx",Center,hyperlinkLabel],{i,4}]]

OpenersExampleSubsection16(Spacer1)VertexShape  (5)

Use any (RefLink[Graphics, paclet:ref/Graphics]), (RefLink[Image, paclet:ref/Image]), or (RefLink[Graphics3D, paclet:ref/Graphics3D]) as a vertex shape:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShape->s,VertexSize->0.3],{s,{,,}}]

Specify vertex shapes for individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShape->{2->},VertexSize->0.3]

(RefLink[VertexShape, paclet:ref/VertexShape]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,VertexShape->,PlotLabel->s],{s,{Medium,Large}}]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.3,VertexShape->,VertexStyle->Blue]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.2,VertexShapeFunction->"Square",VertexShape->]

OpenersExampleSubsection17(Spacer1)VertexShapeFunction  (10)

Get a list of built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

GraphElementData["Vertex"]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Basic" collection:

GraphElementData["Vertex","Basic"]

Simple basic shapes:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Common basic shapes:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"DownTrapezoid","UpTrapezoid","Parallelogram","FiveDown","Circle","Diamond","Star","Capsule"}}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Rounded" collection:

GraphElementData["Vertex","Rounded"]

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Rounded"]}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Concave" collection:

GraphElementData["Vertex","Concave"]

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Concave"]}]

Draw individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Combine with a default vertex function:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->{ 1->"Square","Triangle"},VertexSize->0.2]

Draw vertices using a predefined graphic:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->(Inset[,#]&)]

Draw vertices by running a program:

vf[{xc_,yc_},name_,{w_,h_}]:=
Block[{xmin=xc-w,xmax=xc+w,ymin=yc-h,ymax=yc+h},
Polygon[{{xmin,ymin},{xmax,ymax},{xmin,ymax},{xmax,ymin}}]
];

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->vf,VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf1[{xc_,yc_},name_,{w_,h_}]:=Rectangle[{xc-w,yc-h},{xc+w,yc+h}]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf1]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf2[{xc_,yc_},name_,{w_,h_}]:={Red,Rectangle[{xc-w,yc-h},{xc+w,yc+h}]}

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexShapeFunction->"Star",VertexSize->{1->Small,Medium}]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.3,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection18(Spacer1)VertexSize  (8)

By default, the size of vertices is computed automatically:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->Automatic]

Specify the size of all vertices using symbolic vertex size:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Use a fraction of the minimum distance between vertex coordinates:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,PlotLabel->s],{s,0.1,1,0.3}]

Use a fraction of the overall diagonal for all vertex coordinates:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->{"Scaled", s},PlotLabel->{"Scaled", s}],{s,0.1,1,0.3}]

Specify size in both the x and y directions:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,PlotLabel->s],{s,{{0.1,0.2},{0.2,0.1}}}]

Specify the size for individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->{1->0.2,2->0.3}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,VertexShapeFunction->"Square",PlotLabel->s],{s,{0.05,0.1,0.2}}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShape, paclet:ref/VertexShape]):

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->s,VertexShape->,PlotLabel->s],{s,{0.1,0.2,0.4}}]

OpenersExampleSubsection19(Spacer1)VertexStyle  (5)

Style all vertices:

Table[TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->style,VertexSize->0.3,PlotLabel->style],{style,{Yellow,EdgeForm[Dashed]}}]

Style individual vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->{1->Blue,2->Red},VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf1[{xc_,yc_},name_,{w_,h_}]:=Rectangle[{xc-w,yc-h},{xc+w,yc+h}]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf1]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf2[{xc_,yc_},name_,{w_,h_}]:={Red,Rectangle[{xc-w,yc-h},{xc+w,yc+h}]}

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) can be combined with (RefLink[BaseStyle, paclet:ref/BaseStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->LightBlue,BaseStyle->EdgeForm[Dotted],VertexSize->0.2]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) has higher priority than (RefLink[BaseStyle, paclet:ref/BaseStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexStyle->LightBlue,BaseStyle->Gray,VertexSize->0.2]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexSize->0.3,VertexShape->,VertexStyle->Blue]

OpenersExampleSubsection20(Spacer1)VertexWeight  (2)

Set the weight for all vertices:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexWeight->{2,3,4,5}]

PropertyValue[{%,1},VertexWeight]

Use any numeric expression as a weight:

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4},VertexWeight->{a,b,c,d}]

PropertyValue[{%,1},VertexWeight]

OpenersExampleSection3(Spacer1)Applications  (4)

Generate a random tree:

g=TreeGraph[RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 30],VertexSize->0.4]

Highlight the (RefLink[GraphCenter, paclet:ref/GraphCenter]) and (RefLink[GraphPeriphery, paclet:ref/GraphPeriphery]):

{HighlightGraph[g,GraphCenter[g]],HighlightGraph[g,GraphPeriphery[g]]}

The (RefLink[VertexEccentricity, paclet:ref/VertexEccentricity]):

g=TreeGraph[RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 30],VertexSize->0.4];

VertexEccentricity[g,#]&/@Range[3]

Highlight the vertex eccentricity path:

FindVertexEccentricityPath[g_?UndirectedGraphQ,u_]/;MemberQ[VertexList[g],u]:=Module[{d=GraphDistanceMatrix[g],v,posu,posv,vl=VertexList[g]},posu=VertexIndex[g,u];
posv=First@First@Position[d[[posu]],Max[d[[posu]]]];
PathGraph[FindShortestPath[g,u,vl[[posv]]]]]

Table[HighlightGraph[g,FindVertexEccentricityPath[g,u]],{u,Range[3]}]

The (RefLink[GraphRadius, paclet:ref/GraphRadius]):

g=TreeGraph[RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 30],VertexSize->0.4];

GraphRadius[g]

Highlight the radius path:

FindRadiusPath[g_?UndirectedGraphQ]:=Module[{c=First@GraphCenter[g],d,v,pos},d=Table[GraphDistance[g,c,u],{u,VertexList[g]}];
pos=First@Position[d,Max[d]];
v=First@Part[VertexList[g],pos];
PathGraph[FindShortestPath[g,c,v]]]

HighlightGraph[g,FindRadiusPath[g]]

The (RefLink[GraphDiameter, paclet:ref/GraphDiameter]):

g=TreeGraph[RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 30],VertexSize->0.4];

GraphDiameter[g]

Highlight the diameter path:

FindDiameterPath[g_?UndirectedGraphQ]:=Module[{d=GraphDistanceMatrix[g],u,v,pos},pos=First@Position[d,Max[d]];
{u,v}=Part[VertexList[g],pos];
PathGraph[FindShortestPath[g,u,v]]]

HighlightGraph[g,FindDiameterPath[g]]

OpenersExampleSection4(Spacer1)Properties & Relations  (9)

Use (RefLink[VertexCount, paclet:ref/VertexCount]) and (RefLink[EdgeCount, paclet:ref/EdgeCount]) to count vertices and edges:

g=CompleteKaryTree[3,3]

{VertexCount[g],EdgeCount[g]}

Use (RefLink[VertexList, paclet:ref/VertexList]) and (RefLink[EdgeList, paclet:ref/EdgeList]) to enumerate vertices and edges in standard order:

g=TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,3\[UndirectedEdge]4}];

{VertexList[g],EdgeList[g]}

Edges and vertices are given in the order they are input:

g1=TreeGraph[{3\[UndirectedEdge]4,1\[UndirectedEdge]2,1\[UndirectedEdge]3}];

{VertexList[g1],EdgeList[g1]}

Compute the (RefLink[AdjacencyMatrix, paclet:ref/AdjacencyMatrix]) from a graph:

g=TreeGraph[{1\[DirectedEdge]2,1\[DirectedEdge]3,1->4},EdgeStyle->Arrowheads[Medium],EdgeShapeFunction->"Arrow"]

(a=AdjacencyMatrix[g]//Normal)//MatrixForm

A tree graph is connected:

CompleteKaryTree[3,3]

{ConnectedGraphQ[%],TreeGraphQ[%]}

A tree graph does not have any loops or cycles:

TreeGraph[Range[8],{1,1,2,1,4,2,3,1}]

{LoopFreeGraphQ[%],AcyclicGraphQ[%],TreeGraphQ[%]}

A tree graph with n vertices has n-1 edges:

TreeGraph[{1->2,1->3,2->4,2->5,3->6}]

VertexCount[%]-EdgeCount[%]

A tree graph is a bipartite graph:

CompleteKaryTree[3,3]

{ TreeGraphQ[%],BipartiteGraphQ[%]}

A tree graph with n vertices with n>1 has at least two and at most n-1 vertices of degree 1:

TreeGraph[{1->2,1->3}]

VertexDegree[%]

CompleteKaryTree[2,6]

VertexDegree[%]

A star graph is a tree graph:

StarGraph[10]

TreeGraphQ[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Graph, paclet:ref/Graph])  ▪  (RefLink[UndirectedEdge, paclet:ref/UndirectedEdge])  ▪  (RefLink[DirectedEdge, paclet:ref/DirectedEdge])  ▪  (RefLink[TreeGraphQ, paclet:ref/TreeGraphQ])  ▪  (RefLink[KaryTree, paclet:ref/KaryTree])  ▪  (RefLink[CompleteKaryTree, paclet:ref/CompleteKaryTree])  ▪  (RefLink[StarGraph, paclet:ref/StarGraph])  ▪  (RefLink[FindSpanningTree, paclet:ref/FindSpanningTree])  ▪  (RefLink[TreePlot, paclet:ref/TreePlot])  ▪  (RefLink[PathGraph, paclet:ref/PathGraph])  ▪  (RefLink[PlanarGraph, paclet:ref/PlanarGraph])  ▪  (RefLink[TextStructure, paclet:ref/TextStructure])  ▪  (RefLink[Groupings, paclet:ref/Groupings])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}, {▪(RefLinkPlain[Discrete Mathematics, paclet:guide/DiscreteMathematics])}})}})