-
Basic Concept for Graph##
- self-loop: an edge that connects a vertex to itself
- parallel: edges: two edges are parallel if they connect the same pair of vertices
- adjacent: When an edge connects two vertices, we say that the vertices are adjacent to one another and that the edge is incident on both vertices
- degree: number of edges incident on it
- subgraph: the subset of a graph's edges that constitutes a graph
- path: a sequence of vertices connected by edges
- cycle: a path(at least one edge) whose first and last vertices are the same
- connected: A graph is connected if there is a path from every vertex to every other vertex.
- connected components: A graph that is not connected
- spanning tree: A spanning tree of a connected graph is a subgraph that contains all of the graph's vertices and is a single tree
-
Basic Concept for Tree##
- height:
- depth:
-
Graph Representation
//计算v的度数
public static int degree(Graph G, int v) {
int degree = 0;
for (int w : G.adj(v)) degree++;
return degree;
}
public static int maxDegree(Graph G) {
int max = 0;
for (int v = 0; v < G.V(); v++) {
if (degree(G, v) > max)
max = degree(G, v);
return max;
}
public static double avgDegree(Graph G) {
return 2.0 * G.E() / G.V();
}
-
Depth-first search
-
Breadth-first search
-
Connected Component