# Binary trees

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.

1 Like

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.

Useful Prolog references

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.