zoukankan      html  css  js  c++  java
  • Princeton Algorithm II-4.1 Undirected Graph

    • 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

  • 相关阅读:
    1st_pandas
    8thNumpy a.copy()
    7thNumpy array合并
    6th_numpy array的合并 np.vstack np.concatenate np.newaxis
    numpy_5th array索引
    numpy_4th np.transpose(a); a.T ; a.clip(min,max) ; np.sort(a) ; np.diff() ; np.cumsum(a)
    numpy_3rd 布尔运算/乘积点积
    POJ 3270
    POJ 1721
    POJ 3128
  • 原文地址:https://www.cnblogs.com/kong-xy/p/9055274.html
Copyright © 2011-2022 走看看