The difficulty of finding all the simple paths using the first depth search?

Thanks to everyone who responds with ideas and alternative solutions. More effective solutions to problems are always welcome, as well as reminders to question my assumptions. However, I would like you to momentarily ignore what problem I am trying to solve with the algorithm, and just help me analyze the great complexity of my algorithm, as I wrote it, all simple paths in the graph using depth search, as described here , and implemented here . Thanks!

Edit: this is homework, but I already submitted this assignment, and I just wanted to know if I answered correctly. I'm a little confused about Big-O complexity when it comes to recursion.


Original question below:

I am trying to find the complexity of searching in all paths according to this algorithm . Given the two peaks, I find all the simple paths between them using a depth search.

I know that the time complexity of DFS is O (V + E), and its spatial complexity is O (V), and my intuition is that the complexity of searching on all roads will be greater, m unable to determine what it will be.

Related SO questions here and here .

Refresh (in response to the comment below):

. , ( 6, ).

+3
4

, /!

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).
+1

- ( ) n . n! , n ^ 2 - , , . ( .) , O (n ^ 2 * n!), , .

?

+5

6 , . , 6 , , - . "6", "# ".

, Breadth First Search (BFS). , (/), ( ), 6 . , , 1 , 2 ,... , , . BFS... , ..

(DFS), DFS , , 6 .

, , , , O (V + E), , , , (, - ), . , , /, , BFS DFS, 6 , .

, DFS O (V + E), O (b ^ d), b - , d - (. Wikipedia_DFS ). , , , ? , (6 , ), ?

, , , . , . , , , ;)

+1

O ((n ^ 2) * depth) algorhitm

  • , . (O (n ^ 2) , , 500 5x facebook). 500 * n .

  • , . O (N ^ 2 * )

, * n

0

Source: https://habr.com/ru/post/1724459/


All Articles