二叉查找树(Binary Search Tree)在很多情况下可以良好的工作,但它的限制是最坏情况下的渐进运行时间为 O(n)。平衡查找树(Balanced Search Tree)的设计则是保证其高度在最坏的情况下为 O(log n),其插入、删除和查找可以实现渐进运行时间 O(log n)。本文...
分类:
其他好文 时间:
2014-07-24 14:44:35
阅读次数:
282
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int maxn =10000+5;
const int ma...
分类:
其他好文 时间:
2014-07-24 10:45:34
阅读次数:
230
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...
分类:
其他好文 时间:
2014-07-24 10:06:33
阅读次数:
191
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
分类:
其他好文 时间:
2014-07-24 10:04:33
阅读次数:
214
实现: 1 #ifndef BINARY_SEARCH_TREE_H 2 #define BINARY_SEARCH_TREE_H 3 4 #include "dsexceptions.h" 5 #include // For NULL 6 using namespace st...
分类:
其他好文 时间:
2014-07-24 10:03:33
阅读次数:
398
实现: 1 #ifndef AVL_TREE_H 2 #define AVL_TREE_H 3 4 #include "dsexceptions.h" 5 #include // For NULL 6 using namespace std; 7 8 // AvlTree...
分类:
其他好文 时间:
2014-07-24 10:01:43
阅读次数:
317
题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flatten...
分类:
编程语言 时间:
2014-07-24 09:55:43
阅读次数:
211
# include
# include
# include
using namespace std;
int father[1010];
int next[1010];//当前集合的下个元素(包括i)
int pre[1010];//当前集合的上个元素(包括i)
int num[1010];//num[i]当前集合储存的点的个数(包括i)
int vis[1010];
int sum[101...
分类:
其他好文 时间:
2014-07-23 22:39:47
阅读次数:
446
这道题细节真的很多
首先可以想到a和b的最优策略一定是沿着a和b在树上的链走,走到某个点停止,然后再依次占领和这个点邻接的边
所以,解决这道题的步骤如下:
预处理阶段:
step 1:取任意一个点为根节点,找出父子关系并且对这个树进行dp,求出从某个节点出发往下所包含的所有边的权值总和 复杂度O(n)
step 2:从tree dp 的结果中计算对于某个节点,从某条边出发所包含的边的综...
分类:
其他好文 时间:
2014-07-23 22:38:47
阅读次数:
459
分割后长度相等,就是参数麻烦,p,先序的起始点, ib,ie 终须的结束和开始。 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left;...
分类:
其他好文 时间:
2014-07-23 22:10:37
阅读次数:
211