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 ...
随机推荐
- jfianl返回自定义的404页面
public class MyErrorRenderFactory implements IErrorRenderFactory{ public Render getRender(int errorC ...
- Tsung测试统计报告说明
Tsung测试统计报告说明 ********************** report.html *********************** 1.主要统计信息 Tsung统计数据是平均每十秒重 ...
- js日期操作时间看板
var nowTime = null;//获取服务器时间function GetTime() { $.ajax({ url:config._domain + "/AjaxAuctionCen ...
- js中运算符
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- iOS开发极光推送显示 开发证书没有通过验证 是否重新上传证书?解决方法
1.证书密码错误 2证书环境不匹 3导证书时因手误把私钥导出来了,而不是证书 1.当前上传的p12证书密码输入有误: 2. 证书导出的时候展开了证书,把个人私钥导了出来,导证书的时候请不要展开证书: ...
- CSS3的基础知识点
面临找工作之际,又将CSS3的基础知识撸了一把,做了相应的笔记,主要是方便自己查阅,参考的是W3C的知识. 1.CSS背景 (1).background-size 属性 background-s ...
- 三、WCF的宿主
注:本文为学习摘抄,原文地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/10/01/2706353.html 一.WCF服务应用程序与WCF服务 ...
- JS 之设置元素样式的改变,可以利用样式框架
如果已经将某个元素的样式设定好了,又想改变,可以利用样式框架: function setStyle(obj,attr,value){ obj.style[attr]=value;//注意此处attr的 ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- 递归删除本地目录和ftp目录
本地目录: void CAutoDelete::DoRecursionLocalDelete(CString& localDirectory) { CFileFind finder; CStr ...