Binary Tree Nodes

Sort by

recency

|

2429 Discussions

|

  • + 0 comments

    select N, case when P is NULL then 'Root' when N in (select distinct P from BST) then 'Inner' else 'Leaf' end as X from BST order by N;

  • + 0 comments
    SELECT t.N,
          CASE
              WHEN t.N = (SELECT N FROM BST WHERE P is NULL) THEN "Root"
              WHEN COUNT(t.N)>1 THEN "Inner"
              WHEN COUNT(t.N) = 1 THEN "Leaf"
              END
    FROM (
        SELECT N FROM BST
        UNION ALL
        SELECT P FROM BST
    ) AS t
    WHERE t.N IS NOT NULL
    GROUP BY (t.N)
    ORDER BY t.N
    
  • + 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;