Binary Tree Nodes

Sort by

recency

|

2483 Discussions

|

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

    with cte_tree as ( select distinct a.n as node from bst a join bst b on a.n=b.p )select (case when p is null and n in (select * from cte_tree) then concat(convert(varchar(4),n),' Root') when n in (select * from cte_tree) then concat(convert(varchar(4),n),' Inner') else concat(convert(varchar(4),n),' Leaf') end) as num from bst order by n

  • + 0 comments

    My SQL:

    SELECT Distinct N, CASE WHEN P is null THEN 'Root' WHEN c.P is null THEN 'Leaf' ELSE 'Inner' END as Value FROM (SELECT A.N as N,B.P as P,A.P as root FROM BST A LEFT OUTER JOIN BST B ON A.N=B.P)as c ORDER BY N

  • + 0 comments

    MS SQL - With join

    WITH Parents AS ( SELECT DISTINCT P FROM BST )

    select b.N, case when b.P is null then 'Root' when b2.P IS NULL THEN 'Leaf' else 'Inner' end from BST as b left join (select P from parents ) as b2 on b.N = b2.P order by b.N

  • + 0 comments

    Okay, so i have a major issue with this sim, it keeps returning wrong code for capitalization? WTH? my code was right but it returned 'leaf' instead of 'Leaf' and it kept erroring out.