BFS and Queue
BFS (Bridth First Search) can be implemented by a queue.
![]()
Procedure is like this: (Q is Queue)
1, Put 1 in Q : ->1 (front)
2, Read the front of Q (which is 1) and put its children in Q: ->4->3->2
3, Repeat 2
....
Also, DFS (Depth First Search) can be implemented by a stack.
![]()
Procedure is like this: (S is Stack)
1, Put 1 in S: 1<- (bottom)
2, Read the top of S which is 1 and put its children into S: 2<-7<-8
3, Repeat 2
....
Think about it!
BFS and Queue的更多相关文章
- Trees on the level UVA - 122 复习二叉树建立过程,bfs,queue,strchr,sscanf的使用。
Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- ...
- 32-1题:不分行从上到下打印二叉树/BFS/deque/queue
题目 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 考点 1.广度优先遍历 2.binary tree 3.queue 4.deque 思路 按层打印:8.6.10.5.7.9.11 用ST ...
- Clone Graph leetcode java(DFS and BFS 基础)
题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...
- AOJ 0121: Seven Puzzle (BFS DP STL 逆向推理)(转载)
转载自: http://m.blog.csdn.net/blog/Enjoying_Science/42008801 题目链接:http://acm.hust.edu.cn/vjudge/probl ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- DFS/BFS+思维 HDOJ 5325 Crazy Bobo
题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...
- HDU1241(bfs)JAVA
import java.util.Scanner;public class Main1241 { public static void main(String[] args) { Scanner ci ...
- HDU_1401——同步双向BFS,八进制位运算压缩,map存放hash
这个速度比分步快一点,内存占的稍微多一点 Problem Description Solitaire is a game played on a chessboard 8x8. The rows an ...
- POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))
题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...
随机推荐
- 异步设备IO:OVERLAPPED和IOCompletionPort
异步设备IO:OVERLAPPED和IOCompletionPort 本文内容为<windows核心编程>第10章内容的总结,仅记录一些本人感兴趣的内容. 1:OVERLAPPED &qu ...
- IIS的php环境配置
session保存 再找到 session.save_path = /tmp ,将其改为 session.save_path = C:\php-4.3.2-Win32\sessions .(注:此时你 ...
- iOS开发工具箱
工欲善其事 必先利其器 最新重新安装了MacBook Air和Mac Pro的系统,彻底解决了一编译就报硬盘空间不足的问题.平时开发中比较常用的工具都需一一安装. XCode:没什么好说的,外星人都知 ...
- .Net cxy 提高效率
Visual Studio Visual Studio Productivity Power tool: VS 专业版的效率工具. Web Essentials: 提高开发效率,能够有效的帮助开发人员 ...
- Idea把依赖打入Jar包,Maven项目步骤
1:修改pom.xml安装assembly插件 1:修改pom.xml 安装assembly插件 <plugin> <artifactId>maven-assembly-plu ...
- gulp4个基础API
Gulp.src(globs[, options]) 此接口会匹配工作目录下指定规则的文件并返回提供给下一个插件管道使用.其中globs就是匹配格式,options是一些额外参数. gulp.src( ...
- 编写高质量iOS代码的52个有效方法1-1
一.使用向前声明(@class)的好处 1.有效减少编译器编译的时间: 2.有效避免循环引用: 二.字面量语法的好处 1.字面常量 精简.可用于所有数据类型,如: NSNumber *intNumbe ...
- scale相关设置—颜色设置
颜色设置,在R的可视化中,应该算是相对比较重要的一项内容,如何把握颜色,很大程度上影响图形的展现效果. 在ggplot的scale设置中,颜色相关的函数较多: scale_fill/colour_hu ...
- Android onConfigurationChanged的作用
API原文说明: android:configChangesLists configuration changes that the activity will handle itself. When ...
- Java 内部类和匿名内部类
1.内部类: /* 局部内部类: 在一个类 的方法内部定义另外一个类,那么另外一个类就称作为局部内部类. 局部内部类要注意的细节: 1. 如果局部 内部类访问了一个局部变量,那么该局部变量必须使用fi ...