Graph简述

Graph

remarks: 从bear导入的,不可见图为草稿,重点部分都有写。

基础

1. 术语

连通图(connected graph):如果从任意一个顶点都存在一条路径到达另一个任意顶点(undirected graph)
树:是一幅无环无向连通图
森林:1个or几个树
简单路径(simple path):一条没有重复顶点的路径
简单环(simple cycle):一条(除了起点和终点必须相同之外)不含有重复顶点和边的环
adjacent: when 2 v are connected by a single edge
biconnectivity/ biconnected graph: 移除一条边也不会使graph成为unconnected的graph
subgraph(of graph G):只取G中的几个顶点构成的图
spanning subgraph:取G中所有顶点构成的图
spanning tree:是G的subgraph+是tree=由G中所有顶点构成的无环无向连通图(spanning tree不唯一)

边的分类

directed edge: 有箭头的边,eg. flight(从A点到B点)
undirected edge: 无箭头的边,eg. flight route(A和B的距离)
directed graph
undirected graph

特性

  1. degree sum:degree只和=2E
  2. maximum degree:max degree=V-1
  3. edge count:E <= V(V-1)/2

2. 图的表示方法

2.1 邻接矩阵

邻接矩阵图例 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WUgPCDy8-1605523062295)(Graph/24905163-e121bc7bba6f78d1.png)]
space: O(V^2)
add edge: O(1)
check if adjacent: O(1)
iteration: O(V)

2.2 边的数组(edge lists)

eg: [ [0,1], [0, 2], [0, 5], [1, 2], [2, 3], [2, 4], [3, 4], [3, 5] ]
Edge里含两个int变量
space: O(E)
add edge: O(1)
check if adjacent: O(E)
iteration: O(E)

2.3 邻接表数组

2.3.1 例子

图
0: 6—>5—>2—>1
1: 3—>0
2: 0
3: 5—>1
4: 6—>5
5: 4—>3—>0
6: 7—>4—>0
7: 8—>6
8: 10—>7
9: 11—>10
10: 12—>9—>8
11: 9
12: 10

2.3.2 特点

a) 使用的空间和V+E成正比
b) 添加一条边所需的时间为常数
c) 遍历顶点v的所有相

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值