1.Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
2.Given a singly linked list where elements are sorted in ascending order, convert it to a heig...
分类:
其他好文 时间:
2014-07-21 23:45:53
阅读次数:
264
对于一个二叉搜索树, 要想找到这棵树的最小元素值, 我们只需要从树根开始, 沿着left 孩子指针一直走, 知道遇到NULL(即走到了叶子), 那么这个叶子节点就存储了这棵二叉搜索树的最小元素。 同理, 从根节点开始, 沿着right 孩子指针, 最终找到的是最大关键字的节点。
也就是说寻找BST最小关键字的元素和最大关键字的元素的代码是对称的。伪代码如下:
TREE_MINIMUM(x...
分类:
编程语言 时间:
2014-07-21 09:28:27
阅读次数:
241
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
分类:
其他好文 时间:
2014-07-19 22:34:50
阅读次数:
196
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 pretty straight forward. Could you devis...
分类:
其他好文 时间:
2014-07-18 22:33:04
阅读次数:
328
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 ...
分类:
其他好文 时间:
2014-07-17 17:32:50
阅读次数:
246
Implement a function to check if a binary tree is a binary search tree./* The inorder travel of a BST is strictly increasing. We track the pre node of...
分类:
其他好文 时间:
2014-07-13 22:27:09
阅读次数:
344
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2014-07-13 16:53:01
阅读次数:
189
二叉排序树:
二叉排序树(Binary Sort Tree)又称二叉查找树(Binary Search Tree),亦称二叉搜索树。 它或者是一棵空树;或者是具有下列性质的二叉树:
(1)若左子树不空,则左子树上所有结点的值均小于它的根结点的值;
(2)若右子树不空,则右子树上所有结点的值均大于它的根结点的值; (3)左、右子树也分别为二叉排序树;
注:中序遍历一棵二叉排序...
分类:
其他好文 时间:
2014-07-12 19:35:08
阅读次数:
249
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2014-07-12 17:26:31
阅读次数:
256