We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Advanced Select
- Binary Tree Nodes
- Discussions
Binary Tree Nodes
Binary Tree Nodes
Sort by
recency
|
2429 Discussions
|
Please Login in order to post a comment
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;
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;
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
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;