Graph Search I
HardProblem
You are given an undirected graph with nodes. From every node, you are able to access any other node (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, 9 nodes remain to be visited. Now, when you take the next path, either you end up on the same node (with probability ) or you end up on a new node (with probability ). Note that, when you enter a new node, now the remaining expected number of steps will be , as you have already visited 2 nodes.
Therefore, for our first 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 9 new nodes. Note that we will need to add one more step, which is to "start" the simulation, i.e. enter the graph in the first place, and visit our first node.
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 our final answer, as discussed above, we have: