Random Walk on Tree
Given a rooted tree, there is a coin on some node of the tree. At a certain moment, the coin moves to an adjacent node with equal probability. Find the expected distance for the coin to move to an adjacent node.
Required Definitions
- \(T=(V,E)\): The tree under discussion
- \(d(u)\): Degree of node \(u\)
- \(w(u,v)\): Edge weight between node \(u\) and node \(v\)
- \(p_u\): Parent node of node \(u\)
- \(\textit{root}\): Root node of the tree
- \(\textit{son}_u\): Set of child nodes of node \(u\)
- \(\textit{sibling}_u\): Set of sibling nodes of node \(u\)
Expected Distance to Move to the Parent Node
Let \(f(u)\) denote the expected distance for node \(u\) to move to its parent node \(p_u\). Then:
The first part of the numerator represents moving directly to the parent node, while the second part represents moving to a child node first, then moving back from that child node, and finally moving to the parent node. The denominator \(d(u)\) indicates that the probability of moving from node \(u\) to any of its adjacent nodes is equal.
Simplify as follows:
For a leaf node \(l\), the initial state is \(f(l) = w(p_l, l)\).
When all edge weights in the tree are \(1\), the above formula simplifies to:
This is the sum of the degrees of all nodes in the subtree of \(u\), which is also twice the size of the subtree of \(u\) minus \(1\) (each node has exactly one edge connecting to its parent, and except for the edge between \(u\) and \(p_u\), which contributes only \(1\) to the degree, every other edge contributes \(2\) to the degree).
Expected Distance to Move to a Child Node
Let \(g(u)\) denote the expected distance for node \(p_u\) to move to its child node \(u\). Then:
The first part of the numerator represents moving directly to the child node \(u\). The second part represents moving to the parent node first, then moving back from the parent node, and finally moving to node \(u\). The third part represents moving to a sibling node of \(u\) first, then moving back from that sibling node, and finally moving to node \(u\). The denominator \(d(p_u)\) indicates that the probability of moving from node \(p_u\) to any of its adjacent nodes is equal.
Simplify as follows:
The initial state is \(g(\text{root}) = 0\).
Code Implementation (Example for Unweighted Tree)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用