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

  • 相关阅读:
    稀疏自编码器和矢量化编程
    使用支持向量机训练mnist数据
    采用libsvm进行mnist训练
    支持向量机
    月下“毛景树”
    最小费用最大流模板
    最大流模板
    选学霸
    线段树 2
    线段树 1
  • 原文地址:https://www.cnblogs.com/kong-xy/p/9055274.html
Copyright © 2011-2022 走看看