Binary Tree Nodes

  • + 1 comment

    MySQL

    SELECT n, CASE WHEN n NOT IN (SELECT DISTINCT p FROM bst WHERE p IS NOT NULL ) THEN "Leaf" when p is NULL THEN "Root" ELSE "Inner" END AS 'node_type' FROM bst ORDER BY n ASC;