码迷,mamicode.com
首页 >  
搜索关键字:bst    ( 4557个结果
Convert Sorted Array to Binary Search Tree
题目 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 方法 数组是有序的,要求创建的二叉树尽量平衡,很容易想到对数组进行二分操作,左边的数组元素是左子树,右边的数组元素是右子树。进行递归操作就可以了。 TreeNode...
分类:其他好文   时间:2014-06-20 11:06:46    阅读次数:257
leetcode -day27 Recover Binary Search Tree & Interleaving String
1、 ?? 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 pretty...
分类:其他好文   时间:2014-06-20 10:13:49    阅读次数:243
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. 方法 和有序数组的思想基本一样,将链表进行二分。 TreeNode getBST(ListNode head, int len) { i...
分类:其他好文   时间:2014-06-20 09:46:33    阅读次数:267
LeetCode --- Validate Binary Search Tree
题目链接判断一颗二叉树是否是二叉搜索树(二叉排序树),也就是BST如果该二叉树是BST, 那么对其中序遍历,所得序列一定是单调递增的(不考虑有重复数值的情况)附上代码: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 *...
分类:其他好文   时间:2014-06-07 11:28:18    阅读次数:254
LeetCode: Recover Binary Search Tree [099]
【题目】 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 pretty straight forward. Could you devise a constant space solution? confused what "{1,#,2,3}" ...
分类:其他好文   时间:2014-06-02 10:38:17    阅读次数:246
LeetCode: Validate Binary Search Tree [098]
【题目】 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. The right subtree of a node contains only nodes with ke...
分类:其他好文   时间:2014-06-02 10:29:55    阅读次数:257
LeetCode: Unique Binary Search Trees [095]
【题目】 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's. 1 3 3 2 1 \ / / / \ 3 2 1 ...
分类:其他好文   时间:2014-06-01 15:34:24    阅读次数:231
LeetCode: Unique Binary Search Trees II [096]
【题目】 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 3 2 1 \ / / / \ ...
分类:其他好文   时间:2014-06-01 15:33:45    阅读次数:297
普林斯顿公开课:算法第0章,课程介绍
课程介绍 这门课程核心内容是算法和数据结构。 具体的算法和数据结构如下: 数据类型:堆栈、队列、背包、并查集、优先队列。 排序:快排、并排、堆排、基数排序 查找:BST、红黑BST、哈希表 图:BFS、DFS、Prim、Kruskai、Dijkstra 字符串:KMP、正则、TST、哈夫曼、LZW 高级:B树、后缀数组、最...
分类:其他好文   时间:2014-06-01 10:52:26    阅读次数:285
Geeks Splay Tree Insert 树的插入操作
Splay树的插入操作,只需要处理好插入节点的孩子节点就可以了,最重要的是不要破坏了BST的基本规则。 因为高度并不是Splay树的首要因素,所以插入的时候也是使用splay操作,然后在根节点插入。 参考:http://www.geeksforgeeks.org/splay-tree-set-2-insert-delete/ 对比一下使用插入创建的树和手工创建数的区别,先序遍历的结果...
分类:其他好文   时间:2014-05-31 21:47:50    阅读次数:320
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!