Can anybody help me to solve these prolog exercises:
A) Write a prolog program that given a binary tree whose nodes contain positive integers, checks whether the tree is odd, i.e. it contains only odd numbers. To check whether the number is odd, use the predicate odd(X)
B) writer a prolog program that given a binary tree whose nodes contain positive integers returns a binary tree that is like the input tree but for the subtrees whose root nodes are eve numbers. Such subtrees should be replaced by leaf nodes containing the number 13
On page 72 of the book I recommended (page 113 of the PDF) you will find the section “3.4 Binary Trees”. It is a very good starting point.
Otherwise it almost looks like you are just posting your homework assignment and expecting someone to do it for you.
Which book? Please I need the PDF.
I guess “The Art of Prolog” (second edition) by Sterling and Shapiro. The PDF could be downloaded from the book’s website. I hope this is still the case.
It is also here if you need it.
See: “The Art of Prolog” By Leon S. Sterlingand and Ehud Y. Shapiro (site ) (pdf )
Thanks. I have exam of Prolog and there will be questions about lists and binary tree and guessing the output of the given program. Is this book enough for me?
That is hard to say. I don’t know what you know and I don’t know what will be on the test.
That is a question for the instructor of the class.