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的更多相关文章

  1. Trees on the level UVA - 122 复习二叉树建立过程,bfs,queue,strchr,sscanf的使用。

    Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- ...

  2. 32-1题:不分行从上到下打印二叉树/BFS/deque/queue

    题目 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 考点 1.广度优先遍历 2.binary tree 3.queue 4.deque 思路 按层打印:8.6.10.5.7.9.11 用ST ...

  3. 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. ...

  4. AOJ 0121: Seven Puzzle (BFS DP STL 逆向推理)(转载)

    转载自:  http://m.blog.csdn.net/blog/Enjoying_Science/42008801 题目链接:http://acm.hust.edu.cn/vjudge/probl ...

  5. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  6. DFS/BFS+思维 HDOJ 5325 Crazy Bobo

    题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...

  7. HDU1241(bfs)JAVA

    import java.util.Scanner;public class Main1241 { public static void main(String[] args) { Scanner ci ...

  8. HDU_1401——同步双向BFS,八进制位运算压缩,map存放hash

    这个速度比分步快一点,内存占的稍微多一点 Problem Description Solitaire is a game played on a chessboard 8x8. The rows an ...

  9. POJ 3041 Asteroids(模板——二分最大匹配(BFS增广))

    题目链接: http://poj.org/problem?id=3041 Description Bessie wants to navigate her spaceship through a da ...

随机推荐

  1. LEK-Introduction

    LEK - logstash + elasticsearch + Kibana Elasticsearch, Logstash, and Kibana — designed to take data ...

  2. Paint Pearls

    Paint Pearls 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5009 dp+双向链表优化 看到题目,很自然地可以定义状态:dp[i]表示涂好 ...

  3. 朴素贝叶斯算法 & 应用实例

    转载请注明出处:http://www.cnblogs.com/marc01in/p/4775440.html 引 和师弟师妹聊天时经常提及,若有志于从事数据挖掘.机器学习方面的工作,在大学阶段就要把基 ...

  4. 第九十四节,html5+css3移动手机端流体布局,旅游部分,媒体查询

    html5+css3移动手机端流体布局,旅游部分,媒体查询 媒体查询 媒体查询是手机网站和自适应网站的重要部分,媒体查询可以根据不同的屏幕大小,做响应的处理,如文字的大小,区块隐藏等等 媒体查询,这里 ...

  5. iOS开发富文本

    NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc] initWithString:@" ...

  6. MATLAB制作符合IEEE标准的图插入Latex

    1.MATLAB最好保存为eps格式,虽然IEEE也支持png等其他格式,但是MATLAB在保存为png格式时,很容易在后期插图时,出现分辨率不足等问题. 2. MATLAB在save as图片的时候 ...

  7. 正方形网格 TRIANGLE_STRIP连接

    unsigned int vIdx = 0, iIdx = 0; for (unsigned int stripRow = 0; stripRow < stripRows; stripRow++ ...

  8. 【TestDirector】常见问题分析

    1.IE7无法访问TD 问题原因:兼容性问题 解决方法:步骤一.以系统管理员身份登陆TD: 步骤二.找到TD服务器中TDBIN目录(缺省情况下是C:\Inetpub\TDBIN目录),用编辑器打开st ...

  9. 如何将编译出来的images拷贝到windows下面刷机

    由于SPRD的刷机工具ResearchDownload运行在window环境下:这样,我们平时在开发环境下编译出来的镜像文件就不能直接用于刷机了. 这里涉及到一个双系统中文件共享的方法.由于企业信息安 ...

  10. sublime 配置 python IDE

    安装sublime下载地址:http://www.sublimetext.com/,请自行根据系统版本进行下载.下载好之后直接安装即可. 汉化包 汉化包下载: 汉化方法: 1.运行sublime te ...