Binary Tree Nodes

Sort by

recency

|

2427 Discussions

|

  • + 0 comments

    select n, case when p is null then "Root" when n in (select p from bst) then "Inner"
    else "Leaf" end from bst order by n asc;

  • + 0 comments

    with temp as (select distinct p,count(p) cnt from BST group by p having cnt>=2 ) select n, case when p is null then "Root" when n not in (select p from temp) then "Leaf" else "Inner" end as status from BST order by n

  • + 0 comments

    select N, CASE WHEN P is NULL THEN 'Root' WHEN N NOT IN(SELECT P FROM BST WHERE P IS NOT NULL) THEN 'Leaf' else 'Inner' END as type from bst ORDER BY N;

  • + 0 comments
    SELECT
        [N],
        CASE 
            WHEN [P] IS NULL THEN 'Root'
            WHEN [N] NOT IN (
                SELECT 
                    DISTINCT [P] 
                FROM BST 
                WHERE [P] IS NOT NULL
            ) THEN 'Leaf'
            ELSE 'Inner'
        END AS NodeType
    FROM BST
    ORDER BY [N];
    
  • + 0 comments

    select N, case when P IS NULL then 'Root' when N IN (select distinct P from BST where P is not null) then 'Inner'
    else 'Leaf' end as node_type from BST order by N;