Tree -- Traverse & DFS & BFS
来源:互联网 发布:深圳最好的java培训 编辑:程序博客网 时间:2024/06/15 00:52
- 注意pre order, in order, post order 跟DFS, BFS遍历顺序不一样。
- post order 用于计算expressions.
- tree traverse. see http://interactivepython.org/runestone/static/pythonds/Trees/TreeTraversals.html python code
不同的遍历方法仅仅是print 的顺序不一样,都是先判断root是不是none,然后再看是不是要print,还是说recursive left/right sub tree
BFS
要用queue。
DFS
用 recursive的办法
就是preorder
if root: do some thing# can be print or other function preorder(node.left, level + 1) preorder(node.right, level + 1)
用stack
0 0
- Tree -- Traverse & DFS & BFS
- Tree: DFS vs BFS
- Tree Traverse
- Traverse Tree iteratively
- Tree Traverse & BST
- DFS Search and BFS Search on Tree
- [UVA10410]Tree Reconstruction[BFS、DFS序建树]
- LeetCode oj 100. Same Tree (DFS||BFS)
- Traverse binary tree by level
- Simple Tree Traverse(遍历)
- hdu - 4601 - Letter Tree(bfs+dfs+Trip+二分+RMQ)
- uva10410 - Tree Reconstruction BFS和DFS重建树
- Leetcode bfs&dfs Binary Tree Postorder Traversal II
- hdu4601 Letter Tree,trie,bfs,dfs,二分,rmq
- 199:Binary Tree Right Side View【树】【DFS】【BFS】
- 【LeetCode】104. Maximum Depth of Binary Tree(DFS|BFS)
- LeetCode oj 104. Maximum Depth of Binary Tree(DFS||BFS)
- LeetCode oj 226. Invert Binary Tree (DFS||BFS)
- java int与byte【】之间的转换
- ant 安装
- iOS中UITextField、UITextView的字数限制
- 黑马程序员——OC基础---Foundation<NSArray补充,NSMultableArray,NSDictionary>
- Android最新动画框架完全解析(一)—— Animator(Property Animation)
- Tree -- Traverse & DFS & BFS
- PHP Yii 命令行程序以及定时任务详解
- 类别扩展属性
- LeetCode(164)Maximum Gap
- java/php/c#版rsa签名以及java验签实现--转
- DB2建库指定字符集
- 所谓温柔
- hdu 2586 How far away ?(Tarjan)
- Android Environment 获取各种路径的方法