Uninformed Search Strategy
- Definition: A search strategy that does not use heuristic information.
- Characteristics:
- No direction knowledge
- Works for general problems but inefficient
- Useful when no heuristic function is available
Search Strategy
- Choose an option → If incorrect, keep other options for later.
- The challenge: Which option should be chosen first?
Node Components
- STATE - Current state in the search space.
- PARENT - Where it was generated from.
- ACTION - Action used to generate it.
- PATH-COST - Cost from the initial state to the node.
- DEPTH - Steps from the initial state.
Queue Types
- FIFO (First-In, First-Out) - Used in BFS.
- LIFO (Last-In, First-Out) - Used in DFS.
- Priority Queue - Used in A Search*.
搜索算法性能衡量与不同搜索策略
在人工智能和计算机科学中,搜索算法的性能决定了解决问题的效率。我们可以通过完备性(Completeness)、最优性(Optimality)、时间复杂度(Time Complexity)和空间复杂度(Space Complexity)等指标来衡量搜索策略的优劣。此外,搜索策略可以分为无信息搜索(Uninformed Search)和有信息搜索(Informed Search),不同策略适用于不同的应用场景。本文将详细介绍这些概念。
1. 搜索算法的性能衡量标准
1.1 完备性(Completeness)
完备性指的是算法是否一定能找到解。如果一个搜索算法总是能够找到可达解,则它是完备的。
此外,还需要考虑:
- 算法是否会陷入无限循环(如深度优先搜索可能会陷入死循环)。
- 是否能够避免重复状态,提高搜索效率。
1.2 最优性(Optimality)
最优性指的是找到的解是否是最优解,即是否找到代价最小的路径。例如:
- 广度优先搜索(BFS) 在代价一致时能保证最优解。
- A 搜索算法* 在满足某些条件下可以找到最优解。
1.3 时间复杂度(Time Complexity)
时间复杂度表示搜索算法找到解所需的时间,通常用节点扩展的数量衡量。
时间复杂度的计算涉及以下参数:
- b(分支因子):每个节点的平均子节点数。
- d(目标节点的最浅深度):找到解时的最小步数。
- m(状态空间的最大深度):问题的最大可能路径。
通常,时间复杂度表示为 O(b^d) 或 O(b^m)。
1.4 空间复杂度(Space Complexity)
空间复杂度表示搜索过程中需要存储的最大节点数,也可以用O(b^d) 或 O(b^m) 表示。
2. 时间与空间复杂度的计算
时间与空间复杂度通常由以下因素决定:
- b(分支因子):每个节点可扩展的最大子节点数。
- d(目标节点的深度):最优解所在的最小深度。
- m(状态空间的最大深度):搜索树的最大可能路径。
计算时通常使用 大 O 记号(Big-O notation) 来衡量复杂度。例如:
- 广度优先搜索(BFS) 的时间复杂度为 O(b^d),空间复杂度也为 O(b^d)。
- 深度优先搜索(DFS) 的时间复杂度为 O(b^m),空间复杂度为 O(bm)(只存储路径上的节点)。
3. 搜索策略分类
3.1 无信息搜索(Uninformed Search)
无信息搜索(又称盲目搜索)不使用额外的启发信息,仅依赖基本的搜索规则遍历搜索空间。主要包括:
- 广度优先搜索(BFS)
- 深度优先搜索(DFS)
- 一致代价搜索(Uniform Cost Search)
- 深度限制搜索(Depth-limited Search)
- 迭代加深搜索(Iterative Deepening Search)
3.2 有信息搜索(Informed Search / Heuristic Search)
有信息搜索使用启发式函数(Heuristic Function) 来指导搜索,使得算法更高效。
常见的启发式搜索算法:
- A 搜索*
- 贪心最佳优先搜索(Greedy Best-First Search)
4. 具体搜索算法解析
4.1 广度优先搜索(BFS)
广度优先搜索使用FIFO 队列(先进先出),按照层次展开搜索,确保最优解。
BFS 伪代码
BREADTH-FIRST-SEARCH(problem)
1. 初始化:
- 创建一个 FIFO 队列 frontier,存入初始节点
- 创建 explored 集合,存储已访问节点
2. 进入循环:
- 若 frontier 为空,返回失败
- 取出队列头部节点 node
- 若 node 是目标状态,返回成功
- 遍历 node 的所有子节点 child:
- 若 child 不在 frontier 和 explored 中,加入 frontier
BFS 的时间复杂度和空间复杂度:O(b^d)。
4.2 深度优先搜索(DFS)
深度优先搜索使用LIFO 栈(后进先出),优先沿着路径向下探索,适合解决空间复杂度较大的问题。
DFS 伪代码
DEPTH-FIRST-SEARCH(problem)
1. 初始化:
- 创建一个 LIFO 栈 frontier,存入初始节点
- 创建 explored 集合,存储已访问节点
2. 进入循环:
- 若 frontier 为空,返回失败
- 取出栈顶节点 node
- 若 node 是目标状态,返回成功
- 遍历 node 的所有子节点 child:
- 若 child 不在 frontier 和 explored 中,加入 frontier
DFS 的时间复杂度:O(b^m),空间复杂度 O(bm)。
5. 总结
-
衡量搜索算法的性能主要考虑:
- 完备性(能否找到解)
- 最优性(找到的解是否最优)
- 时间复杂度(搜索所需时间)
- 空间复杂度(存储需求)
-
时间复杂度计算时,主要参数包括:
- b(分支因子):每个节点的最大子节点数
- d(最小目标深度)
- m(最大路径长度)
-
搜索策略分类:
- 无信息搜索(Uninformed Search):不依赖启发信息(如 BFS, DFS)。
- 有信息搜索(Informed Search):使用启发式指导搜索(如 A*)。
-
广度优先搜索(BFS)适用于:需要最优解的情况,但占用较大内存。
-
深度优先搜索(DFS)适用于:内存受限的问题,但不保证最优解。
📌 英文翻译:Searching Algorithm Performance & Strategies
1. Performance Metrics
- Completeness: Can a solution always be found?
- Optimality: Is the solution the best among possible solutions?
- Time Complexity: How long does it take to find a solution?
- Space Complexity: How much memory is required?
2. Time & Space Complexity Calculation
- b: Branching factor (number of successors per node)
- d: Depth of the shallowest goal node
- m: Maximum path length
Complexity measured using Big-O notation:
- BFS: O(b^d)
- DFS: O(b^m)
3. Search Strategies
- Uninformed Search: No heuristic, includes BFS, DFS.
- Informed Search: Uses heuristics, includes A*.
4. BFS vs DFS
- BFS: Guarantees optimal solution, but uses more memory.
- DFS: Uses less memory, but may not find the best solution.
📚 考试笔记(Exam Notes)
- BFS: FIFO Queue, O(b^d).
- DFS: LIFO Stack, O(b^m).
- Time Complexity: O(b^d) vs O(b^m).
- Uninformed vs Informed Search: Blind vs Guided.
1.2 Optimality Conditions of A Search Algorithm*
English Explanation
-
Admissible Heuristic
The heuristic function h(n)h(n) must never overestimate the true cost h∗(n)h^*(n) from node nn to the goal.
Example: In grid-based maps, Manhattan distance or Euclidean distance is commonly used as a heuristic estimate. -
Consistent Heuristic
h(n)≤c(n,m)+h(m)h(n) \leq c(n, m) + h(m)
For every pair of adjacent nodes nn and mm, the heuristic must satisfy:where c(n,m)c(n, m) is the movement cost between nodes nn and mm. This ensures path expansion consistency and prevents unnecessary backtracking.
-
Finite Problem Domain
The graph must contain a finite number of nodes; otherwise, the algorithm may enter an infinite loop. -
Non-Negative Path Costs
The actual cost g(n)g(n) of all paths must be non-negative, ensuring the validity of physical quantities such as time and distance.
📌 考试笔记(Exam Notes)
BFS
- FIFO queue, expands level by level.
- Complexity: O(b^d) (time & space).
- Best for shortest path problems.
UCS
- Uses priority queue, always expands the lowest-cost node.
- Guarantees optimal path.
- Time complexity: O(b^d).
DFS
- LIFO stack, expands deepest nodes first.
- Complexity: O(b^m) time, O(bm) space.
- Best for deep search spaces.
一、问题定义的四个要素(就像规划一次旅行)
-
初始状态
- 你现在的位置,比如“在家门口”。
-
可能的行动
- 你能做的动作,比如“开车、坐地铁、步行”。
-
目标状态
- 你想去的地方,比如“市中心的书店”。
-
路径代价
- 每种选择的成本,比如“开车要油费,坐地铁要时间,步行免费但累”。
例子:
走迷宫问题 = 初始位置(入口)→ 行动(上下左右移动)→ 目标(出口)→ 代价(步数最少)。
二、测量问题解决的性能(像评价导航APP的好坏)
-
**时间快吗?**(时间复杂度)
- 比如:BFS(广度优先)像地毯式搜索,速度慢;DFS(深度优先)像一条路走到底,可能更快找到解,但不一定最优。
-
**内存大吗?**(空间复杂度)
- BFS需要记住所有可能的路径,内存爆炸;DFS只需要记住当前路径,内存小。
-
**能保证找到最优解吗?**(最优性)
- BFS和Uniform-cost(均一成本)像“强迫症”,必须找到最短路径;DFS可能找到一条路就停,不保证最短。
-
**能解决问题吗?**(完备性)
- 比如:无限深的树中,DFS可能永远找不到解,BFS则能保证找到(如果解存在)。
三、六大搜索策略的原则(像不同的找人策略)
-
广度优先(BFS)
- 原则:像“水波纹扩散”,一层层找。
- 例子:在迷宫中,先检查所有离起点1步的位置,再检查2步的位置……保证找到最短路径,但内存消耗大。
-
均一成本(Uniform-cost)
- 原则:优先走“当前已知最便宜的路”。
- 例子:导航APP实时计算路线,优先推荐高速费最少(或时间最短)的路径,类似Dijkstra算法。
-
深度优先(DFS)
- 原则:像“钻牛角尖”,一条路走到黑,走不通再回头。
- 例子:迷宫中选择一个方向走到死胡同,再回上一个岔路换方向。内存小,但可能绕远路。
-
深度限制(Depth-limited)
- 原则:给DFS加一个“探索深度上限”,避免无限下钻。
- 例子:找人时规定“最多找3条街”,找不到就放弃。
-
迭代加深(Depth-Deepening)
- 原则:结合BFS和DFS,先浅层DFS,再逐步加深深度。
- 例子:找钥匙时,先翻抽屉第一层,没有就翻第二层……直到找到。
-
深度延长(排版疑似错误,可能指其他策略)
- (此处可能是排版问题,或指动态调整搜索深度,暂不展开)
四、这些策略的对比(像选不同的交通工具)
策略 | 优点 | 缺点 | 适用场景 |
---|---|---|---|
广度优先 | 保证最短路径 | 内存爆炸 | 小规模迷宫、树搜索 |
均一成本 | 边权不同时仍最优 | 比BFS稍慢 | 带权重的路径规划 |
深度优先 | 内存小,适合深问题 | 可能绕远路、死循环 | 解空间深,不求最优 |
迭代加深 | 内存小且保证最优 | 重复搜索浅层节点 | 未知深度的问题 |
通俗总结
-
搜索策略的核心矛盾:
“快和省内存不可兼得”——想要快(DFS),可能绕路;想要省内存(DFS),可能不最优;想要又省内存又最优(迭代加深),就得牺牲时间。 -
实际应用:
导航软件用均一成本(Dijkstra/A*)找最短路径;游戏AI用BFS/DFS生成地图;智能客服用深度限制搜索快速回答用户问题。
Below is a concise cheat sheet for quick memorization, focusing on the key ideas and properties of Depth-Limited Search, Iterative Deepening Search, and Iterative Lengthening Search—especially useful for exam revision.
Depth-Limited Search (DLS)
- Definition: A form of Depth-First Search (DFS) with a fixed maximum depth dd.
- Pros:
- Straightforward modification of DFS.
- Can avoid infinite-depth pitfalls.
- Cons:
- Not guaranteed to find a solution if the true solution depth > dd.
- Not optimal (might miss shallower solutions).
- Completeness: Only if dd is large enough and state space is finite.
- Use Case: When you have a reasonable guess for the solution depth.
Iterative Deepening Search (IDS)
- Definition: Increases the depth limit step by step: try d=0, then d=1, d=2, etc.
- Pros:
- Combines BFS’s completeness/optimality (for uniform-cost edges) with DFS’s low memory usage.
- Finds the shallowest goal first ⇒ optimal when all edges have the same cost.
- Cons:
- May repeat states multiple times (due to repeated DFS at each depth).
- Completeness: Yes, when the branching factor is finite.
- Use Case: When you don’t know the solution depth but still want BFS-like optimality in a large search space.
Iterative Lengthening Search (ILS)
- Definition: Similar to IDS but with path cost as the limit (rather than depth). Increments the maximum cost allowed each iteration.
- Pros:
- An iterative version of Uniform-Cost Search (UCS).
- Finds the least-cost path (like UCS).
- Uses lower memory than a single full UCS run.
- Cons:
- Each increase in cost limit restarts the search ⇒ repeated work.
- Completeness/Optimality:
- Optimal when path costs are non-negative.
- Complete in a finite state space.
- Use Case: When path costs vary widely or are unknown, and you want guaranteed least-cost solutions.
Remember
- DLS: DFS + depth cap; easy but not optimal.
- IDS: Depth-limited DFS repeated; BFS-like guarantees, DFS-like memory.
- ILS: Cost-limited search repeated; UCS-like optimality, iterative overhead.