Binary Tree : It is a tree data structure in which each node has at most two children. As such there is no relation between a parent and its left and right descendants. Hence they are unordered. Binary Search Tree : These are ordered binary trees wit…
What is Binary Search Tree (BST) A binary tree in which for each node, value of all the nodes in left subtree is less or equal and value of all the nodes in right subtree is greater The idea: We can use set boundry for each node. We take C tree for e…
详见:剑指 Offer 题目汇总索引:第6题 Binary Tree Postorder Traversal Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. Note: Recursive solution is trivial, could…
Recover Binary Search Tree OJ: https://oj.leetcode.com/problems/recover-binary-search-tree/ Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is prett…
For a binary tree, preorder traversal may be enough. For example, _ / \ / / \ 50 45 35 The result is 30 10 50 # # # 20 45 # # 35 # # Using a queue to deserialize it . But a for multi-way tree, we could also use an array to ser…
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [3], …
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example:Given the following binary tree, 1 <--- / \2 3 <--- \ \ 5 4 …