更改

跳到导航 跳到搜索
添加420字节 、 2020年10月21日 (三) 23:17
无编辑摘要
第20行: 第20行:  
图的邻接表表示法将图中的每个顶点与其邻接顶点或边的集合关联起来。这个基本思想有许多变体,在如何实现顶点和集合之间的关联,如何实现集合,以及是否包括顶点和边还是只包括顶点作为第一类对象,以及什么类型的对象被用来表示顶点和边的细节上都有所不同。
 
图的邻接表表示法将图中的每个顶点与其邻接顶点或边的集合关联起来。这个基本思想有许多变体,在如何实现顶点和集合之间的关联,如何实现集合,以及是否包括顶点和边还是只包括顶点作为第一类对象,以及什么类型的对象被用来表示顶点和边的细节上都有所不同。
   −
* An implementation suggested by [[Guido van Rossum]] uses a [[hash table]] to associate each vertex in a graph with an [[array data structure|array]] of adjacent vertices. In this representation, a vertex may be represented by any hashable object. There is no explicit representation of edges as objects.
+
* An implementation suggested by [[Guido van Rossum]] uses a [[hash table]] to associate each vertex in a graph with an [[array data structure|array]] of adjacent vertices. In this representation, a vertex may be represented by any hashable object. There is no explicit representation of edges as objects.<ref>{{cite web| author = Guido van Rossum| year = 1998| title = Python Patterns — Implementing Graphs| url = https://www.python.org/doc/essays/graphs/}}</ref>
   −
  --[[用户:黄秋莉|黄秋莉]][[用户讨论:黄秋莉|讨论]]  【审校】* 吉多·范罗苏姆(Guido van Rossum)提出一种实现方法:'''<font color="#ff8000">哈希表</font>''',将图中的每个顶点与其相邻顶点采用一种'''<font color="#ff8000">数组</font>'''数据结构表示。在这种表示法中,顶点可以由任何散列对象表示,而连边没有被表示为对象。
  −
  | author = [[Guido van Rossum]]
     −
  | author = Guido van Rossum
     −
作者: 吉多·范罗苏姆
+
* Cormen et al. suggest an implementation in which the vertices are represented by index numbers.<ref>{{cite book| title = Introduction to Algorithms, Second Edition| publisher = MIT Press and McGraw-Hill | year = 2001|author1 = Thomas H. Cormen|author2 = Charles E. Leiserson| author3 = Ronald L. Rivest| author4 = Clifford Stein }}</ref> Their representation uses an array indexed by vertex number, in which the array cell for each vertex points to a [[singly linked list]] of the neighboring vertices of that vertex. In this representation, the nodes of the singly linked list may be interpreted as edge objects; however, they do not store the full information about each edge (they only store one of the two endpoints of the edge) and in undirected graphs there will be two different linked list nodes for each edge (one within the lists for each of the two endpoints of the edge).
  --[[用户:黄秋莉|黄秋莉]][[用户讨论:黄秋莉|讨论]]  【审校】吉多·范罗苏姆(Guido van Rossum)
+
它们的表示使用一个按顶点数索引的数组,其中每个顶点的数组单元格指向该顶点的相邻顶点的单链表。在这种表示中,单链表的节点可以解释为边对象; 然而,它们并不存储关于每条边的完整信息(它们只存储边的两个端点中的一个) ,在'''<font color="#ff8000">无向图 Undirected Graph </font>'''中,每条边有两个不同的链表节点(边的两个端点中的每个端点的列表中都有一个)。
 
  −
  | year = 1998
  −
 
  −
  | year = 1998
  −
 
  −
1998年
  −
 
  −
  | title = Python Patterns — Implementing Graphs
  −
 
  −
  | title = Python Patterns — Implementing Graphs
  −
 
  −
| title = Python Patterns ーー实现图形
  −
  --[[用户:黄秋莉|黄秋莉]][[用户讨论:黄秋莉|讨论]]  【审校】“| title = Python Patterns ーー实现图形”改为“标题 = Python代码 --图形实现”
  −
  | url = https://www.python.org/doc/essays/graphs/}}</ref>
  −
 
  −
  | url = https://www.python.org/doc/essays/graphs/}}</ref>
  −
 
  −
| url = https://www.python.org/doc/essays/graphs/} </ref >  
  −
 
  −
* Cormen et al. suggest an implementation in which the vertices are represented by index numbers.
  −
 
  −
  --[[用户:黄秋莉|黄秋莉]][[用户讨论:黄秋莉|讨论]]  【审校】Cormen等建议使用'''<font color="#ff8000">顶点索引号</font>'''对顶点操作
  −
  | title = [[Introduction to Algorithms]], Second Edition
  −
 
  −
  | title = Introduction to Algorithms, Second Edition
      +
 +
*The [[object oriented]] incidence list structure suggested by Goodrich and Tamassia has special classes of vertex objects and edge objects. Each vertex object has an instance variable pointing to a collection object that lists the neighboring edge objects. In turn, each edge object points to the two vertex objects at its endpoints.<ref name="A">{{cite book| author = Michael T. Goodrich and Roberto Tamassia | title = Algorithm Design: Foundations, Analysis, and Internet Examples| publisher = John Wiley & Sons | year = 2002  | isbn = 0-471-38365-1}}</ref> This version of the adjacency list uses more memory than the version in which adjacent vertices are listed directly, but the existence of explicit edge objects allows it extra flexibility in storing additional information about edges. 
 
这个版本的邻接表比直接列出相邻顶点的版本使用更多的内存,但是显示边对象的存在操作可以允许它在存储额外的关于边的信息方面有额外的灵活性。
 
这个版本的邻接表比直接列出相邻顶点的版本使用更多的内存,但是显示边对象的存在操作可以允许它在存储额外的关于边的信息方面有额外的灵活性。
    
==操作==
 
==操作==
操作
      
接表数据结构执行的主要操作是列出给定顶点的邻居列表。使用上面详细说明的任何表示方式,都可以在每个邻居的固定时间内执行。换句话说,列出一个顶点 ''v'' 所有邻居的总时间与 ''v'' 的'''<font color="#ff8000">度 Degree </font>'''成正比。
 
接表数据结构执行的主要操作是列出给定顶点的邻居列表。使用上面详细说明的任何表示方式,都可以在每个邻居的固定时间内执行。换句话说,列出一个顶点 ''v'' 所有邻居的总时间与 ''v'' 的'''<font color="#ff8000">度 Degree </font>'''成正比。
    
也可以使用邻接列表来测试两个指定顶点之间是否存在边,但效率不高。在一个邻接表中,每个顶点的邻域都是不排序的,通过对该顶点的邻域进行顺序搜索,可以按照给定两个顶点的最小阶数按时间比例进行边的存在性测试。如果邻域被表示为一个排序数组,则可以使用二进制搜索,时间与次数的对数成正比。
 
也可以使用邻接列表来测试两个指定顶点之间是否存在边,但效率不高。在一个邻接表中,每个顶点的邻域都是不排序的,通过对该顶点的邻域进行顺序搜索,可以按照给定两个顶点的最小阶数按时间比例进行边的存在性测试。如果邻域被表示为一个排序数组,则可以使用二进制搜索,时间与次数的对数成正比。
 +
    
==权衡==
 
==权衡==
权衡
+
 
    
'''<font color="#ff8000">邻接表</font>'''的主要替代方法是'''<font color="#ff8000">邻接矩阵 Adjacency Matrix </font>''',该矩阵的行和列按顶点索引,其单元格包含一个布尔值,该值指示与单元格的行和列对应的顶点之间是否存在边。对于'''<font color="#ff8000">稀疏图 Sparse Graph </font>'''(大多数顶点对不是由边连接的图),'''<font color="#ff8000">邻接表</font>'''比邻接矩阵(存储为二维数组)更节省空间:'''<font color="#ff8000">邻接表</font>'''的空间使用与图中的边和顶点的数量成正比,而对于以这种方式存储的邻接矩阵,其空间与顶点数的平方成正比。然而,通过使用由顶点对索引的'''<font color="#ff8000">哈希表</font>'''而不是数组,可以更有效地存储邻接矩阵的空间,从而匹配'''<font color="#ff8000">邻接表</font>'''的线性空间使用。
 
'''<font color="#ff8000">邻接表</font>'''的主要替代方法是'''<font color="#ff8000">邻接矩阵 Adjacency Matrix </font>''',该矩阵的行和列按顶点索引,其单元格包含一个布尔值,该值指示与单元格的行和列对应的顶点之间是否存在边。对于'''<font color="#ff8000">稀疏图 Sparse Graph </font>'''(大多数顶点对不是由边连接的图),'''<font color="#ff8000">邻接表</font>'''比邻接矩阵(存储为二维数组)更节省空间:'''<font color="#ff8000">邻接表</font>'''的空间使用与图中的边和顶点的数量成正比,而对于以这种方式存储的邻接矩阵,其空间与顶点数的平方成正比。然而,通过使用由顶点对索引的'''<font color="#ff8000">哈希表</font>'''而不是数组,可以更有效地存储邻接矩阵的空间,从而匹配'''<font color="#ff8000">邻接表</font>'''的线性空间使用。
第73行: 第47行:     
==数据结构==
 
==数据结构==
数据结构
+
 
    
'''<font color="32CD32">作为一种数据结构,邻接表的主要替代方法是邻接矩阵。因为邻接矩阵中的每个条目只占一个比特(bit) ,所以它可以用非常紧凑的方式表示,只占用相邻空间的n<sup>2</sup>/8}}字节,其中n是图的顶点数。除了避免占用空间外,这种紧凑性还支持局部引用locality of reference。</font>'''
 
'''<font color="32CD32">作为一种数据结构,邻接表的主要替代方法是邻接矩阵。因为邻接矩阵中的每个条目只占一个比特(bit) ,所以它可以用非常紧凑的方式表示,只占用相邻空间的n<sup>2</sup>/8}}字节,其中n是图的顶点数。除了避免占用空间外,这种紧凑性还支持局部引用locality of reference。</font>'''
第90行: 第64行:  
==延伸阅读==
 
==延伸阅读==
   −
* {{cite web
+
* {{cite web | author = David Eppstein| year = 1996| title = ICS 161 Lecture Notes: Graph Algorithms| url = http://www.ics.uci.edu/~eppstein/161/960201.html}}
 
  −
  | author = [[David Eppstein]]
  −
 
  −
  | author = David Eppstein
  −
 
  −
作者: David Eppstein
  −
 
  −
  | year = 1996
  −
 
  −
  | year = 1996
  −
 
  −
1996年
  −
 
  −
  | title = ICS 161 Lecture Notes: Graph Algorithms
  −
 
  −
  | title = ICS 161 Lecture Notes: Graph Algorithms
  −
 
  −
161课堂笔记: 图形算法
  −
 
  −
  | url = http://www.ics.uci.edu/~eppstein/161/960201.html}}
  −
 
  −
  | url = http://www.ics.uci.edu/~eppstein/161/960201.html}}
  −
 
  −
Http://www.ics.uci.edu/~eppstein/161/960201.html
  −
 
       
7,129

个编辑

导航菜单