PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

AI · Theory

Uniform Cost Search

← All stacks

Theory

75/215

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.

Diagram
start
    ├── BFS  queue
    ├── DFS  stack
    └── A*   g+h
    │
    ▼
   goal
Exam tip

UCS vs BFS when costs differ.

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.

Short notes

  • DefPriority on g(n). Optimal if costs ≥ 0.

Questions

1

Explain Uniform Cost Search as if you are teaching a junior — definition, then one example.

2

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

3

What mistake do freshers make with Uniform Cost Search?

Previous← Truth Maintenance SystemNextfor Kids →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.