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

  • 31Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Problem Fundamentals

List the five components of a formal search problem.

31 questions

  1. 1

    List the five components of a formal search problem.

    Model answer

    s_start (start state), actions(s) (function returning possible actions), cost(s,a) (cost of taking action a in state s), successor(s,a) (resulting state), and end(s) (boolean indicating if s is a goal state).

    Explanation

    These components define a search problem: start state, action availability, cost of actions, transition function, and goal test.

  2. 2

    Define a state in the context of search problems.

    Model answer

    A state is a summary of all past actions that is sufficient to choose future actions optimally.

    Explanation

    The state captures all necessary information from the past to make optimal decisions going forward, without needing the full history.

  3. 3

    In the city problem with forward and backward travel, why must the state include direction as well as the current city?

    Model answer

    Including direction breaks the cycle between forward and backward travel, allowing dynamic programming to be applied without infinite loops.

    Explanation

    Without direction, the state space would contain cycles (e.g., city 1 forward then city 4 forward vs city 4 backward). Adding direction makes each (city, direction) pair unique, eliminating cycles.

  4. 4

    What is memoization and how does it help in dynamic programming for search?

    Model answer

    Memoization stores the optimal cost for each state once computed, so that when the state is revisited, the stored value is reused instead of recomputing, avoiding exponential blowup.

    Explanation

    In tree search, the number of paths grows exponentially with depth. Memoization ensures each state is solved only once, reducing complexity to polynomial.

  5. 5

    What is the key difference between tree search and graph search algorithms?

    Model answer

    Tree search treats the state space as a tree and may revisit the same state along different paths, while graph search uses memoization (an explored set) to avoid revisiting states.

    Explanation

    Tree search algorithms like DFS and BFS explore the state space without tracking visited states, leading to potential exponential redundancy. Graph search (e.g., UCS with explored set) ensures each state is processed only once.

  6. 6

    In the city block problem, why can depth-first search not be used when edge costs are non-zero?

    Model answer

    Depth-first search assumes all edge costs are zero; with non-zero costs, it may not find the optimal (minimum-cost) path because it stops at the first solution found.

    Explanation

    DFS explores one branch fully before backtracking. Without costs all zero, the first path found may have arbitrarily high cost, so DFS does not guarantee optimality.

  7. 7

    Why can breadth-first search not be used if edge costs are not all equal?

    Model answer

    Breadth-first search assumes all edge costs are equal, as it explores by number of steps (levels). With unequal costs, the shortest path in terms of steps may not have the lowest total cost.

    Explanation

    BFS finds the path with the fewest edges, but if edge costs vary, that path may be more expensive than a longer path with cheaper edges.

  8. 8

    Compare dynamic programming and uniform cost search in terms of allowed cycles, allowed costs, and complexity.

    Model answer

    Dynamic programming cannot handle cycles, allows any costs (including negative), and has O(n) complexity. Uniform cost search handles cycles, requires non-negative costs, and has O(n log n) complexity.

    Explanation

    DP relies on acyclic state space; UCS uses a priority queue and can revisit states. DP works with negative costs because it assumes no cycles; UCS requires non-negative costs for correctness.

  9. 9

    What algorithm can handle cycles with negative costs that is not covered in this course?

    Model answer

    The Bellman-Ford algorithm can handle cycles with negative costs.

    Explanation

    Bellman-Ford relaxes edges repeatedly and can detect negative cycles; it is not covered in the course but mentioned as an alternative.

  10. 10

    Under what cost assumption is uniform cost search guaranteed to find the optimal solution?

    Model answer

    All edge costs must be non-negative.

    Explanation

    If costs are non-negative, UCS expands states in order of increasing cost and the first time it pops a goal state, the cost is optimal. Negative costs could cause earlier expansions with higher total cost.

  11. 11

    Describe the three sets used in uniform cost search and their roles.

    Model answer

    Explored set: states for which the optimal cost is known (popped from frontier). Frontier: states reached but not yet confirmed optimal, stored in a priority queue by past cost. Unexplored set: states not yet seen.

    Explanation

    The frontier contains candidate states; the minimum-cost state is popped and moved to explored. Its successors are added to frontier if they are not in explored (or if a better cost is found).

  12. 12

    Provide the pseudocode for the main loop of uniform cost search.

    Model answer

    Initialize frontier with (start, cost=0). While frontier not empty: pop state s with minimum past cost. If goal(s), return cost. For each (action, s', cost) from successor(s): add (s', cost + past_cost) to frontier (update if better).

    Explanation

    This loop expands the cheapest unexpanded state each iteration, ensuring that when a goal is popped, its cost is optimal.

  13. 13

    What is the runtime of uniform cost search? When does it become O(n^2 log n)?

    Model answer

    O(n log n), where n is the number of states explored. In a fully connected graph, it becomes O(n^2 log n) because each state has up to n edges.

    Explanation

    The priority queue operations are O(log n) per state. For a dense graph, the number of edges is O(n^2), leading to O(n^2 log n) total.

  14. 14

    How does uniform cost search differ from Dijkstra's algorithm?

    Model answer

    Uniform cost search stops as soon as it pops a goal state, while Dijkstra's algorithm continues until all states are explored.

    Explanation

    UCS is goal-directed: it terminates early once the optimal path to the goal is found. Dijkstra computes shortest paths to all nodes.

  15. 15

    State the correctness theorem for uniform cost search.

    Model answer

    When a state is popped from the frontier and moved to the explored set, its past cost is the minimum cost to reach that state.

    Explanation

    This is proved by showing that any alternative path must have cost at least as high, using the fact that popped states have the smallest priority in the frontier.

  16. 16

    In the proof of correctness for UCS, why must the alternative path leave the explored set at some state t?

    Model answer

    Because the alternative path starts at s_start in explored and ends at s in explored (s is popped), it must cross from explored to frontier at some edge (t -> u).

    Explanation

    If the entire alternative path stayed inside explored, it would have been considered earlier. The crossing point ensures the priority argument applies.

  17. 17

    What is the inverse problem of search in the context of learning? Give an example.

    Model answer

    Given an optimal path (sequence of actions), infer the cost function that produced it. Example: from observed human grasp trajectories, learn the cost function they optimized.

    Explanation

    Search is forward (cost -> path), learning is inverse (path -> cost). This is useful when cost is unknown but optimal behavior is observed.

  18. 18

    In the structured perceptron for learning costs, how are the weights updated?

    Model answer

    For each action in the true path, subtract 1 from its weight (to make it cheaper); for each action in the predicted path, add 1 (to make it more expensive).

    Explanation

    This update reduces the cost of the correct path and increases the cost of the incorrect predicted one, moving weights towards making the true path optimal.

  19. 19

    Why might the algorithm converge to weights that are not the true costs (e.g., 1 and 3 instead of 1 and 2)?

    Model answer

    The algorithm only needs to produce the same optimal paths as the true costs, not the exact values. Different weight combinations can yield the same optimal policy.

    Explanation

    If the training data is consistent with multiple weight settings (e.g., scaling or adding constant), the algorithm stops when no mistakes occur, which may not recover the exact original weights.

  20. 20

    If the training data only contains walk actions, can the algorithm learn the cost of tram? Why?

    Model answer

    No, because the algorithm never sees tram in the true path, so it has no signal to adjust its weight; tram's weight remains whatever it was initialized to.

    Explanation

    The update only involves actions present in the true or predicted paths. If tram never appears in either, its weight is never updated.

  21. 21

    How can the structured perceptron be generalized beyond action-dependent costs to state-action features?

    Model answer

    Represent cost as w·φ(s,a) where φ are features. Update w by subtracting feature sums of the true path and adding feature sums of the predicted path.

    Explanation

    This allows the cost to depend on state and action through features, making the model more expressive. The update becomes: w = w - Σ φ(s,a) for true path + Σ φ(s,a) for predicted path.

  22. 22

    What is the main motivation for A* over uniform cost search?

    Model answer

    A* uses a heuristic to guide search towards the goal, exploring fewer states than uniform cost search, which expands uniformly in all directions.

    Explanation

    Uniform cost search expands in order of past cost, ignoring goal location. A* uses heuristic estimate of remaining cost to prioritize states that appear closer to the goal.

  23. 23

    How does A* modify the edge costs from uniform cost search?

    Model answer

    A* uses a modified cost: cost'(s,a) = cost(s,a) + h(successor) - h(s), where h is a heuristic.

    Explanation

    This transformation makes the cumulative cost along a path equal to the actual cost plus a constant (h(goal)-h(start)), so optimizing modified cost is equivalent to optimizing actual cost.

  24. 24

    What conditions must a heuristic satisfy for A* to be consistent? State the two conditions.

    Model answer
    1. cost(s,a) + h(successor) - h(s) >= 0 (triangle inequality). 2) h(goal) = 0.

    Explanation

    Consistency ensures non-negative edge costs in the transformed problem, allowing uniform cost search (which A* reduces to) to work correctly. It also implies admissibility.

  25. 25

    Prove that if h is consistent, then A* returns the optimal solution.

    Model answer

    Cumulative modified cost along any path = sum(cost) + h(goal) - h(start) = actual cost - h(start) (since h(goal)=0). So optimizing modified cost is equivalent to optimizing actual cost. Since A* is uniform cost search with non-negative costs (by consistency), it finds the optimal solution.

    Explanation

    The telescoping sum cancels intermediate heuristics. Consistent heuristics guarantee non-negative modified costs, so UCS correctness applies.

  26. 26

    Why is A* more efficient than uniform cost search? What is the condition for states explored?

    Model answer

    A* explores states with g(s) + h(s) < g*(goal) (optimal cost), whereas UCS explores states with g(s) < g*(goal). Since h(s) is an estimate, the inequality is stricter, reducing explored set.

    Explanation

    A larger heuristic (closer to true future cost) results in fewer states explored. In the extreme, if h equals future cost, only states on the optimal path are explored.

  27. 27

    What is an admissible heuristic? How does it relate to consistency?

    Model answer

    An admissible heuristic satisfies h(s) <= futureCost(s) for all s. Consistency implies admissibility (by induction), but admissibility alone does not guarantee consistency.

    Explanation

    Admissibility ensures the heuristic never overestimates; it is a weaker condition than consistency. For A* optimality, consistency (or at least admissibility with a graph search) is required.

  28. 28

    Explain the relaxation method for constructing heuristics. Give an example from the lecture.

    Model answer

    Remove constraints from the original problem to make it easier, then use the optimal cost of the relaxed problem as the heuristic. Example: in robot navigation, remove walls and use Manhattan distance.

    Explanation

    Relaxation typically makes the problem solvable in closed form or via simple computation, providing an optimistic (admissible) estimate of future cost because fewer constraints can only reduce cost.

  29. 29

    In the eight-puzzle example, what relaxation yields a heuristic? What is the resulting heuristic?

    Model answer

    Relaxing the constraint that tiles cannot overlap yields the heuristic: sum of Manhattan distances of each tile to its goal position.

    Explanation

    When tiles can overlap, each tile moves independently, so the optimal cost is the sum of individual Manhattan distances. This is a common heuristic for the 8-puzzle.

  30. 30

    When using relaxation, why might you need to solve a reverse problem to compute future costs via uniform cost search?

    Model answer

    Uniform cost search computes past costs from the start; to compute future costs (cost to goal) for all states, you need to run UCS on the reversed graph (edges reversed) starting from the goal.

    Explanation

    Since UCS is designed for past costs, you reverse the graph so that the goal becomes the start, and then the past cost from reversed start is the future cost in the original.

  31. 31

    What is the effect of relaxation on edge costs?

    Model answer

    Relaxation typically reduces edge costs from infinity (or very high) to finite values, because constraints that prevented direct transitions are removed.

    Explanation

    In the original problem, some actions may be prohibited (cost infinity). Relaxation removes those prohibitions, making those actions feasible with finite cost, thereby making the problem easier.

1 of 31
Question 1 of 31

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent