TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Possibly all the ways to get loop-finding in graphs wrong

230 点作者 matt_d9 个月前

13 条评论

xelxebar9 个月前
First time I&#x27;ve heard of the disjoint-set data structure. For a DSF implementation, Wikipedia [0] gives the wildest asymptotic complexity I&#x27;ve seen, using the <i>inverse Ackermann function</i>! &quot;Almost constant time&quot; indeed.<p>[0]:<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Disjoint-set_data_structure" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Disjoint-set_data_structure</a>
评论 #41509519 未加载
评论 #41512384 未加载
评论 #41512756 未加载
评论 #41516797 未加载
评论 #41517330 未加载
karmakaze9 个月前
I&#x27;ve always thought Floyd&#x27;s tortoise and hare[0] algorithm was handy as it can find a cycle in a DAG with low memory usage.<p>[0] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cycle_detection#Floyd&#x27;s_tortoise_and_hare" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cycle_detection#Floyd&#x27;s_tortoi...</a>
评论 #41512919 未加载
评论 #41512906 未加载
zeroonetwothree9 个月前
This problem is called “online cycle detection” in the literature. You can search for various better algorithms that have been developed.
评论 #41511910 未加载
tromp9 个月前
The problem of finding cycles in (pseudo randomly generated) graphs is actually one of the first examples of an <i>asymmetric</i> Proof-of-Work puzzle [1]. Asymmetry means that while finding a cycle takes a lot of memory and effort, a solution can be verified instantly.<p>Several of the suggested algorithms were in fact implemented in the various Cuckoo Cycle solvers [2]. But by maintaining directed paths, my union-find based algorithm <i>did</i> identify the entire cycle and not just the cycle completing edge [1] (implemented in [3]).<p>This algorithm suffers from three problems though. One, it only finds one among a set of interconnected cycles. Second, it&#x27;s rather slow, being latency bound by the random memory accesses. Third, it uses much more memory than needed.<p>So repeatedly trimming edges with only one endpoint is a much faster approach. And for the random graphs that the PoW generates, it can be done using only 1 bit per edge to record if it&#x27;s been trimmed.<p>Once sufficiently trimmed, a loop tracing algorithm (like [4] for the Cuckatoo Cycle variant) can find <i>all</i> remaining (simple) cycles.<p>[1] <a href="https:&#x2F;&#x2F;www.semanticscholar.org&#x2F;paper&#x2F;Cuckoo-Cycle%3A-A-Memory-Bound-Graph-Theoretic-Tromp&#x2F;cce6bb06d77da858c547955a4336ced1de1a1091" rel="nofollow">https:&#x2F;&#x2F;www.semanticscholar.org&#x2F;paper&#x2F;Cuckoo-Cycle%3A-A-Memo...</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo">https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo&#x2F;blob&#x2F;master&#x2F;src&#x2F;cuckoo&#x2F;cyclebase.hpp">https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo&#x2F;blob&#x2F;master&#x2F;src&#x2F;cuckoo&#x2F;cycle...</a><p>[4] <a href="https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo&#x2F;blob&#x2F;master&#x2F;src&#x2F;cuckatoo&#x2F;graph.hpp">https:&#x2F;&#x2F;github.com&#x2F;tromp&#x2F;cuckoo&#x2F;blob&#x2F;master&#x2F;src&#x2F;cuckatoo&#x2F;gra...</a>
评论 #41509858 未加载
评论 #41510034 未加载
评论 #41511203 未加载
JohnVideogames9 个月前
I had to tackle a problem much like this one when analysing the polygons in planar graphs (analysis of planar chemical networks). A fun approach I found was to use a Delaunay triangulation (the dual of a Voronoi diagram; draw the Voronoi polygons and join their centres if they share an edge). Then join the triangles into larger polygons by removing edges that are in the Delaunay triangulation but not in your original planar graph. Once you&#x27;ve got no more edges to remove you&#x27;ve got all the polygons in the graph and convenient triangles for rendering &#x2F; analysis.<p>For planar graphs on the surface of a torus, like they faced here, I just ended up adding extra images of the central unit cell, and then removing the excess. Not elegant (lots of weird corner cases) but convenient for visualisation.
评论 #41510443 未加载
评论 #41510065 未加载
yohannesk9 个月前
If this article triggers a desire to work on an actual problem with graphs try <a href="https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;freedom-trail" rel="nofollow">https:&#x2F;&#x2F;leetcode.com&#x2F;problems&#x2F;freedom-trail</a>
评论 #41518014 未加载
vouwfietsman9 个月前
Funny I&#x27;ve had to do this occasionally and I always do the following: for each edge E, attempt to construct a clockwise loop from that edge by traversing each vertex and picking the edge that is &quot;most clockwise&quot; compared to the incoming edge. Converse for counter clockwise. This gives you, for each edge, the two loops the edge is a part of (if they exist).<p>It sounds horribly slow, but isn&#x27;t because the loop finding process for one edge can mark all edges it traverses as either being on the same loop, or not having a loop, for the orientation its checking. These edges can be skipped henceforth.<p>This does not find all loops, only the smallest disjoint loops (as every edge is at most part of two disjoint loops). But basically results in a similar planar &quot;face&quot; partition the author describes.<p>Its not clear to me whether my approach does not work (perhaps the angle compares fail on a torus? I&#x27;ve never had to deal with torii), or simply isn&#x27;t suited because it misses some loops, but I thought I&#x27;d share it anyway :-)
评论 #41513207 未加载
评论 #41514415 未加载
Hendrikto9 个月前
I think it is strange that there is no mention of either time or space complexity, in an article about graph algorithms.<p>If you don‘t need to be efficient, any problem is relatively easy to solve.
评论 #41509699 未加载
emmanueloga_9 个月前
I thought I recognized the name; this article was written by the putty guy [1] :-)<p>---<p>1: <a href="https:&#x2F;&#x2F;www.chiark.greenend.org.uk&#x2F;~sgtatham&#x2F;putty&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.chiark.greenend.org.uk&#x2F;~sgtatham&#x2F;putty&#x2F;</a>
sim7c009 个月前
one of the more interesting reads ive had on here so firstly thanks for that! love all the explanations of the intermediate solutions. ive been working lately with graphs to deduce network topologies and finding loops is one of my problems. excited to learn about the final answer, and happy to see it involves spanning tree :&#x27;) kind of saves me reading through how that protocol works (or should work) so i can get on with implementing it! saving me likely all sorts of wrong solutions &lt;3 thanks!
评论 #41526117 未加载
penguin_booze9 个月前
I&#x27;m curious: If I were to share the same link again now, I&#x27;ll be forwarded to the latest submission instead. Interestingly, this link was shared twice in the past few days (click the &quot;past&quot; link above - and, yes, one of the submitters was I). How, then, was it that neither of the recent submitters, including myself, were forwarded to the latest at the time, but instead new submissions were created?
wonnage9 个月前
Any time you’re looking for a graph algorithm there’s a pretty good chance Tarjan’s name is on it
评论 #41509688 未加载
devit9 个月前
Seems like a trivial problem to me.<p>If the graph is directed, do an SCC decomposition in linear time using a graph library and then any SCC with size more than one has at least a loop, trivially extracted by following any edges in the SCC.<p>If the graph is undirected, compute a spanning tree in linear time using a graph library and then any edge outside the tree forms a loop, again trivially extractable from the edge and the paths from its endpoints to their least common ancestor in the tree.<p>Since those algorithms are already asymptotically optimal, it&#x27;s just an engineering problem of finding the solution with the best constant factor given the precise data structures and goal in question.
评论 #41511668 未加载
评论 #41511800 未加载
评论 #41518110 未加载