发现使用深度优先搜索所有简单路径的复杂性?

编程入门 行业动态 更新时间:2024-10-23 09:34:14
本文介绍了发现使用深度优先搜索所有简单路径的复杂性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

感谢的想法和替代解决方案大家答复。解决问题总是受欢迎的更有效的方法,以及提醒怀疑我的假设。不过,我想你忽略了一会儿什么问题,我试图解决的算法,只是帮我分析一下大哦,我复杂的算法,因为我已经写了 - 一个所有简单路径在使用深度限制搜索的描述这里图,并实施here.谢谢!

Thanks to everyone replying with ideas and alternate solutions. More efficient ways of solving problems are always welcome, as well as reminders to question my assumptions. That said, I'd like you to ignore for a moment what problem I'm trying to solve with the algorithm, and just help me analyze the big-Oh complexity of my algorithm as I've written it -- an all simple paths in a graph using depth-limited search as described here, and implemented here. Thanks!

编辑:这是家庭作业,但我已提交了这项任务,我只是想知道,如果我的回答是正确的。我有点儿困惑过大O的复杂性涉及递归时。

This is homework, but I've already submitted this assignment and I'd just like to know if my answer correct. I get a little confused over Big-O complexity when recursion is involved.

低于原题:

我试图找到的全部路径复杂搜索所给出的的这个算法。 给定两个顶点,我发现它们之间的所有简单路径使用深度优先搜索。

I'm trying to find the complexity of an all-paths search as given by this algorithm. Given two vertices, I'm finding all simple paths between them using a depth-first search.

我知道DFS的时间复杂度为O(V + E),其空间复杂度为O(V),而我的直觉是,一个全路径的复杂性搜索将不止于此,但我中号无法确定这将是。

I know that the time complexity of DFS is O(V+E) and its space complexity is O(V), and my intuition is that the complexity of an all-paths search will be more than that, but I'm unable to determine what it will be.

相关SO问题here和here.

更新(根据下文评论):

Update (in response to a comment below):

我要解决的贝肯数的问题。这通常需要找到一个对演员之间的分离程度最低的,但我必须找到所有分离度(现在,不到6,但可以改变)。

I'm trying to solve the six degrees of Kevin Bacon problem. This generally requires finding the lowest degree of separation between a pair of actors, but I have to find ALL degrees of separation (for now, less than 6, but this can change).

推荐答案

回答我的问题与我的分析,请评论/正确的!

Answering my own question with my analysis, please comment/correct!

The algorithm is simplified and analyzed as follows: (Note: here MAXDEPTH is the maximum degrees of separation to search for, default 6) 1. For the current vertex, get neighbors (amortized O(1)) 2. For every neighbor, do the following [O(b), where b is the branching factor, or the avg. number of neighbors of a vertex] 2.1. Check if already visited [O(MAXDEPTH), since it’s a linked list of max size MAXDEPTH) 2.2. Append path to paths list [amortized O(1)] 3. End for 4. Do the following MAXDEPTH times [O(MAXDEPTH)] 4.1. For every neighbor do the following [O(b)] 4.1.1. Check if already visited [O(MAXDEPTH)] 4.1.2. Add to visited list [O(1)] 4.1.3. Recursively call search again [becomes O(MAXDEPTH*b)] 4.1.4. Delete from visited list [O(1)] 4.2 End for /* Neighbor */ 5. End loop /* MAXDEPTH */ Thus, the complexity becomes O((MAXDEPTH*b)^MAXDEPTH).

更多推荐

发现使用深度优先搜索所有简单路径的复杂性?

本文发布于:2023-11-30 21:02:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂性   路径   深度   简单   发现

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!