1. BST只保存preorder或者postorder就够了,递归有O(n^2)和O(n)算法。非递归有利用栈的O(n)算法。2. Complete binary treelevel traversal就行了。3. Full binary tree用一个bit来保存该结点是internal nod...
分类:
其他好文 时间:
2014-10-31 21:53:15
阅读次数:
253
题目描述:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
思路:采用类似折半查找的方式找到当前根节点,则当前根节点左边的属于它的左子树部分,当前根节点右边的属于它的右子树部分。再采用同样的方法,递归地对当前根节点的左右子树做相同的处理。
...
分类:
其他好文 时间:
2014-10-30 19:22:04
阅读次数:
197
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST....
分类:
其他好文 时间:
2014-10-30 10:55:20
阅读次数:
151
BSTTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 8657Accepted: 5277DescriptionConsider an infinite full binary search tree (see the figure ...
分类:
其他好文 时间:
2014-10-30 09:27:09
阅读次数:
237
图的广度和深度遍历,具体内容教材有clc;clear all;close all;%初始化邻接压缩表compressTable=[1 2;1 3;1 4;2 4;2 5;3 6;4 6;4 7];max_vertex = max(compressTable(:)); ...
分类:
其他好文 时间:
2014-10-29 21:29:40
阅读次数:
332
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Solution:/** * Definition for binary tree * public cl...
分类:
其他好文 时间:
2014-10-27 06:51:31
阅读次数:
137
2014-10-2515:13:56暑假打(luan)完(gao)了基础,是时候做一下下一步的规划了。 codeforces #190-#199 图论--基础(割顶、割边、连通性等) 图论--二分图及二分图匹配 图论--差分约束 树结构--BST 树结构--LCA 树结构--树分治 ...
分类:
其他好文 时间:
2014-10-25 15:47:45
阅读次数:
240
这道题是Search in Rotated Sorted Array的扩展,区别就是现在不是找一个目标值了,而是在bst中找最小的元素。主要思路还是跟Search in Rotated Sorted Array差不多,还是通过左边界和中间的大小关系来得到左边或者右边有序的信息,如果左半边有序,那么左半边最小就是左边第一个元素,可以和当前最小相比取小的,然后走向右半边。否则,那么就是右半半边第一个元...
分类:
其他好文 时间:
2014-10-25 08:10:05
阅读次数:
200
问题描述:
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...
分类:
其他好文 时间:
2014-10-24 16:33:10
阅读次数:
117