1. Home
  2. Explore
  3. Computer Science
  4. Search Algorithms and Intuition

Study methods

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

Search Algorithms and Intuition

Speaker 1Speaker 2

Search Algorithms and Intuition

11:19
0:00-11:19
  1. Michael

    Today we’re talking about search—not just as a way to get from one place to another, but as a way to understand how a system explores choices. We’ll compare several strategies, see what they trade off, and then connect search to the way a program can interpret a story.

  2. Hope

    And the map examples are just a convenient illustration. Search isn’t really about maps; it’s about choosing what to examine next when there are multiple possibilities.

  3. Michael

    Exactly. A person can often glance at a map and find a pretty good route almost immediately. We don’t have a complete account of how human visual processing makes that possible, so the search procedures we’re discussing are ways programs can work without eyes or visually grounded algorithms.

  4. Hope

    The Cambridge cab-driver comparison makes that distinction vivid. A driver who behaves like a thief might take a terrible route, a beginner might find a decent route, and a highly experienced, physics-Ph.D.-after-three-postdocs driver might find the optimal one. The point is to understand different ways of searching—not to claim they reproduce the visual intuition people use.

  5. Michael

    Let’s begin with the deliberately unhelpful strategy called the British Museum approach: find every possible path. Starting at s, we can go to a or b. We list choices in lexical order—alphabetically—so the search tree has a consistent order.

  6. Hope

    And there’s an important rule: a path can’t loop back through a place it already contains. So if we’ve gone from s to a, we don’t then return to s and keep going around. That restriction keeps the paths from biting their own tails.

  7. Michael

    From a, the choices are b and d; from b, they’re a and c. Following the branches, the paths include s-a-b-c-e, s-a-d-g, s-b-a-d-g, and s-b-c-e. The British Museum search enumerates the whole set rather than stopping at the first goal.

  8. Hope

    Which is why cleverness doesn’t save much work there: if the requirement is to find every possible path, you have to find them all. It’s a useful contrast, but generally not the search we want when finding one route is enough.

  9. Michael

    A more practical strategy is depth-first search. It follows one branch as far as it can, using the chosen ordering—in our example, the left or alphabetically earlier choice—before considering alternatives.

  10. Hope

    So it might go s-a-b-c-e and discover that e is a dead end. That doesn’t mean the whole search has failed. It can back up to the most recent place where it had another choice, then try the other branch.

  11. Michael

    That recovery step is called backtracking. It would return to the choice between b and d at a, then try s-a-d-g. Backtracking is an optional add-on in the way this material defines depth-first search, though it’s usually a very sensible one; a quiz problem should say whether to use it.

  12. Hope

    The companion strategy is breadth-first search. Instead of plunging down one branch, it explores the tree level by level: first paths one step long, then paths two steps long, and so on, until it reaches a level containing the goal.

  13. Michael

    That can find a path, but it may build up many possibilities along the way. In the map example, it can spend a lot of effort exploring to the left even when the goal is nearby in another direction. The search order follows path length, not how promising a direction looks.

  14. Hope

    We can express both strategies with one basic algorithm. Keep a queue of paths under consideration, start it with the one-node path s, take a path from the queue, check whether it reaches the goal, and, if not, extend it and put the resulting paths back.

  15. Michael

    The key difference is where the new paths go. For depth-first search, put extensions at the front of the queue, so the search keeps pursuing the paths it just created. For breadth-first search, put them at the back, so older paths at the current level get considered first.

  16. Hope

    That’s a small implementation change with a big effect on the order of exploration. The goal test can happen when a path is taken from the queue; if it’s a winner, stop, and otherwise extend it.

  17. Michael

    There’s another inefficiency: different paths can reach the same node. A straightforward search might extend a path ending at a even though it has already extended another path ending at a. That repeats work.

  18. Hope

    The proposed fix is to keep a record of nodes that have already been the final node of an extended path. If a new path ends at a node on that record, don’t extend it again. The lecturer calls this an extended list; elsewhere the discussion refers to keeping track of already-queued or extended places, but the essential idea is avoiding repeated expansion.

  19. Michael

    That filter can help depth-first and breadth-first search, but it doesn’t help the British Museum strategy, whose whole purpose is to enumerate every path. Backtracking is useful for depth-first search, while it doesn’t add value to breadth-first search in this setup.

  20. Hope

    Even with that efficiency improvement, ordinary depth-first and breadth-first search don’t know whether a choice is taking them nearer to the goal. If we have a useful estimate of distance, we can make search more informed.

  21. Michael

    That leads to hill climbing. It’s like depth-first search, except the choices are ordered by which next node seems closer to the goal rather than simply by lexical order. In the example, b is closer to the goal than a, so the search chooses b first.

  22. Hope

    If two choices seem equally close, the lexical convention can break the tie. Then the search continues from the chosen node, always preferring the direction that appears to make progress. That can produce a much straighter search and require fewer queue operations than a roundabout depth-first search.

  23. Michael

    But hill climbing doesn’t guarantee the best path, and a heuristic can mislead it. A path that looks closer can lead into a blind alley. The examples show why the estimate is helpful when available, not that it’s infallible.

  24. Hope

    There’s a useful distinction here: British Museum, depth-first, and breadth-first search aren’t using information about distance to the goal. Hill climbing is informed because it uses that extra heuristic information. If a problem gives you no meaningful way to estimate progress, you can’t use that particular guidance.

  25. Michael

    The breadth-first counterpart is beam search. It begins by exploring level by level, but limits how many paths it keeps at each level. That limit is called the beam width.

  26. Hope

    With a beam width of two, for example, you keep only the two paths judged closest to the goal and discard the rest. Then you extend those survivors and again retain the best two. It can avoid spending time on far-off branches, but it deliberately throws away possibilities.

  27. Michael

    That’s why it can be more focused than ordinary breadth-first search. In the example, it retains the promising paths, reaches the goal, and doesn’t fan out broadly to the left just because those branches are at the same depth.

  28. Hope

    The queue perspective makes these variations easy to compare. Depth-first puts new paths at the front. Breadth-first puts them at the back. Hill climbing puts new paths at the front, ordered by the heuristic. Beam search keeps the w best paths, where w is the chosen beam width.

  29. Michael

    There’s also best-first search. Instead of committing to one branch or one whole level, it repeatedly works on whichever leaf of the search tree is currently closest to the goal. So its attention can jump between different parts of the tree.

  30. Hope

    That kind of jumping also appears in the integration program mentioned in the lecture: it can work on the easiest problem in an and/or tree, even if that problem lies on a different branch. The general idea is to prioritize the most promising available piece.

  31. Michael

    Hill climbing also has special difficulties in continuous spaces. Imagine being in fog on a mountain and checking a few possible directions—north, south, east, and west—to see which seems to go upward. You choose the best one and repeat.

  32. Hope

    One risk is a local maximum: you reach a point higher than its surroundings, but not the highest point overall. The search can get stuck there because its local choices don’t reveal a better direction.

  33. Michael

    A second risk is a flat region, sometimes illustrated as the telephone-pole problem. If the surface is level, trying nearby directions gives no useful signal about which way goes upward. The lecture connects this to broad, flat areas on the shoulders of Mount Washington, where hill climbing may fail to guide someone to the ranger station.

  34. Hope

    And there’s a subtler problem: a ridge can run diagonally across the terrain. If you test only north, south, east, and west, every step may appear to go downhill, even though you’re standing on a rising ridge. You can mistakenly conclude you’re at the top.

  35. Michael

    That issue can be especially acute in high-dimensional spaces. The lesson is that a local rule—move in the direction that looks best among the directions you checked—depends on what the space looks like and which directions the algorithm can examine.

  36. Hope

    Now let’s connect search to intelligence. Whenever we make a plan, we evaluate choices and consider how they might work out. So search is relevant not just to routes, but to models of the kinds of reasoning people do.

  37. Michael

    The lecture’s story example uses a system that reads a Macbeth story and builds what it calls an elaboration graph. The story and its background knowledge are expressed in English, and the system also has higher-level knowledge about concepts such as revenge.

  38. Hope

    There’s no free lunch in preparing the material. People can rewrite a story in very simple English, or they can use a more natural adult version and add annotations that help the system absorb it. In the example, Story Workbench and the Genesis system had been connected so it could work with more natural English.

  39. Michael

    Once the elaboration graph is built, the system can search it for patterns. It finds revenge by looking for a description of revenge in the graph. The match can draw on things stated explicitly in the story and things added through if-then rules, such as common-sense knowledge.

  40. Hope

    It can also find a Pyrrhic victory: a situation that seems to go well at first but ends badly. Macbeth wants to become king and does become king, but he is eventually killed as a consequence. The system identifies that pattern by searching the graph.

  41. Michael

    Then it can answer a question such as why Macduff killed Macbeth. For a common-sense answer, it can look locally at connections in the goal tree. For a reflective answer, it can report the higher-level patterns its searches found—such as revenge or Pyrrhic victory—involving that event.

  42. Hope

    So search here isn’t merely finding a route through a map. It’s also finding meaningful structures in a story and using them to answer questions. The system can report the results in English, and the lecture notes that language generation had recently been connected to the parser system running in reverse.

  43. Michael

    That brings the ideas together: search is a family of strategies for choosing what to examine, from exhaustive enumeration to guided exploration. The right choice affects what gets explored, how much work is done, and whether useful structure—like a route or a story pattern—can be found.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent