Forward and Backward Chaining — AI Technical Interview Questions & Answers
Forward and Backward Chaining
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.
Technical Interview Tip: One situation for each chaining style.
Code Examples for Forward and Backward Chaining
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.
How to Explain Forward and Backward Chaining to an Interviewer
Explain Forward and Backward Chaining as if you are teaching a junior — definition, then one example.
Forward : data-driven. Backward : goal-driven.
What does the example print, and what does that prove?
Forward and Backward Chaining — output: forward derived {'dirt', 'suck'}
What mistake do freshers make with Forward and Backward Chaining?
Only the buzzword, no example