chapter_graph/graph_operations/ #305
Replies: 66 comments 71 replies
-
大佬,在GraphAdjMat 中
这里的edges 能否对应图给个具体的值,这里想不明白。谢谢! |
Beta Was this translation helpful? Give feedback.
-
Hello, Baby K! 有一个微不足道的想法,邻接矩阵 |
Beta Was this translation helpful? Give feedback.
-
自定义Vertex对象,将该节点的邻接点列表包含其中,可以省一点空间?不知是否会影响效率 public class Vertex {
int id;
int value;
List<Vertex> neighbors; // 节点邻居列表
...
} |
Beta Was this translation helpful? Give feedback.
-
在使用邻接表添加边这里有问题, 如果边已经存在那么他还是会添加进去
我做的修改是
|
Beta Was this translation helpful? Give feedback.
-
邻接表删除顶点的复杂度为什么是 O(n + m) 呢? |
Beta Was this translation helpful? Give feedback.
-
Hello,K神. 请问一下/添加顶点/里面的emplace_back(n, 0)如何理解?不太懂
|
Beta Was this translation helpful? Give feedback.
-
hii, 不太理解用hashtable实现的删除边、删除节点的时间复杂度为什么分别是O(1), O(n)?
|
Beta Was this translation helpful? Give feedback.
-
// 请注意,edges 元素代表顶点索引,即对应 vertices 元素索引 |
Beta Was this translation helpful? Give feedback.
-
不好意思,初学者想问一下,那个java实现的邻接表里,关于添加节点的代码 // 遍历其他顶点的链表,删除所有包含 vet 的边
for (List<Vertex> list : adjList.values()) {
list.remove(vet);
} remove只会删除list里第一次出现的vet,要是假如出现了重边,即添加了两次addEdge(n6, n7); // 遍历其他顶点的链表,删除所有包含 vet 的边
for (List<Vertex> list : graph.values())
for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(vet))
{ list.remove(i);//使用list.remove(i)删除节点
i--;//并将索引i递减以保持正确的循环遍历
}
} 这样也行吧,感觉这两种存储方式都没考虑到重边 |
Beta Was this translation helpful? Give feedback.
-
hi,想问一下在用链表实现的邻接表中,添加边的复杂度不应该是O(n)吗,因为要遍历找到要添加边的顶点,初学者/(ㄒoㄒ)/~~ |
Beta Was this translation helpful? Give feedback.
-
对不起我比较笨, 我想请问一下java的vertex类是怎么实现的呢? |
Beta Was this translation helpful? Give feedback.
-
是不是释放二级指针p总是需要free(p[0]);free(p);这样两个语句?我看C语言的邻接矩阵实现中添加节点操作用到这种操作,但是后面,邻接列表的添加顶点操作只用了free(t->verticesList); 来释放内存,这两者之间有什么差别吗? |
Beta Was this translation helpful? Give feedback.
-
self.adj_list = dictVertex, list[Vertex],这段代码不是建立了一个字典吗?不应该是"{}"吗? |
Beta Was this translation helpful? Give feedback.
-
”添加顶点:在邻接表中添加一个链表,并将新增顶点作为链表头节点“。我并没有找到有关链表的实现,请问是哪一步? |
Beta Was this translation helpful? Give feedback.
-
graph_adjacency_list.c有一处注释错误,位于删除顶点函数中
这个注释应该是 |
Beta Was this translation helpful? Give feedback.
-
C环境下基于邻接表的实现的代码中,那个自定义Vertex类型具体是什么组成呢?代码里没有具体说明。 |
Beta Was this translation helpful? Give feedback.
-
是否在最后一行末尾多添加了一个0呢?添加行的时候最后一行已有n个0了 |
Beta Was this translation helpful? Give feedback.
-
看了半天才知道这里的list是hashSet,所以判断顶点是否邻接的效率是O(1) |
Beta Was this translation helpful? Give feedback.
-
在邻接矩阵的删除顶点中,还有种方法就是将该顶点对应的行和列都置为0,然后增加一个变量用来表示这个顶点是不是为空即可,可以降低时间复杂度 |
Beta Was this translation helpful? Give feedback.
-
邻接矩阵和邻接表操作图示tab切换好像会互相影响 |
Beta Was this translation helpful? Give feedback.
-
有点看不懂了,┭┮﹏┭┮ |
Beta Was this translation helpful? Give feedback.
-
根据我老师和Wikipedia的说法,邻接矩阵中添加顶点的时间复杂度是O(n^2) |
Beta Was this translation helpful? Give feedback.
-
java的代码里面的
可以修改
输出的内容
|
Beta Was this translation helpful? Give feedback.
-
邻接表Java写法顶点类是不是需要重写hashcode方法,相同值的顶点算是同一个 |
Beta Was this translation helpful? Give feedback.
-
我去这个图和哪个树一样,有点难懂 |
Beta Was this translation helpful? Give feedback.
-
基于邻接矩阵的实现中 void printVector(const vector<int>& vec) {
cout << "[";
for (size_t i = 0; i < vec.size(); i++) {
cout << vec[i];
if (i != vec.size() - 1) cout << ", ";
}
cout << "]" << endl;
}
void printVectorMatrix(const vector<vector<int>>& mat) {
for (const auto& row : mat) {
for (size_t i = 0; i < row.size(); i++) {
cout << row[i];
if (i != row.size() - 1) cout << " ";
}
cout << endl;
}
}
|
Beta Was this translation helpful? Give feedback.
-
文中提到基于邻接表实现时,删除顶点需要遍历整个邻接表,然后删除对应的顶点和边。 |
Beta Was this translation helpful? Give feedback.
-
for edge in edges: |
Beta Was this translation helpful? Give feedback.
-
Hi, 9.2.2 基于邻接表的实现 这里对于各种操作的复杂度分析,是关于 用链表实现的邻接表的分析吧?可是下面的graph_adjacency_list.cs却是用哈希表实现的邻接表,有没有用链表实现的邻接表的代码呢?我看的是c#代码。 |
Beta Was this translation helpful? Give feedback.
-
上面提到:如果每个顶点都是唯一的 Vertex 实例,删除某一顶点之后就无须改动其他顶点了。 |
Beta Was this translation helpful? Give feedback.
-
chapter_graph/graph_operations/
一本动画图解、能运行、可提问的数据结构与算法入门书
https://www.hello-algo.com/chapter_graph/graph_operations/
Beta Was this translation helpful? Give feedback.
All reactions