简体   繁体   English

有关在C ++中实现图形的问题

[英]Questions regarding Implementation of graph in c++

I am learning to implement a graph in C++ hence i read Wikipedia entry and found out there are two commonly used methods : Adjacency list and Adjacency matrix . 我正在学习用C ++实现图形,因此我阅读了Wikipedia条目 ,发现有两种常用的方法: 邻接表邻接矩阵 I understand the tradeoff in space between Adjacency list and Adjacency matrix . 我了解邻接列表邻接矩阵之间在空间上的权衡。

I have three questions 我有三个问题

1) Are there any more ways other than the two listed above to implement the graph ?? 1)除了上面列出的两种以外,还有其他方法可以实现该图吗?

2) What are the differences between using the different data structures ??? 2)使用不同的数据结构之间有什么区别? Linked List VS Vector VS Map 链表VS向量VS映射

3) What does the following paragraph mean in the article 3)下一段在文章中是什么意思

The other significant difference between adjacency lists and adjacency matrices is in the efficiency of the operations they perform. 邻接表和邻接矩阵之间的另一个重要区别是它们执行的操作效率。 In an adjacency list, the neighbors of each vertex may be listed efficiently, in time proportional to the degree of the vertex. 在邻接表中,每个顶点的邻居可以按与顶点度成比例的时间有效地列出。 In an adjacency matrix, this operation takes time proportional to the number of vertices in the graph, which may be significantly higher than the degree. 在邻接矩阵中,此操作所花费的时间与图中的顶点数量成正比,而该数量可能远高于度。 On the other hand, the adjacency matrix allows testing whether two vertices are adjacent to each other in constant time; 另一方面,邻接矩阵可以测试两个顶点是否在恒定时间内彼此相邻; the adjacency list is slower to support this operation. 邻接表较慢以支持此操作。

What does efficiency of the operations they perform refer to ?? efficiency of the operations they perform指的是什么? What type of operations??? 什么类型的操作???

What does two vertices are adjacent to each other in constant time mean and are there any practical usage of knowing if two vertices are adjacent to each other??? two vertices are adjacent to each other in constant time意味着什么?知道两个顶点是否彼此相邻有什么实际用途?

  1. Yes, you can also implement it explicitly using pointers to other nodes. 是的,您还可以使用指向其他节点的指针来显式实现它。
  2. listS consume more memory and are not random access, but handles (iterators) to elements stay valid on insertion and deletion; listS消耗更多的内存,并且不是随机访问的,但是元素的句柄(迭代器)在插入和删除时仍然有效; vectorS are memory efficient, random access, but invalidate handles (iterators) get invalidated on insertion and deletion; vectorS是内存有效的随机访问,但是无效句柄(迭代器)在插入和删除时会失效; mapS usually consume more memory, don't iterate slower, handles (iterators) usually stay valid on insertion and deletion; mapS通常会消耗更多的内存,而不要迭代太慢,句柄(迭代器)通常在插入和删除时仍然有效; look up of child nodes can be very fast. 查找子节点可以非常快。 This is really the general difference between those containers and not very graph specific. 这实际上是这些容器之间的一般区别,并非特定于图形。
  3. The operations are explicitly given: listing neighbors and testing adjacency. 明确给出了这些操作:列出邻居和测试邻接关系。 Both have different complexities depending on the graph implementation. 两者都有不同的复杂度,具体取决于图形实现。

two vertices are adjacent to each other just means that there is a direct edge between two nodes. two vertices are adjacent to each other仅表示两个节点之间存在直接边缘。 To do that in constant time means that the operation is independent of how many neighbors each node has. 以恒定的时间执行此操作意味着该操作与每个节点具有多少个邻居无关。 As practical purposes go: Yes, tons of them. 按照实际目的去做:是的,很多。 You might want to know if a city is connected to another city by a direct street. 您可能想知道一个城市是否通过直达街道与另一个城市相连。 You might want to know if two vertices have an edge before collapsing it etc. 在折叠等之前,您可能想知道两个顶点是否具有边。

As you are talking C++ I would highly encourage you to have a look at some of the good graph libraries like Boost.Graph or Lemon . 在您谈论C ++时,我强烈建议您看一下Boost.GraphLemon等一些好的图形库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM