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 leaf

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
