It is not hard to show that, for any graph \(G\) and tree decomposition \((T,B)\) of \(G\text{,}\) there exists a tree decomposition \((T',B')\) of \(G\) with \(|V(T')|\leq |V(G)|\) of the same width as \((T,B)\text{.}\) So, we assume that \((T,B)\) satisfies \(|V(T)|\leq |V(G)|\text{.}\) Let \(r\) be an arbitrary root of \(T\) and orient all edges of \(T\) away from \(r\text{.}\) The out-neighbours of a vertex \(x\) in \(T\) are called the children of \(x\) and the vertices that are reachable by directed paths starting at \(x\) are its descendants. The subtree rooted at \(x\) is the subtree of \(T\) induced by \(x\) and all of its descendants.
Now, for each pair \((x,S)\) where \(x\in V(T)\) and \(S\subseteq B(x)\text{,}\) initialize \(mw(x,S):=\text{null}\text{.}\) Here, the letters \(mw\) stand for “max weight;” it will correspond to the highest weight of a stable set containing \(S\) in the subgraph of \(G\) induced by the vertices in the bags in the subtree rooted at \(x\text{.}\) Also, for each arc \(xy\) of \(T\) and set \(S\subseteq B(x)\text{,}\) initialize \(be(xy,S):=\text{null}\text{.}\) Here, \(be\) stands for “best extension” and will describe the intersection of \(B(y)\) with a highest weight stable set containing \(S\) in the subgraph of \(G\) induced by the vertices in the bags in the subtree rooted at \(x\text{.}\) This will play the role of the predecessor function in the previous section and will allow us to construct the maximum weight stable set in the end. Note that, since each bag has cardinality at most \(k+1\) and \(|V(T)|\leq |V(G)|\text{,}\) the domains of the functions \(mw\) and \(be\) each have cardinality at most \(2^{k+1}|V(G)|\text{.}\) Now, to solve the problem, we run the algorithm \(\text{SubtreeStableSet}(r,mw,be)\text{,}\) which is described below in the more general case where \(r\) is replaced by any vertex \(x\) of the tree.
Algorithm 5.2.4. \(\text{SubtreeStableSet}(x,mw,be)\).
Since the bags have size at most \(k+1=O(1)\text{,}\) the number of steps of this algorithm that involve any given vertex or arc of the tree take time \(O(1)\text{.}\) So, the total running time is \(O(|V(T)|)=O(|V(G)|)\text{.}\)
We claim that, after running this algorithm at the root \(r\text{,}\) we now have enough information to find the maximum weight stable set in the graph. Indeed, let \(S_r\) be the subset of \(B(r)\) for which \(mw(r,S)\) is maximized. Then, for each arc \(xy\) of the tree, starting at the top, we define \(S_y=be(xy,S_x)\text{.}\) After doing this for all arcs, we let
\begin{equation*}
S:=\bigcup_{x\in V(T)}S_x.
\end{equation*}
We claim that \(S\) is a maximum weight stable set. First, let us explain why it is a stable set. Suppose there is an adjacent pair \(u,v\in S\text{.}\) Let \(x,y\in V(T)\) such that \(u\in S_x\) and \(v\in S_y\) and let \(z\) be the most recent common ancestor of \(x\) and \(y\text{.}\) Since the subtrees \(T_u\) and \(T_v\) must intersect and the unique path from \(x\) to \(y\) in \(T\) passes through \(z\text{,}\) we must have that \(u,v\in B(z)\text{.}\) Also, by construction, the stable sets corresponding to adjacent vertices \(a,b\) of the tree must agree on all of the vertices that are common to the two bags (i.e. if \(w\in B(a)\cap B(b)\text{,}\) then either \(w\in S_a\cap S_b\) or \(w\notin S_a\cup S_b\)). By following along a path from \(x\) to \(z\) and a path from \(y\) to \(z\text{,}\) we get that \(u,v\in S_z\text{.}\) However, this cannot happen as \(S_z\) is a stable set for each vertex of the tree, by construction. So, it is a stable set.
Its fairly evident, if you sit and think about it, that, for every \(x\in V(T)\) and \(S\subseteq B(x)\text{,}\) this algorithm identifies the maximum weight of a stable set containing \(S\) in the graph induced by the bags in the subtree rooted at \(x\text{.}\) Its certainly true at the leaves of the tree and, if you think about how the solutions at the children of \(x\) are combined at \(x\text{,}\) its not hard to see that its correct. I may try to explain this better later, but hopefully this explanation suffices for now!