Greedy Best-First Search — AI Technical Interview Questions & Answers

Greedy Best-First Search

Greedy Best-First Search

  • Greedy best-first expands the node that looks closest to the goal (smallest h only). Fast, not guaranteed optimal. Can walk into a dead alley. A* adds g so you don’t ignore cost already paid.
  • Greedy Best-First Search — output: three exam lines. Graph on paper first.
  start
    ├── BFS  queue
    ├── DFS  stack
    └── A*   g+h
    │
    ▼
   goal

Technical Interview Tip: Greedy vs A*: h vs g+h.

Code Examples for Greedy Best-First Search

Example

# Greedy Best-First Search
print("draw 6 nodes")
print("name the DS: queue / stack / priority")
print("say if the path is optimal")

Greedy Best-First Search — output: three exam lines. Graph on paper first.

How to Explain Greedy Best-First Search to an Interviewer

Explain Greedy Best-First Search as if you are teaching a junior — definition, then one example.

Uses only h(n). Not always optimal.

What does the example print, and what does that prove?

Greedy Best-First Search — output: three exam lines

What mistake do freshers make with Greedy Best-First Search?

Uses only h(n). Not always optimal.