Question
The above image shows a binary tree. Write a series of predicates parentOf/2 that records if a node is a parent of another (parentOf is
The above image shows a binary tree. Write a series of predicates parentOf/2 that records if a node is a parent of another (parentOf is shown as an outgoing arrow where the parent node is the source and the child node is the destination). The first two predicates are:
parentOf(a,h) parentOf(a,b) parentOf(h,b)
Ensure you use lowercase letters to represent the nodes. There should be 8 parentOf lines in your program.Now write a predicate ancestorOf/2 using recursion which checks if the first parameter is an ancestor of the second. You must use recursion for this predicate. Example output is:
ancestorOf(a,d). true. ancestorOf(h,i). true. ancestorOf(h,e). true. ancestorOf(g,f). false.
Note: you must use recursion to write the ancestorOf predicate.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started