Graphs in Mathematica

Graphs representation

ShowGraph[Star[12],VertexNumber->True]

g1=Star[12]

Head[g1]

g1[[1]] (* the first element of g1 is a list of edges *)

Edges[g1] (* the correct way of getting the edges is using the function Edges *)

g1[[2]] (* the second element of g1 is a list of vertices containing the position of the point representing the vertex *)

Vertices[g1]  (* the correct way of getting the infos of the vertices *)

ShowGraph[g2=SetGraphOptions[Star[12],VertexStyle->Box[Large],EdgeStyle->NormalDashed]]

{g2[[3]],g2[[4]]}

ShowGraph[g3=SetGraphOptions[Star[12],{{1,7,VertexStyle->Disk[Large]}}]]

Vertices[g3,All]

DegreeSequence[g3]

ShowGraph[g4=CompleteGraph[5],VertexNumber->True,TextStyle->{FontSize->13},PlotRange->0.1]

ShowGraph[g4=SetGraphOptions[CompleteGraph[5],{{{1,2},{2,5},EdgeStyle->Thick}}]]

Edges[g4,All]

Edges[g4,EdgeWeight]

ShowGraph[RandomGraph[10,.3,Type->Directed]]

ShowGraph[RandomGraph[5,.3,Type->Directed]]

Adjacency Lists, Adjacency matrix

ToAdjacencyLists[CompleteGraph[4]]

ToAdjacencyLists[g4]//ColumnForm

ToAdjacencyMatrix[g4]//TableForm

ToAdjacencyMatrix[g4]//MatrixForm

IncidenceMatrix[g4]//MatrixForm

Trees

ShowGraphArray[Table[CompleteKaryTree[20,i],{i,5}]]

ShowGraph[CompleteBinaryTree[31]]

ShowGraphArray[Partition[ListGraphs[5,4],3]]