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

  • 相关阅读:
    [敏杰开发]Beta Scrum Meeting 6
    团队作业第六次--Beta阶段集合随笔
    宅单词——置顶博客
    Beta冲刺总结
    随机组队吐槽
    用户使用调查报告
    Beta冲刺--Day7
    Beta冲刺--Day6
    Beta冲刺--Day5
    Beta冲刺--Day4
  • 原文地址:https://www.cnblogs.com/kong-xy/p/9055274.html
Copyright © 2011-2022 走看看