chapter_graph/graph_operations/ #305
Replies: 72 comments 77 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.
-
根据我老师和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.
-
这里会因为indexOf没有找到返回-1,从而错误删除了数组末尾的元素
|
Beta Was this translation helpful? Give feedback.
-
我有一个想法,给邻接表添加边加一句判断这条边是否已经存在的语句,比如 |
Beta Was this translation helpful? Give feedback.
-
大神,基于哈希表的领接表,删除边的复杂度为啥是O(1)呢?如果我没理解错的话,文中用的python代码是用哈希表实现的,然后删除边的复杂度好像是O(m)呀,因为要遍历value这个list的所有vertex然后删除它,所以是O(m)。我哪儿理解错了么 |
Beta Was this translation helpful? Give feedback.
-
day07 |
Beta Was this translation helpful? Give feedback.
-
疑问:删除顶点:需遍历整个邻接表,删除包含指定顶点的所有边,使用 |
Beta Was this translation helpful? Give feedback.
-
希望可以出个伪代码呀,一是看一长串代码挺费时的,二是想先理解一下思路,自己写一写呢 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
chapter_graph/graph_operations/
一本动画图解、能运行、可提问的数据结构与算法入门书
https://www.hello-algo.com/chapter_graph/graph_operations/
Beta Was this translation helpful? Give feedback.
All reactions