Path SumTotal Accepted:50593Total Submissions:169742My SubmissionsQuestionSolutionGiven a binary tree and a sum, determine if the tree has a root-to-l...
分类:
其他好文 时间:
2015-04-24 12:09:15
阅读次数:
95
题目链接:Balanced Binary Tree
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 subtrees ...
分类:
其他好文 时间:
2015-04-23 10:58:02
阅读次数:
153
将问题的各状态之间的转移关系描述为一个图,则深度优先搜索遍历整个图的框架为:Dfs(v) {if( v 访问过)return;将v标记为访问过;对和v相邻的每个点u: Dfs(u);}int main() {while(在图中能找到未访问过的点 k)Dfs(k);}4例题:百练2815 城堡问题? ...
分类:
其他好文 时间:
2015-04-22 23:30:20
阅读次数:
158
通过GIF图“生动”介绍深度优先搜索与广度优先搜索...
分类:
其他好文 时间:
2015-04-21 01:52:17
阅读次数:
181
深度优先搜索算法:优先向下层进行状态扩展搜索过程:从一个顶点开始,如果该结点下层能够继续扩展,则向下层进行状态扩展,如果下层不能够继续扩展,寻找本层未处理过的结点,继续向下层状态进行扩展用一个经典的例子(走迷宫)来感受下给定一个二维数组 int a[10][10] = {0 , 1 , 0 , 0 ...
分类:
其他好文 时间:
2015-04-20 22:16:59
阅读次数:
135
题目链接:Balanced Binary Tree
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 subtrees ...
分类:
其他好文 时间:
2015-04-17 18:17:21
阅读次数:
140
题目链接: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.
这道题的要求是将有序链表转化成高度平衡的二叉搜索树(BST)。
1. 利...
分类:
其他好文 时间:
2015-04-17 18:16:32
阅读次数:
165
题目链接:Construct
Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in th...
分类:
其他好文 时间:
2015-04-17 18:15:57
阅读次数:
159
题目链接:Convert Sorted Array
to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
这道题的要求是将有序数组转化成高度平衡的二叉搜索树(BST)。
由于数组有序,因此相当于二叉搜索树...
分类:
其他好文 时间:
2015-04-17 18:15:21
阅读次数:
187
描述从根节点开始的递归深度优先搜索与树的前序遍历(preorder traversal)类似,是前序遍历的推广。从某个顶点V开始处理,然后递归地遍历所有与顶点V邻接的且没有被访问过的顶点。算法的基本思想如下:
假设图G初态为所有顶点未被访问(visited[i]=false),从G中任选一顶点vi :
从该顶点vi出发,首先访问vi,,置visited [vi ]=true;
然后依次搜索vi的每...
分类:
其他好文 时间:
2015-04-17 15:52:07
阅读次数:
217