码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
[LeetCode系列]BST有效性确定问题[前序遍历]
给定一个BST的根节点, 试判断此BST是否为符合规则的BST?规则: 对于一个BST的节点,它左侧的所有节点(包括子节点)必须小于它本身;它右侧的所有节点(包括子节点)必须大于它本身;它的左右节点也必须满足上面两条.算法思路: 对于给定的根节点N, 先找到它左子节点L的最底层的右子节点MR, 比较...
分类:其他好文   时间:2014-09-09 16:00:18    阅读次数:216
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 5 unique BST's shown below. 1 3...
分类:其他好文   时间:2014-09-09 12:31:39    阅读次数:143
Leetcode: Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.难度70,与Convert Sorted Array to Binary Sear...
分类:其他好文   时间:2014-09-08 06:26:16    阅读次数:263
二叉搜索树的个数
二叉搜索树(BST)定义左孩子的值全部小于根节点,右孩子的值全部大于跟结点,左孩子、右孩子同样满足上述条件。假如有3个结点,总共有5个可能的BST: 1 3 3 2 1 \ / / / \ \ 3 ...
分类:其他好文   时间:2014-09-07 12:10:25    阅读次数:195
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-09-07 07:38:14    阅读次数:315
【LeetCode】Balanced Tree & Binary Search Tree
整合两道差不多的题目放上来,其中第一题是第二题的基础。 1. Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two...
分类:其他好文   时间:2014-09-06 21:21:03    阅读次数:279
数据结构-5-平衡二叉树算法原理解析
平衡二叉树定义(AVL):它或者是一颗空树,或者具有以下性质的二叉树:它的左子树和右子树的深度之差的绝对值不超过1,且它的左子树和右子树都是一颗平衡二叉树。 平衡因子(bf):结点的左子树的深度减去右子树的深度,那么显然-1   很显然,平衡二叉树是在二叉排序树(BST)上引入的,就是为了解决二叉排序树的不平衡性导致时间复杂度大大下降,那么AVL就保持住了(BST)的最好时间复杂度O(logn...
分类:其他好文   时间:2014-09-06 09:46:03    阅读次数:332
Leetcode--Convert Sorted List to Binary Search Tree
Problem Description: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 分析:很容易想到的一种解法是将链表中所有的元素保存到数组中,然后每次取中间值进行构造,时间复杂度为O(n),空间复杂度为O(n)。具体...
分类:其他好文   时间:2014-09-05 18:14:11    阅读次数:223
<code> CODING
插入排序,归并排序,快排,冒泡,选择排序算法源码;折半搜索;判断链表是否有环;BST树的数量,二叉树的前中后续遍历;数字反转;判断相同树;排列、组合等源码;
分类:其他好文   时间:2014-09-04 16:48:39    阅读次数:269
LeetCode: Unique Binary Search Trees
LeetCode: Unique Binary Search TreesGiven n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n = 3...
分类:其他好文   时间:2014-08-31 22:41:31    阅读次数:361
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!