Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node.自己想的复杂了,其实就是一个反向的inorder。新的值就是前面所有元素的...
分类:
其他好文 时间:
2014-11-09 15:07:49
阅读次数:
186
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-11-09 07:30:45
阅读次数:
155
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-11-09 06:19:31
阅读次数:
173
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Solution: 1 /** 2 * Definition for binary tree 3 * .....
分类:
其他好文 时间:
2014-11-09 00:58:31
阅读次数:
213
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution: 1 /** 2 * Definition for singl....
分类:
其他好文 时间:
2014-11-09 00:52:30
阅读次数:
316
BST
即二叉搜索树:
1.所有非叶子结点至多拥有两个儿子(Left和Right);
2.所有结点存储一个关键字;
3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树;
如:
B-树(B树)
是一种多路搜索树(并不是二叉的):
1.定义任意非叶子结点最多只有M个儿子;且M>2;
2.根结点的儿子数为[2, M];
3.除根结点以外的非叶子结点的儿子数...
分类:
其他好文 时间:
2014-11-07 22:05:05
阅读次数:
310
leetcode 原题 :(即判断二叉树是否为二叉查找树)Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subt...
分类:
编程语言 时间:
2014-11-05 22:54:17
阅读次数:
204
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 1 /** 2 * Definition for singly-linked ....
分类:
其他好文 时间:
2014-11-03 23:53:07
阅读次数:
185
1 AVL树的定义
AVL树是一种自平衡二叉排序树,它的特点是任何一个节点的左子树高度和右子树的高度差在-1,0,1三者之间。AVL树的任何一个子树都是AVL树。
2 AVL树的实现
AVL树本质是一种二叉排序树,所以二叉排序树的任何性质AVL树都具有,但是AVL树稍微复杂的地方就是AVL树必须满足平衡条件,具体跟BST不同的地方主要体现在插入,删除操作。
插入操作:当插入之后可能会出现不...
分类:
编程语言 时间:
2014-11-03 19:25:21
阅读次数:
183
判断堆:递归判断每个节点的孩子是否都比其父亲大(小)。判断BST:中序遍历是否有序。 1 #include 2 using namespace std; 3 #define lc (rtb[i-1]) {f2=0; break;}18 if(f2) return 1;19 retur...
分类:
其他好文 时间:
2014-11-01 08:37:15
阅读次数:
290