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, 21.06.2019 22:00, rosetoheart2
What do the principles of notice, choice, onward transfer, and access closely apply to? a. privacyb. identificationc. retentiond. classification
Answers: 1
Computers and Technology, 22.06.2019 16:30, nxusasmangaliso1191
The most common battery cable terminal is a that provides a large surface contact area with the ability to tighten the terminal onto the battery post using a nut and bolt.
Answers: 2
Computers and Technology, 24.06.2019 19:30, hermine40
Which phrase is the best definition of a pivottable a a table containing data that is organized horizontally b a table used to calculate financial pivot values c a tool used to summarize data d a table containing specific formatting
Answers: 1
Mathematics, 04.01.2020 02:31
Mathematics, 04.01.2020 02:31
Mathematics, 04.01.2020 02:31
Mathematics, 04.01.2020 02:31