Uniform Cost Search — AI Technical Interview Questions & Answers
Uniform Cost Search
Uniform Cost Search
- UCS expands the cheapest path-so-far first (priority queue on g). Optimal if costs ≥ 0. Like Dijkstra. No heuristic. If all costs are 1, UCS behaves like BFS.
- Uniform Cost Search — output: three exam lines. Graph on paper first.
start
├── BFS queue
├── DFS stack
└── A* g+h
│
▼
goalTechnical Interview Tip: UCS vs BFS when costs differ.
Code Examples for Uniform Cost Search
Example
# Uniform Cost Search
print("draw 6 nodes")
print("name the DS: queue / stack / priority")
print("say if the path is optimal")
Uniform Cost Search — output: three exam lines. Graph on paper first.
How to Explain Uniform Cost Search to an Interviewer
Explain Uniform Cost Search as if you are teaching a junior — definition, then one example.
Priority on g(n). Optimal if costs ≥ 0.
What does the example print, and what does that prove?
Uniform Cost Search — output: three exam lines
What mistake do freshers make with Uniform Cost Search?
Only the buzzword, no example