Graph Search II
HardProblem
You are given an undirected graph with nodes. From every node, you are able to access any other node (not including itself), all with an equal probability of . What is the expected number of steps to reach all nodes at least once (rounded to the nearest step)?
Original Problem Link: Click here
Solution
It is clear that we must deal with conditional expectations in the given problem. As a recap, using conditional expectations, we get
Step 1: Formulating Recursive Relation
Lets denote as the expected number of steps required to visit un-visited nodes. Note that this does not count our current node.
Now, when the simulation starts, you will take 1 step and enter the first node. After this, 10 nodes remain to be visited. Now, when you take the next path, you will definitely end up on a new node (as all other nodes are unvisited). Lets say this step is done. Now, you are on your 2nd node, with 9 unvisited, and 1 visited. Now, with probability , you may end up on an already visited note, and with probability , you may end up on a new un-visited node.
Therefore, for our second iteration, we could write
Note that the + 1 is added in each term as you take one step to reach there.
Step 2: Generalizing the Relation
After a few iterations, it will be clear that the relation can be generalized as follows -
"If you must visit n nodes more, then with probability you will reach an already visited node (where you will take steps), and with probability you will visit a new node (where you will take steps)."
Therefore,
On simplification, we get
Step 3: Solving Recursion
Now that we have established the recurrence relation
we can solve it iteratively to find a general expression for , which is the expected number of steps to visit all 10 new nodes at least once. Note that we will also need to add 1 to this, as that will mark our "first" step into the graph (because its only on our first node we need to walk steps more. We must include that first step to our first node as well).
First, note that the recurrence starts with since when no nodes are unvisited, no more steps are required.
Now, let’s compute the values step by step:
-
For :
-
For :
-
For :
-
For :
-
For :
-
For :
-
For :
-
For :
-
For :
-
Finally, for :
As discussed earlier, we must add 1 to account for our first step on the 11th node (from where we start exploring the remaining 10 nodes). Therefore,