Example 7 For a natural number $k, g(k)$ represents the greatest odd divisor of $k$ (for example, $g(3)=3, g(20)=5$), find $g(1)+$ $g(2)+g(3)+\cdots+g\left(2^{n}\right.$ ) (where $n \in N$ ).
Let $S_{n}=g(1)+g(2)+g(3)+\cdots+g\left(2^{n}\right)$. It is easy to see that $S_{1}=g(1)+g\left(2^{1}\right)=2$.

From the definition of $g(k)$: when $k$ is odd, $g(k)=k$; when $k$ is even, i.e., $k=2 m(m \in N)$, $g(k)=g(m)$.
Thus,
$$
\begin{aligned}
S_{n}= & {\left[g(1)+g(3)+\cdots+g\left(2^{n}-1\right)\right]+} \\
& {\left[g(2)+g(4)+\cdots+g\left(2^{n}\right)\right] } \\
= & {\left.\left[1+3+\cdots+2^{n}-1\right)\right]+g(1)+g(2) } \\
& \left.+\cdots+g\left(2^{n-1}\right)\right] \\
= & \left(2^{n-1}\right)^{2}+S_{n-1},
\end{aligned}
$$

Thus, $S_{n}-S_{n-1}=4^{n-1}$.
Therefore, $\sum_{i=2}^{n}\left(S_{i}-S_{i-1}\right)=\sum_{i=2}^{n} 4^{i-1}$,

which means $S_{n}=S_{1}+\sum_{i=2}^{n} 4^{i-1}=\frac{4^{n}+2}{3}$.