Question: prolog binary tree I am working on this attached file. Just the prolog problem, I have this so far leftchild(do,he). leftchild(at,do). leftchild(to,we). leftchild(in,to). rightchild(go,do). rightchild(be,at).

prolog binary tree

I am working on this attached file. Just the prolog problem, I have this so far leftchild(do,he). leftchild(at,do). leftchild(to,we). leftchild(in,to). rightchild(go,do). rightchild(be,at). rightchild(we,he). rightchild(me,in). depth(he,0).

% rules

justabove(X,Y):- rightchild(Y,X) ; leftchild(Y,X).

above(X,Y):- justabove(X,Y).

above(X,Y):- justabove(Z,Y) , above(X,Z).

root(X):- depth(X,0). equaldepth(X,Y):- depth(X,D) == depth(Y,D).

depth(N,0):- root(N).

depth(N,L):- above(P,N), depth(P,LP), L is LP+1.

However the rules are not working, above and just above work fine, the others do not, and OI have no clue on how to determine if leafprolog binary tree I am working on this attached file. Just theprolog problem, I have this so far leftchild(do,he). leftchild(at,do). leftchild(to,we). leftchild(in,to). rightchild(go,do).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!