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
|
2427 Discussions
|
Please Login in order to post a comment
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;
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;