码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
[LeetCode]题解(python):098 Validate Binary Search Tree
题目来源 https://leetcode.com/problems/validate-binary-search-tree/ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST ...
分类:编程语言   时间:2016-05-03 20:10:18    阅读次数:204
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 ...
分类:其他好文   时间:2016-04-29 22:12:33    阅读次数:178
一步一步写数据结构(BST-二叉排序树)
二叉排序树的重要性不用多说,下面用c++实现二叉排序树的建立,插入,查找,修改,和删除。难点在于删除,其他几个相对比较简单。 以下是代码: 上面的代码分别实现了查找,建立,插入的操作,下面是删除函数的实现,删除比较难主要是因为删除节点后下面的所有节点都会受到影响。此时采取的思维是分类讨论节点的孩子节 ...
分类:编程语言   时间:2016-04-28 23:54:07    阅读次数:369
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' ...
分类:其他好文   时间:2016-04-28 23:48:55    阅读次数:174
数据结构与算法--二叉树(一)
1 基于二叉链表的有序二叉树 1.1 问题 BST是Binary Search Tree的缩写,译为二叉搜索树,或有序二叉树,是二叉树的一种,它的定义如下: 1)或者是一棵空树; 2)或者是具有下列性质的二叉树: I) 若左子树不空,则左子树上所有结点的值均小于它的根结点的值; II) 若右子树不空,则右子树上所有结点的值均大于它的根结点的值; III)左、右...
分类:编程语言   时间:2016-04-22 10:37:48    阅读次数:318
How to delete a node in BST?
Step 1: Use the key to find this node in BST, time complexity is log(n) Step 2: after finding this node, we have 3 different conditions: 1, if this no ...
分类:其他好文   时间:2016-04-21 18:34:53    阅读次数:172
235.236. Lowest Common Ancestor of a Binary (Search) Tree -- 最近公共祖先
235. Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the ...
分类:其他好文   时间:2016-04-21 16:34:57    阅读次数:197
173. Binary Search Tree Iterator -- 迭代器
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the n ...
分类:其他好文   时间:2016-04-21 13:31:58    阅读次数:174
99. 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 i ...
分类:编程语言   时间:2016-04-20 11:34:36    阅读次数:127
Leetcode 230 Kth Smallest Element in a BST
1. 问题描写叙述 给定一个二叉搜索树,找出第k小的元素。 注意:能够如果k总是存在,1≤k≤BST总元素数1 \le k \le BST总元素数。 2. 方法与思路 依据二叉搜索树的特点。中序遍历的结果即是排序好的数组。那么找出第k小的数,仅仅须要先进行一次中序遍历就可以。 /** * Defin ...
分类:其他好文   时间:2016-04-17 20:44:37    阅读次数:148
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!