Princeton Algorithm II-4.1 Undirected Graph

本文介绍了图论和树的基本概念,包括自环、平行边、邻接、度数、子图、路径、环、连通性和连通分量等,并讨论了图的表示方法及搜索算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 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

转载于:https://www.cnblogs.com/kong-xy/p/9055274.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值