文章目录
- 前言
- 一、Uninformed Search (无信息搜索)
- 二、Data structure for search tree
- 三、Breadth-first search (广度优先搜索)
- 四、Depth-first search (深度优先搜索)
- 五、Measuring performance
- 六、BFS和DFS时间和空间复杂度
- 七、Iterative deepening search(迭代加深搜索)
- 八、Branching factor (分支因子)
- 九、Reference(参考文献)
- 总结
前言
介绍(个人吐槽):本人是一个大二的计算机科学的在读生,这一篇文章相当于复习笔记一样的。
为什么要写这个文章?
一,是因为我发现计算机科学要学的东西太多太多了,我实在顶不住了!!!大一的知识的话还可以通过我聪明的小脑袋瓜学着混混。但大二的知识越来越难而且越来越多。所以我需要一个笔记将他们总结记录下来,以后方便复习。
二,是发布到网上可以让各位大佬们帮我看看我理解的正不正确,欢迎各位大佬与我讨论。
三,是以后毕业找工作时,还可以把我拥有的这个博客写入我的简历,想想就美滋滋!(加分加分)
提示:本片文章是本人上课后通过自己的理解总结下来的一些笔记。不一定是完全正确的。只是个人的片面之词。这也是本人第一次写这样的文章,我也不知道格式和书写语言是否合适,和正规。还请各位读者请多包涵,在这我先谢谢你们了。还有如果有大佬能发现文章中的理解错误的,虽然我不想耽误你们时间但如果可以帮我指出,我十分感谢。(在我眼里,能帮我支持我的错误的人都是我的大佬!!!)我也希望我的文章当你读完后可以对你有一点点帮助!
一、Uninformed Search (无信息搜索)
- Agents have no additional information beyond that provided in the definition of the search problem.
- Uninformed search algorithms do not have additional information about state or search space other than how to traverse the tree, so it is also called blind search
- 无信息搜索算法意味着算法搜索时除了便利树之外,没有关于状态或者搜索空间的额外信息。
二、Data structure for search tree
- Every node of our search tree has an associated data structure: (id,state,parent_id,action,path_cost,depth)
where:
-id is the unique integral identifier of the node(1 for root). id 代表着每个节点有着自己的数字号码表示他本身。
-state is the associated state from the state space (initial state for root). state是状态空间中的相关状态,如在根节点的state就为x0。
-parent_id is the identifier of the parent of the node in the search tree (empty for root). parent_id 就是父节点自身的id数字。根节点没有它的父节点,所以根节点没有parent_id的。
-action is the action which enabled the transition from the parent-node to the node in question (empty for root). action是允许从父节点转换到相关节点的操作。
-path_cost is the cumulative cost of the step-costs in the path from the root to the node in question (0for root). path_cost是从根节点到相关节点的累计花的步骤。
-depth is the depth of the node in question (0for root). depth是根节点到相关节点的深度。
三、Breadth-first search (广度优先搜索)
- Given the fringe of the search tree, every node on the fringe is expanded in each phase
i.e., a node with smallest (search-tree) depth is expanded. - termination occurs when a goal-node appears on the fringe.
- 基本过程,BFS 是从根节点开始,沿着树(图)的宽度遍历树(图)的节点。如果所有节点均被访问,则算法中止。一般用队列数据结构来辅助实现 BFS 算法。对于下面的树而言,BFS 方法首先从根节点1开始,其搜索节点顺序是 1,2,3,4,5,6,7,8。
1. Pseudocode for a BFS
下图是BFS的伪代码表示:
BFS 使用队列 queue 来实施算法过程,queue有着先进先出 FIFO (First Input First Output)的特性。
四、Depth-first search (深度优先搜索)
- given the fringe of the search tree, a node of greatest depth is expanded.
- 其过程简要来说是对每一个可能的分支路径深入到不能再深入为止,而且每个节点只能访问一次。
1. Pseudocode for a DFS
- DFS is implemented by identical code to that implementing BFS except that the queue is now a lifo queue: “last-in first-out” (also called a stack).
- 下图是DFS的伪代码表示:
- DFS的实现代码与BFS的实现代码完全相同,不同的是,该队列现在是后进先出(lifo)队列:“后进先出”(也称为堆栈)。
五、Measuring performance
- We evaluate a search strategy using four concepts. 无信息搜索策略可以按照如下4个特点来评价:
- Completeness(完备性):是否总能找到一个存在的解。
- Optimality(最优性):是否总能找到最优的解。
- Time complexity(时间复杂度):花费多长时间找到这个解。
- Space complexity(空间复杂度):需要多少内存。
– Time/space complexity associated with specific notions of “size” or “difficulty”
- b: the “branching factor”, namely the maximum number of children of a tree-node. b 为分支因子。后面有一个补充说明关于这个分支因子。
maximum number of state-action successors of any state. - d: the depth of the shallowest goal-node in the search tree. d 是搜索树中最浅目标节点的深度
smallest number of transitions from the initial state to a goal in the state space. - m: the maximum length of a path from the root in the search tree. m 是从搜索树的根结点开始的路径的最大长度
the maximum length of a walk in the state space. - Time: the number of tree-nodes generated ( or revealed). 是生成(或显示)的树节点的数量。
- Space: number of tree-nodes held in memory at any one time. 在任何时候存储在内存中的树节点数。
六、BFS和DFS时间和空间复杂度
- 下面是我从其他博客里找到的内容,我认为它很好介绍了BFS和DFS的时间和空间复杂度:
- 以下是我自己对这两个的理解:
- DFS 是的内存是可以少于BFS的。因为DFS 作为运用栈的算法,当算法便利完左边的节点后没发现目标节点时,DFS是完全可以删除那些没有的节点的,如下图:
-所以这就是为什么BFS和DFS的空间复杂度的不同。BFS 是 O(bd),而DFS是O(bm).这里的bd其实就是n,节点的数量。bm就和d一样是最大深度。
七、Iterative deepening search(迭代加深搜索)
- 其实就是将DFS和BFS结合起来一起用,对于一个树图进行分层,在每层使用DFS来找目标节点,如果没有到下一层,继续使用DFS 来寻找。如同:
八、Branching factor (分支因子)
- 因为我刚开始也不太知道什么是分支因子或对于一个树如何去求它的分支因子。我通过查阅发现维基百科很好的介绍什么是分支因子和如何对于一个树求分支因子。以下是引用从WIKIPEDIA:
- 简单来说Branching factor就是一个节点分支出多少个子节点。
- 而一般来说对于一个tree来说,是求它的平均分子因子,这样更方便计算和使用。而平均分支因子就是用除了根节点的总节点数量除以总非叶子节点的数量。
- 以下是一个简单的例子:
如同所示,这个树图的大小为10,则它的非根节点的节点总数为10-1=9,它的非叶子节点的数量为5。 所以它的平均分支因子为9/5,在1到2之间。
九、Reference(参考文献)
1,分支因子(百度)
2,分支因子(WIKIPEDIA)
3, 广度优先搜索
4,广度优先搜索原理与实践
5, 深度优先搜索
6,广度优先和深度优先树遍历的时间和空间复杂度是多少?
7,无信息搜索
总结
本篇写了无信息搜索,BFS和DFS分别是什么,和对比它们的时间和空间复杂度。还有简单描述了于他们相关的迭代加深搜索。(这是本人第一次写这样的文章,为了记录我的学习内容。如果幸运的你读到了这篇,希望对你有帮助。也希望大佬的你可以帮我看看我的理解是否正确。十分感谢。祝大家学业有成,工作顺利!!!)