The minimum spanning tree, based on the concept of ultrametricity, is constructed from the correlation matrix of stock returns and provides a meaningful economic taxonomy of the stock market. In order to study the dynamics of this asset tree we characterise it by its normalised length and by the mean occupation layer, as measured from an appropriately chosen centre called the 'central node'. We show how the tree evolves over time, and how it shrinks strongly, in particular, during a stock market crisis. We then demonstrate that the assets of the optimal Markowitz portfolio lie practically at all times on the outskirts of the tree. We also show that the normalised tree length and the investment diversification potential are very strongly correlated.