DFS & BFS--Data Structure
来源:互联网 发布:简述linux启动过程 编辑:程序博客网 时间:2024/06/03 16:11
Two ways of traversal : DFS, BFS
Three methods to implement DFS:
InOrderTraversal (tree)
if (tree == null) return;
InOrderTraversal (tree.left);
Print (tree.key);
InOrderTraversal (tree.right);
PreOrderTraversal (tree)
if (tree == null) return;
Print (tree.key);
PreOrderTraversal (tree.left);
PreOrderTraversal (tree.right);
PostOrderTraversal (tree)
if (tree == null) return;
PostOrderTraversal (tree.left);
PostOrderTraversal (tree.right);
Print (tree.key);
Implement of BFS:
LevelTraversal (tree)
if (tree == null) return;
Queue q;
q.Enqueue (tree);
while (!q.Empty()){
node <-- q.Dequeue();
Print (node);
if (node.left != null) q.Enqueue (node.left);
if (node.right != null) q.Enqueue (node.right);
}
Summary:
Tree walks: DFS, BFS.
When working with a tree, recursive algorithms are common.
In CS, trees grow down.
- DFS & BFS--Data Structure
- cdoj 483 Data Structure Problem DFS
- Data Structure
- Data structure
- Data Structure
- Data structure
- Data structure
- data structure
- Data Structure
- Data structure
- Data Structure
- Data Structure
- Data Structure
- Data Structure
- Data structure alignmentData structure alignment
- Finish Data Structure Examination
- 【OPENGL】DEVMODE data structure
- Critical Data Structure -- sk_buff
- C++利用常量表达式在编译期操作字符串
- 【bzoj1455】【罗马游戏】左偏树+并查集(模板)
- C++笔记之前向声明
- 基于51单片机和L298N的小车制作(二)
- ES6(三)字符串的扩展
- DFS & BFS--Data Structure
- Galaxy Note8获一致好评,市场前景值得期待
- 与程序竞赛有关的数学知识点
- spark压缩 配置
- Tomcat version 7.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 and 6 Web modules
- python内置函数
- 指针函数和函数指针
- 想提高软件测试技能?今天我给你仔细讲讲有什么方法!
- C数据结构-线性表之顺序表