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

AI · Theory

Hill Climbing

← All stacks

Theory

23/215

Hill Climbing

Hill climbing looks only at neighbours and steps to a better one. Like climbing in fog: you go up, then you stop at a peak that may not be the highest mountain. Local maxima, plateaus, ridges trap it. Variants: random restart, simulated annealing.

8-queens or a tiny landscape sketch is enough. Don’t claim hill climbing always finds global best. It is greedy local search, not A*.

Hill Climbing — output — stopped at index 1 height 5. Global peak is 9. Local maximum trap.

Exam tip

Local max trap + one fix.

Example

# Hill climb — may miss global peak
height = [2, 5, 4, 9, 8]
i = 0
while i + 1 < len(height) and height[i + 1] > height[i]:
    i += 1
print("stopped at index", i, "height", height[i])

Hill Climbing — output: stopped at index 1 height 5. Global peak is 9. Local maximum trap.

Short notes

  • DefStep to better neighbour.
  • TrapLocal maximum.
  • Fix : random restart.

Questions

1

Explain Hill Climbing 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 Hill Climbing?

Previous← A* Search AlgorithmNextMeans-Ends Analysis →
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.