Question: use Prolog programming Design two predicates path/2 and cycle/1 that determine structures within a graph whose directed edges are encoded with given instances of edge/2.
use Prolog programming
Design two predicates path/2 and cycle/1 that determine structures within a graph whose directed edges are encoded with given instances of edge/2. For example, path(x,y) should evaluate to true if a path exists from vertex x to vertex y, and false otherwise. And cycle(x) should evaluate to true if a cycle exists which includes vertex x.
Note: All edges are directional. Note: Your solution should avoid infinite recursion.
Note: The Knowledge Base of edges below is for example only.
You are just responsible for the definitions of path/2 and cycle/1. The Knowledge Base edges used for grading will be different.
Example:-
Knowledge Base
edge(a,b).
edge(b,c).
edge(c,d).
edge(d,a).
edge(d,e).
edge(b,a).
?- path(b,d)
true.
?- path(e,b).
false.
?- path(c,a).
true.
?- cycle(b).
true.
?- cycle(e).
false.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
