Lists
Write the following predicates on lists.
• equal/2 meaning that both given lists a...
Computers and Technology, 09.07.2021 01:30 bnnn
Lists
Write the following predicates on lists.
• equal/2 meaning that both given lists are equal:
?- equal([3, 5, 2, 1], [3, 5, 2, 1]).
true
?- equal([3, 5, 2, 1], [1, 2, 3, 5]).
false
?- equal(bob, bob).
false
• contains/2 meaning that the list contains an element:
?- contains([3, 5, 2, 1], 2).
true
?- contains([3, 5, 2, 1], 4).
false
• reverse/2 meaning the first list is the reverse of the second.
?- reverse([3, 5, 2, 1], X).
X = [1, 2, 5, 3]
?- reverse (bob, X).
false
• sum/2 meaning the second member is the sum of elements in the first.
?- sum([3, 5, 2, 1], S).
S = 11
?- sum([], S).
S = 0
Binary trees
We will create a data structure that represents binary trees. Each node will be represented as bt(L, E, R), where L is the left subtree, R is the right subtree, and E is the element at the given note. An empty tree is denoted as the atom nil.
• Write the predicate binary_treee/1, that returns true if the argument is a binary tree:
?- binary_treee(nil)
true
?- binary_tree(bt(nil, 3, nil))
true
?- binary_tree(bt(bt(nil, 4, bt(nil, 5, nil)), 3, nil))
true
?- binary_tree(bt(nil, 3))
false
• Write the predicate in_order/2, that returns the list of arguments ordered by the in-order traversal (left-to-right: https://www. geeksforgeeks. org/tree-traversals-inorder-preorde r-and-postorder/ ):
?- in_order(bt(bt(nil, 4, bt(nil, 5, nil)), 3, nil), L)
L = [4, 5, 3]
Answers: 2
Computers and Technology, 22.06.2019 08:40
What are the three parts to physical security standards for various types of army equipment and the risk level
Answers: 2
Computers and Technology, 22.06.2019 14:30
Hi plz 11 ! when planning a table, what step comes first: "define the column headers" or "calculate the number of columns/rows"? a. calculate the number of columns/rows b. define the column headers
Answers: 1
Computers and Technology, 23.06.2019 00:30
If joey was single and his taxable income was $9,500, how much would he pay in taxes each year?
Answers: 1
Computers and Technology, 23.06.2019 11:00
Sports and entertainment class, your goal is to increase attendance and make a profit for a game by getting your team on a winning track with total salaries less than $3,000,000
Answers: 3
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40
Mathematics, 23.04.2021 17:40