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
|
2391 Discussions
|
Please Login in order to post a comment
select distinct b1.N, case when b2.N is null AND b1.P is not null then 'Leaf' when b2.N is not null and b1.P is not null then 'Inner' when b1.P is null then 'Root' end as quoted
from BST b1 left join BST b2 on b1.N = b2.P order by 1;
SELECT N, CASE
WHEN P is null THEN 'Root' WHEN N IN (SELECT P FROM BST) THEN 'Inner' ELSE 'Leaf'
END AS node_type
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 AS BST_TYPES FROM BST ORDER BY N,BST_TYPES
select b1.n, case when n = (select n from bst where p is NULL) then 'Root' when b1.n in (select b2.n from bst b2 left join bst b3 ON b2.n=b3.p where b3.p IS NULL) then 'Leaf' else 'Inner' end from bst b1 order by n asc