Where does null get inserted into a binary search tree?
This problem is an example input for a problem on leetcode.
Input: root = [10,5,15,3,7,null,18]
If I follow a BST insertion algorithm, what do I do with that null there? Where does it end up as a node in the tree?
When you see nulls in serializations of binary trees in LeetCode test cases like that, it doesn't mean that nodes in the tree have null as data, it's showing you where in the tree nodes are missing left and/or right children. See https://support.leetcode.com/hc/en-us/articles/360011883654-What-does-1-null-2-3-mean-in-binary-tree-representation- for LeetCode's official explanation including a tree visualizer tool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With