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.
"_ first select the node then for each node check weather their parent is null if parent of a node is null, it means that particular node is a 'Root Node'
if for any node their parent is not null then we'll check that particular node is paresent in parent section , if yes it means that node will be a 'Inner node'
Rest of the else node will be "leaf node" because those are not parent of any node.
SELECT
N,
CASE
WHEN P IS NULL THEN 'Root'
WHEN N IN (SELECT DISTINCT P FROM BST) THEN 'Inner'
ELSE 'Leaf'
END AS Node_Type
FROM BST
ORDER BY N;
/
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
"_ first select the node then for each node check weather their parent is null if parent of a node is null, it means that particular node is a 'Root Node' if for any node their parent is not null then we'll check that particular node is paresent in parent section , if yes it means that node will be a 'Inner node' Rest of the else node will be "leaf node" because those are not parent of any node.
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N IN (SELECT DISTINCT P FROM BST) THEN 'Inner' ELSE 'Leaf' END AS Node_Type FROM BST ORDER BY N;
/