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

AI · Theory

Forward and Backward Chaining

← All stacks

Theory

40/215

Forward and Backward Chaining

Forward chaining is data-driven: new facts fire rules, more facts appear, until the query is known. Backward chaining is goal-driven: start from what you want, ask what would prove it, recurse. Expert systems use both.

Medical: lots of symptoms arriving → forward. “Does the patient have measles?” → backward. Horn clauses keep both tractable.

Forward and Backward Chaining — output — forward derived {'dirt', 'suck'}. Backward starts from the goal suck.

Exam tip

One situation for each chaining style.

Example

# Forward vs backward
facts = {"dirt"}
rules = [("dirt", "suck")]
# forward: facts fire rules
derived = set(facts)
for cond, act in rules:
    if cond in derived:
        derived.add(act)
print("forward derived", derived)
# backward: start from goal suck
print("backward asks: what proves suck? → dirt, which is known")

Forward and Backward Chaining — output: forward derived {'dirt', 'suck'}. Backward starts from the goal suck.

Short notes

  • DefForward : data-driven.
  • RuleBackward : goal-driven.

Questions

1

Explain Forward and Backward Chaining 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 Forward and Backward Chaining?

Previous← Resolution in FOLNextDifference between Backward Chaining and Forward Chaining →
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.