How to display top level categories and sub-categories in magento

Here, we will explain How to display top level categories and sub-categories in magento?

The code for displaying top level categories in magento:

The code for displaying top level categories and sub-categories in magento: