Question: 2. A binary tree is either empty or it is composed of a root element and two children, which are binary trees themselves. In
2. A binary tree is either empty or it is composed of a root element and two children, which are binary trees themselves. In Prolog we can represent an empty tree by the constant 'nil' and represent a non-empty tree by a list [X,L,R], where X denotes the value in the root node and Land R denote the left subtree and right subtree, respectively, e.g., [a,[b,[d,nil,nil],[e,nil,nil]],[c,nil,[f,[g,nil,nil],nil]]] (2a) Draw the binary tree corresponding to the list above. (2b) Write a Prolog program istree(L) that determines if L is a binary tree.
Step by Step Solution
3.41 Rating (145 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
