1. Home
  2. Explore
  3. Computer Science
  4. Search Algorithms Lecture

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Search Algorithms Lecture

  • 17Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Algorithm Review

In the city block problem described in the lecture, which search algorithms can be used to find the optimal path from City 1 to City n and back to City 1, given non-negative edge costs cijc_{ij}cij​ that are not necessarily uniform?

17 questions

  1. 1

    In the city block problem described in the lecture, which search algorithms can be used to find the optimal path from City 1 to City n and back to City 1, given non-negative edge costs cijc_{ij}cij​ that are not necessarily uniform?

    1. A

      Breadth-first search and uniform cost search only

    2. B

      Depth-first search and dynamic programming only

    3. C

      Depth-first search and breadth-first search only

    4. D

      Dynamic programming and uniform cost search only

    Correct answer
    D

    Dynamic programming and uniform cost search only

    Explanation

    Depth-first search requires zero costs, and breadth-first search requires uniform costs. Since cij≥0c_{ij} \geq 0cij​≥0 but not necessarily uniform, only dynamic programming (which allows cycles when state includes direction) and uniform cost search (which handles non-negative costs and cycles) are applicable.

  2. 2

    Why can't depth-first search be used in the city block problem with non-zero edge costs?

    1. A

      Depth-first search requires all edge costs to be zero.

    2. B

      Depth-first search cannot handle cycles.

    3. C

      Depth-first search only works for tree-structured state spaces.

    4. D

      Depth-first search requires uniform edge costs.

    Correct answer
    A

    Depth-first search requires all edge costs to be zero.

    Explanation

    Depth-first search assumes that reaching any goal state is sufficient, which works only if all edges have zero cost. Non-zero costs make the path cost matter, so DFS does not guarantee optimality.

  3. 3

    What is a state in the context of search problems?

    1. A

      The set of all actions available at a given point.

    2. B

      The current location of the agent in the environment.

    3. C

      A summary of all past actions sufficient to choose future actions optimally.

    4. D

      The cost incurred so far from the start state.

    Correct answer
    C

    A summary of all past actions sufficient to choose future actions optimally.

    Explanation

    A state is defined as a summary of all past actions that are sufficient for optimal future decision-making. It may include more than just location, e.g., direction in the back-and-forth city problem.

  4. 4

    In the back-and-forth city problem (City 1 to City n forward, then back to City 1 backward), how can dynamic programming be applied despite the apparent cycle?

    1. A

      By ignoring the return trip and solving only the forward path.

    2. B

      By setting all edge costs to zero and using uniform cost search.

    3. C

      By extending the state to include both city and direction of travel.

    4. D

      By using depth-first search with memoization to break cycles.

    Correct answer
    C

    By extending the state to include both city and direction of travel.

    Explanation

    Including direction in the state (e.g., City 4 going forward vs. City 4 going backward) breaks the cycle, making the state space acyclic. Dynamic programming can then be applied.

  5. 5

    In uniform cost search, what data structure is used to manage the frontier?

    1. A

      A stack

    2. B

      A queue

    3. C

      A priority queue

    4. D

      A hash set

    Correct answer
    C

    A priority queue

    Explanation

    Uniform cost search uses a priority queue (often implemented as a min-heap) to efficiently pop the state with the smallest past cost from the frontier.

  6. 6

    What is the runtime complexity of uniform cost search when the number of states explored is nnn?

    1. A

      O(2n)O(2^n)O(2n)

    2. B

      O(n2)O(n^2)O(n2)

    3. C

      O(nlog⁡n)O(n \log n)O(nlogn)

    4. D

      O(n)O(n)O(n)

    Correct answer
    C

    O(nlog⁡n)O(n \log n)O(nlogn)

    Explanation

    The runtime is O(nlog⁡n)O(n \log n)O(nlogn) due to priority queue operations (pop and update) for each state, assuming a sparse graph. In worst-case dense graphs, it may be O(n2log⁡n)O(n^2 \log n)O(n2logn).

  7. 7

    The correctness theorem for uniform cost search states that when a state sss is popped from the frontier, its priority (past cost) is:

    1. A

      The cost of the first path found to sss.

    2. B

      An upper bound on the optimal cost to sss.

    3. C

      The minimum possible cost to reach sss from the start.

    4. D

      The maximum possible cost to reach sss from the start.

    Correct answer
    C

    The minimum possible cost to reach sss from the start.

    Explanation

    The theorem proves that when sss is popped, the past cost is the optimal (minimum) cost to reach sss. The proof uses the explored set and the fact that any alternative path must have higher or equal cost.

  8. 8

    Which of the following is a key difference between dynamic programming and uniform cost search?

    1. A

      Dynamic programming cannot handle negative costs, while uniform cost search can.

    2. B

      Dynamic programming has O(nlog⁡n)O(n \log n)O(nlogn) runtime; uniform cost search is O(n)O(n)O(n).

    3. C

      Uniform cost search handles cycles; dynamic programming requires a DAG.

    4. D

      Uniform cost search requires the cost to be the same for all actions.

    Correct answer
    C

    Uniform cost search handles cycles; dynamic programming requires a DAG.

    Explanation

    Uniform cost search can handle cycles (by revisiting nodes with better costs), while dynamic programming typically requires a DAG or a state space made acyclic by state augmentation. Dynamic programming runs in O(n)O(n)O(n) and handles arbitrary costs (including negative) as long as no negative cycles.

  9. 9

    When the costs of actions are unknown, but we have data on optimal paths, what is the inverse problem called?

    1. A

      Cost relaxation

    2. B

      Reinforcement learning

    3. C

      Structured perceptron learning

    4. D

      Heuristic search

    Correct answer
    C

    Structured perceptron learning

    Explanation

    The lecture describes learning costs from optimal paths as an inverse problem, and presents the structured perceptron algorithm for this purpose. It is not reinforcement learning (which involves reward and exploration) but a supervised learning approach.

  10. 10

    In the structured perceptron algorithm for learning action costs, how are weights updated after each example?

    1. A

      Randomly perturb weights and keep the change if prediction improves.

    2. B

      Set weights equal to the count of each action in the true path.

    3. C

      Decrease weights for actions in the true path and increase weights for actions in the predicted path.

    4. D

      Increase weights for actions in both the true and predicted paths.

    Correct answer
    C

    Decrease weights for actions in the true path and increase weights for actions in the predicted path.

    Explanation

    The algorithm subtracts 1 from the weight of each action in the true path (to make it cheaper) and adds 1 to each action in the predicted path (to make it more expensive), encouraging the model to favor the true path.

  11. 11

    What is the purpose of the heuristic function h(s)h(s)h(s) in A* search?

    1. A

      To store the past cost from the start to state sss.

    2. B

      To replace the actual edge costs with a simpler function.

    3. C

      To ensure the search explores all states uniformly.

    4. D

      To estimate the future cost from state sss to the goal.

    Correct answer
    D

    To estimate the future cost from state sss to the goal.

    Explanation

    The heuristic h(s)h(s)h(s) provides an estimate of the optimal cost from sss to the goal (future cost). A* uses g(s)+h(s)g(s) + h(s)g(s)+h(s) to order exploration, where g(s)g(s)g(s) is the past cost.

  12. 12

    How does A* search modify the edge costs to incorporate a heuristic?

    1. A

      It multiplies each edge cost by the heuristic value of the current state.

    2. B

      It subtracts the heuristic of the current state from the edge cost.

    3. C

      It replaces the edge cost with the heuristic difference: c′(s,a)=c(s,a)+h(s′)−h(s)c'(s,a) = c(s,a) + h(s') - h(s)c′(s,a)=c(s,a)+h(s′)−h(s).

    4. D

      It adds the heuristic value of the successor to the edge cost.

    Correct answer
    C

    It replaces the edge cost with the heuristic difference: c′(s,a)=c(s,a)+h(s′)−h(s)c'(s,a) = c(s,a) + h(s') - h(s)c′(s,a)=c(s,a)+h(s′)−h(s).

    Explanation

    A* transforms the cost of each edge to c′(s,a)=c(s,a)+h(s′)−h(s)c'(s,a) = c(s,a) + h(s') - h(s)c′(s,a)=c(s,a)+h(s′)−h(s), where s′s's′ is the successor. This encourages moving toward states with lower heuristic values.

  13. 13

    A heuristic hhh is consistent if it satisfies which condition?

    1. A

      h(s)≤h(s′)h(s) \leq h(s')h(s)≤h(s′) for all s′s's′ reachable from sss.

    2. B

      h(s)≥0h(s) \geq 0h(s)≥0 for all states and h(sgoal)=0h(s_{goal}) = 0h(sgoal​)=0.

    3. C

      c(s,a)+h(s′)≥h(s)c(s,a) + h(s') \geq h(s)c(s,a)+h(s′)≥h(s) for all transitions and h(sgoal)=0h(s_{goal}) = 0h(sgoal​)=0.

    4. D

      h(s)=0h(s) = 0h(s)=0 for all states.

    Correct answer
    C

    c(s,a)+h(s′)≥h(s)c(s,a) + h(s') \geq h(s)c(s,a)+h(s′)≥h(s) for all transitions and h(sgoal)=0h(s_{goal}) = 0h(sgoal​)=0.

    Explanation

    Consistency requires c(s,a)+h(s′)≥h(s)c(s,a) + h(s') \geq h(s)c(s,a)+h(s′)≥h(s) (triangle inequality) and h(sgoal)=0h(s_{goal}) = 0h(sgoal​)=0. This ensures the transformed costs c′(s,a)c'(s,a)c′(s,a) are non-negative and that hhh is admissible.

  14. 14

    If a heuristic is consistent, what additional property does it automatically satisfy?

    1. A

      Dominance: h(s)≥0h(s) \geq 0h(s)≥0 only.

    2. B

      Monotonicity: h(s)≥h(s′)h(s) \geq h(s')h(s)≥h(s′) for all successors s′s's′.

    3. C

      Optimality: h(s)=FutureCost(s)h(s) = \text{FutureCost}(s)h(s)=FutureCost(s) for all sss.

    4. D

      Admissibility: h(s)≤FutureCost(s)h(s) \leq \text{FutureCost}(s)h(s)≤FutureCost(s) for all sss.

    Correct answer
    D

    Admissibility: h(s)≤FutureCost(s)h(s) \leq \text{FutureCost}(s)h(s)≤FutureCost(s) for all sss.

    Explanation

    Consistency implies admissibility. An admissible heuristic never overestimates the true future cost. The proof uses induction: for the goal it holds, and consistency ensures the condition propagates backward.

  15. 15

    What is the benefit of using a larger (but still admissible) heuristic in A* search?

    1. A

      It allows negative edge costs in the transformed problem.

    2. B

      It guarantees finding the goal with zero exploration.

    3. C

      It reduces the number of states explored, making the search more efficient.

    4. D

      It increases the search space to ensure optimality.

    Correct answer
    C

    It reduces the number of states explored, making the search more efficient.

    Explanation

    A larger admissible heuristic provides a better estimate of future cost, focusing the search more toward the goal and reducing the number of states with g(s)+h(s)g(s) + h(s)g(s)+h(s) less than the optimal cost. This improves efficiency.

  16. 16

    In the 8-puzzle, a common heuristic is the Manhattan distance sum. What relaxation does this heuristic correspond to?

    1. A

      Removing the goal state constraints.

    2. B

      Allowing tiles to move through each other (overlap).

    3. C

      Allowing any tile to move to any empty space instantly.

    4. D

      Allowing tiles to move diagonally.

    Correct answer
    B

    Allowing tiles to move through each other (overlap).

    Explanation

    Manhattan distance sum relaxes the constraint that tiles cannot occupy the same square. By assuming tiles can overlap, each tile can move independently to its goal, giving a lower bound on actual moves.

  17. 17

    What is the main idea behind deriving heuristics through relaxation?

    1. A

      Remove some constraints from the original problem and solve the easier problem to get an estimate.

    2. B

      Assume all edge costs are zero and use breadth-first search.

    3. C

      Add extra constraints to make the problem more realistic.

    4. D

      Use machine learning to train a heuristic from data.

    Correct answer
    A

    Remove some constraints from the original problem and solve the easier problem to get an estimate.

    Explanation

    Relaxation simplifies the problem by removing constraints, making it solvable (often with closed-form or efficient algorithms). The optimal cost of the relaxed problem is a heuristic (lower bound) for the original problem.

Question 1 of 17
Question 1 of 17

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent