Computers and Technology
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]

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 15:00, victordhernandez01
Jake really works well with numbers and is skilled with computers but doesn't work well with others. which of the jobs discussed in this unit might be best for jake? why?
Answers: 3
image
Computers and Technology, 24.06.2019 08:10, anthonysutton82
Where are american poets found in the dewey decimal system
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, elviaortiz402373
Which of the following is not a “fatal four” event?
Answers: 2
image
Computers and Technology, 25.06.2019 16:30, alyssamaize
Unit 3 computer programming study guide refer to code. org for puzzles refer to brainpop; under functions, computer programming, variables part one: define. algorithm- a list of steps to finish a task binary- a way to represent information using 1 and 0 bug- part of a program that does not work correctly code- 1 or more commands to be carried out by a computer function debug sequencing loop repeat conditionals variable part two: answer accordingly. a programmer is to a computer as a teacher is to: a good algorithm must be: imagine writing a program that instructs a bird how to take off, fly and land. what function is likely to be looped? which of the following is most similar to a function? what do variables and functions have in common? 8. the main cause of bugs in coding is: 9. list the following in order from the simplest to most complex: function program step 10. if a program has gone through many iterations, what must be true? 11. what is a benefit of drying up code? a. it makes it less likely to break b. it makes the code compatible with different software c. it saves programmers time d. it makes it less vulnerable to hackers 12. a statement in a function can be most closely compared to: a. a step in a recipe b. a line of a poem c. a brushstroke in a painting d. a piece of assembled furniture t/f: are the solutions provided true? t/f: t/f: t/f:
Answers: 1
Do you know the correct answer?
Lists Write the following predicates on lists.

• equal/2 meaning that both given lists a...

Questions in other subjects: