码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
Leetcode-Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should return all...
分类:其他好文   时间:2014-11-29 06:47:54    阅读次数:165
Leetcode-Unique Binary Search Trees
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'...
分类:其他好文   时间:2014-11-29 06:36:51    阅读次数:160
【leetcode】Convert Sorted Array to Binary Search Tree (easy)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.有序数组变二叉平衡搜索树,不难,递归就行。每次先序建立根节点(取最中间的数),然后用子区间划分左右子树。一...
分类:其他好文   时间:2014-11-27 23:20:29    阅读次数:269
[Leetcode]Validate Binary Search Tree
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-11-27 16:30:19    阅读次数:226
BZOJ 3769 spoj 8549 BST again 记忆化搜索
题目大意:求深度为h,大小为n个BST的数量对1000000007取模的值 令f[i][j]为大小为i,深度为j以下的BST的数量 设根节点为k,那么两个儿子一定分别是两个BST 有递推式f[i][j]=(1 记忆化搜索即可 卡常数可以过 #include #include #include #include #define M 610 #define MOD 100000000...
分类:其他好文   时间:2014-11-27 16:23:00    阅读次数:188
CC150 4.5
4.5Writeanalgorithmtofindthe‘next’node(i.e.,in-ordersuccessor)ofagivennodeinabinarysearchtreewhereeachnodehasalinktoitsparent.//BST. classNode { Nodeparent; Nodeleft; Noderight; } Nodemin(Nodenode) { if(node==null) returnnull; while(node.left!=null) nod..
分类:其他好文   时间:2014-11-27 08:01:56    阅读次数:218
LeetCode - Convert Sorted Array to Binary Search Tree
给出一个已排序的数组,将其转化为二叉查找树(BST)。思路:取数组中间元素为根结点的value,则数组左侧、右侧分别为BST的左子树、右子树。递归可求解。代码如下: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * ...
分类:其他好文   时间:2014-11-26 18:13:30    阅读次数:206
二叉查找树之二
BST树的经典问题首先构造如下一棵二元查找树(BST树):C++代码实现:typedef struct _BSTreeNode { int value; struct _BSTreeNode *left; struct _BSTreeNode *right;} BSTreeNode...
分类:其他好文   时间:2014-11-26 18:05:42    阅读次数:211
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 ...
分类:其他好文   时间:2014-11-26 13:58:49    阅读次数:255
leetcode[98] Validate Binary Search Tree
判断给定的数是不是合法的BST。即当前节点值比他左子树大,比右子树小。思路一:递归,考虑所有可能。1. 为空是返回true2. 用flag记录左子树返回的合法性。考虑左子树不空的时候,那么要根要比左子树的最右下角要大。3. flag为真且右子树也为真则返回真。考虑右子树时,根要比右子树的最左小。/*...
分类:其他好文   时间:2014-11-26 01:21:50    阅读次数:281
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!