Prolog programming Write a set of rules that performs an in-order traversal of a
ID: 3777188 • Letter: P
Question
Prolog programming
Write a set of rules that performs an in-order traversal of a binary tree. The binary tree is expressed by the set of nodes, similar to the tree used in the classroom example. node(3, nil, 14). node(14, nil, 15). node(15, nil, 92). node(92, 65, nil). node(65, 35, 89). node(35, nil, nil). node(89, nil, nil). Performing an in-order traversal of a binary search tree yields the node values of the tree in increasing order. A sample run will look like: ?- inOrder(3, X). X = [3, 14, 15, 35, 65, 89, 92]. Use the same database of nodes, but write a set of rules that print the node values represented by the search tree in descending order. A sample run can look like: ?- inOrderDesc(3, X). X = [92, 89, 65, 35, 15, 14, 3] .Explanation / Answer
3)
theleft->left node
theright->right node
theRoot->root node
4.for inorder_desc we will have the following. We will just change the order of operations for the same.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.