Easy Pandas solution with full explanation | Beats ~93% in runtime
IntuitionIdentifying root nodes and leaf nodes and creating a dataframe containing all nodes in 'id' column and creating a new 'type' column where values will b
# Intuition
Identifying root nodes and leaf nodes and creating a dataframe containing all nodes in 'id' column and creating a new 'type' column where values will be updated from Inner to Root and Leafby comparing them with the created series containing root and leaf nodes.

# Approach
Identify root nodes- p_id should contain Null, Identify leaf nodes- those nodes who don't have any child nodes meaning they should not exist in 'p_id' column since they are no parent of any nodes. Creating a dataframe containing all nodes in 'id' column and 'type' column with 'Inner' assigned to all rows in the column. We are gonna use the series containing root nodes and leaf nodes to update the 'type' column of our dataframe so there was no need to identify Inner nodes.

# Complexity
- Time complexity:
O(N)
#### 325ms

- Space complexity:
O(N)
#### 66.66MB

# Code
```pythondata []
import pandas as pd

def tree_node(tree: pd.DataFrame) -> pd.DataFrame:
    #Identify root node
    root_node = tree[tree['p_id'].isnull()]['id']

    #Identify leaf node
    leaf_node = tree[~tree['id'].isin(tree['p_id'].dropna())]['id'] #it will drop null values since p_id has NaN for the root node, we should dropna() before checking.

    # Identify Inner node / No real need though but for the sake of understanding
    #inner_node = tree[~tree['id'].isin(root_node) & ~tree['id'].isin(leaf_node)]['id']

    result = pd.DataFrame({'id': tree['id'], 'type':'Inner'})

    #Updating each value of the 'type' column 
    #We are going to update to Leaf first because 'leaf_node' series will contain the root node in case the node has no child nodes since there wouldn't be anything else in 'p_id' column so it will cause trouble in result. By Updating to Root later in case of only 1 Node, it updates the already updated root node to it's real type 
    result.loc[result['id'].isin(leaf_node), 'type'] = 'Leaf'
    result.loc[result['id'].isin(root_node), 'type'] = 'Root'
    return result
```
['Pandas']