subject
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]

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:20
Cengagenowv2 is a comprehensive online learning tool. using cengagenowv2, you may access all of the following except: 2. each time you log in, cengagenowv2 automatically performs a system check and informs you if your computer does not meet the cengagenowv2 system requirements. 3. which tab/page allows you to easily track your assignment scores, number of submissions, time spent, as well as the ability view assign
Answers: 3
question
Computers and Technology, 22.06.2019 19:20
Write a program that prompts the user to input a string. the program then uses the function substr to remove all the vowels from the string. for example, if str = "there", then after removing all the vowels, str = "thr". after removing all the vowels, output the string. your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.
Answers: 2
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
You know the right answer?
Lists Write the following predicates on lists.

• equal/2 meaning that both given lists a...
Questions
question
Mathematics, 23.07.2019 02:00
question
Social Studies, 23.07.2019 02:00
question
History, 23.07.2019 02:00
Questions on the website: 13722363