Questions: Logic Programming Basics (Prolog)

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A Prolog programmer writes the rule: ancestor(X, Z) :- ancestor(X, Y), parent(Y, Z). When queried, the program immediately enters an infinite loop. What is the most likely cause?

AThe rule is logically incorrect — ancestor cannot be defined in terms of itself
BProlog searches depth-first and always tries to resolve the recursive subgoal first, looping before reaching base cases
CUnification fails because X and Z are the same variable
DProlog requires all facts to be listed before rules, and the parent facts must be missing
Question 2 Multiple Choice

What happens in Prolog when you query a predicate that has been misspelled (e.g., grandparent vs grandparnet)?

AA compile-time error is raised identifying the unknown predicate
BA runtime type error is thrown when the predicate is first evaluated
CThe query silently fails — Prolog returns 'false' with no error message
DProlog prompts the user to define the missing predicate interactively
Question 3 True / False

In Prolog, when a sub-goal fails during query resolution, the interpreter backtracks by undoing the most recent variable binding and attempting alternative clause matches.

TTrue
FFalse
Question 4 True / False

The order in which clauses appear in a Prolog program does not affect whether a query will succeed or fail — mainly the logical content of the clauses matters.

TTrue
FFalse
Question 5 Short Answer

Explain the difference between how an imperative program and a Prolog program approach computing the grandparent relationship, and what this reveals about the logic programming paradigm.

Think about your answer, then reveal below.