Binary Tree Nodes

  • + 0 comments

    tried in oracle let me know if this cna optimized further.

    select num, case when (select N from bst where p is null)=num then 'Root' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)>1 then 'Inner' when (select count(N) from bst where n=num)=1 and (select count(P) from bst where p=num)=0 then 'Leaf' end from ( select N num from bst union select P num from bst) where num is not null;