BST就是二叉检索树,或者是二叉排序树,或者叫二叉搜索树等等。 BST的平衡问题可以去学习AVL树或者Treap或者Splay这些平衡树。 BST的一些高级应用: 1,求BST中比k小的数的个数: 只需在BST上面多维护值size,表示当前这个节点的子树的点的个数。 伪代码如下: 1 ...
分类:
其他好文 时间:
2015-12-22 16:08:41
阅读次数:
175
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia:...
分类:
其他好文 时间:
2015-12-20 08:12:25
阅读次数:
158
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's ...
分类:
其他好文 时间:
2015-12-19 13:44:38
阅读次数:
163
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解法一:双节点public TreeNode sortedListToBST...
分类:
其他好文 时间:
2015-12-19 06:37:24
阅读次数:
171
题目描述:(链接)Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路: 1 /** 2 * Definition for ....
分类:
其他好文 时间:
2015-12-17 22:27:19
阅读次数:
228
题目描述:(链接)Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路: 1 /** 2 * Definition for a binary tre....
分类:
其他好文 时间:
2015-12-17 20:42:02
阅读次数:
122
Lowest Common Ancestor of a Binary Search TreeTotal Accepted:42225Total Submissions:111243Difficulty:EasyGiven a binary search tree (BST), find the lo...
分类:
其他好文 时间:
2015-12-17 15:43:53
阅读次数:
120
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined
betw...
分类:
其他好文 时间:
2015-12-11 10:08:34
阅读次数:
137
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3, there are a total of 5 unique BST'...
分类:
其他好文 时间:
2015-12-10 21:21:37
阅读次数:
118
题目:Given a non-empty binary search tree and a target value, findkvalues in the BST that are closest to the target.Note:Given target value is a floatin...
分类:
其他好文 时间:
2015-12-09 07:09:39
阅读次数:
180