|| EASY SOLUTION IN MYSQL DATABASE ||
Intuition\n Describe your first thoughts on how to solve this problem. \nSELECT id, CASE WHEN p_id IS NULL THEN \'Root\' WHEN id IN (SELECT p_id FROM Tree) THEN
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSELECT id, CASE WHEN p_id IS NULL THEN \'Root\' WHEN id IN (SELECT p_id FROM Tree) THEN \'Inner\' ELSE \'Leaf\' END AS type FROM Tree\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMy approach was to use a CASE statement in the SELECT clause to classify each node based on its characteristics. I used three conditions to check if a node is the root, an inner node, or a leaf node. If the p_id is NULL, it\'s the root node. If the id exists in the p_id column of the Tree table, it\'s an inner node. Otherwise, it\'s a leaf node.\n# Complexity\n- Time complexity:\nTime complexity: $$O(n)$$\n- Space complexity:\nSpace complexity: $$O(n)$$,\n# Code\n```\n# Write your MySQL query statement below\nSELECT \n    id, \n    CASE \n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN (SELECT p_id FROM Tree) THEN \'Inner\'\n        ELSE \'Leaf\'\n    END AS type\nFROM \n    Tree\n```
['Database', 'MySQL']