[SOLVED] CS代考 CPS 721 Quiz 6

30 $

File Name: CS代考_CPS_721_Quiz_6.zip
File Size: 216.66 KB

SKU: 7563964099 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


CPS 721 Quiz 6
2021 Practice Version
(not shared) Switch account
Company employee hierarchy

Copyright By PowCoder代写加微信 assignmentchef

Let the predicate direct_boss(X, Y) denote that person X is the boss of person Y. Let the predicate works_under(X, Y) denote that person X has a lower-level position in the company than person Y. The base case is given below:
works_under(X, Y):- direct_boss(Y, X).
Which of the following is the correct recursive rule for the predicate ‘works_under(X, Y)’ ?
works_under(X, Y):- works_under(X, Z), direct_boss(Y, Z). works_under(X, Y):- direct_boss(Y, Z), works_under(X, Z). works_under(X, Y):- direct_boss(Y, Z), direct_boss(Z, X). works_under(X, Y):- not works_under(Y, X). works_under(X, Y):- works_under(X, Z), works_under(Z, Y).
Writing a chain of bosses
The predicate write_boss_chain(X) takes as input the name of a person who works in the company, and prints their name and the names of all the people they work under, starting from the most senior position. For example, if Anne works for Bob, and Bob works for Carol, the query ?- write_boss_chain(anne) would print the following:
carol bob anne
The base case for this predicate occurs when X does not work under anyone, and is given below: write_boss_chain(X):- not works_under(X, Y), write(X), nl.

Which of the following is the correct recursive rule for the predicate ‘write_boss_chain(X)’ ?
write_boss_chain(X):- works_under(Y, X), write(X), nl, write_boss_chain(Y). write_boss_chain(X):- works_under(Y, X), write_boss_chain(Y), write(X), nl. write_boss_chain(X):- works_under(X, Y), write_boss_chain(Y), write(X), nl. write_boss_chain(X):- works_under(X, Y), write(X), nl, write_boss_chain(Y).
Common elements between two lists
The predicate common_elements(L1, L2, Common) succeeds when Common is a list of all the elements which appear in both lists L1 and L2.
For example, the query ?- common_elements([a,b,c,d], [b,c,e], [b,c]) will succeed, but the query ?- common_elements([a,b,c], [b,c,d], [b]) will fail.
Note that the query ?- common_elements([a,b], [x,y], Result) will succeed with Result = [ ], as there are no elements which appear in both lists.
The base case for this predicate is given below: common_elements([ ], L2, [ ]).

Select the two recursive cases from the options below which constitute a correct implementation of the predicate common_elements(L1, L2, Result). You may use the built-in predicate member(X, L), which succeeds when the element X is present in the list L. (Select exactly 2, the correct answers will be adjacent)
common_elements([H|T1], [H|T2], [H|Result]):- member(H, T1), member(H, T2), common_elements(T1, T2, Result).
common_elements([X1|T1], [X2|T2], Result):- common_elements(T1, T2, Result).
common_elements([H|T], L2, Result):- member(H, L2), common_elements(T, L2, [H|Result]).
common_elements([H|T], L2, L2):- common_elements(H, L2, [ ]), member(T, L2).
common_elements([H|T], L2, [H|Result]):- member(H, L2), common_elements(T, L2, Result).
common_elements([H|T], L2, Result):- not member(H, L2), common_elements(T, L2, Result).
Difference in lengths of tree branches
The predicate longer_than_LMB(Tree1, Tree2, N) succeeds when the leftmost branch of the binary tree Tree1 contains N more nodes than the leftmost branch of the binary tree Tree2.
For example, the query ?- longer_than_LMB(tree(a, tree(b, tree(c, void, void), void), void), tree(x, void, void), 2) will succeed, but the query ?- longer_than_LMB(tree(a, tree(b, tree(c, void, void), void), void), tree(x, tree(y, void, void), void), 2) will fail.
Note that the query ?- longer_than_LMB(tree(a, void, void), tree(x, tree(y, void, void), void), N) will fail, since the leftmost branch of the second tree contains two elements, while the leftmost branch of the first tree only contains 1. The query ?- longer_than_LMB(tree(a, void, void), tree(x, void, void), N) will succeed with N = 0, since the leftmost branches have the same length.
The base case for this predicate is given below: longer_than_LMB(void, void, 0).

Select the two recursive cases from the options below which constitute a correct implementation of the predicate longer_than_LMB(Tree1, Tree2, Result). (Select exactly 2, the correct answers will be adjacent)
longer_than_LMB(tree(X, L, R), void, Result):- longer_than_LMB(L, void, N), Result is N+1.
longer_than_LMB(tree(X1, L1, R1), tree(X2, L2, R2), Result):- longer_than_LMB(L1, L2, Result).
longer_than_LMB(Tree1, Tree2, Result):- longer_than_LMB(Tree2, Tree1, N), Result is 0-N.
longer_than_LMB(tree(X, L, R), Tree2, Result):- longer_than_LMB(L, Tree2, N), Result is N+1.
longer_than_LMB(tree(X, L, R), tree(X, void, void), Result):- longer_than_LMB(L, void, Result).
longer_than_LMB(tree(X, L1, R1), tree(X, L2, R2), Result):- longer_than_LMB(tree(X, L1, R1), L2, N), Result is N-1.
Clear form
This form was created inside of. Report Abuse Forms

程序代写 CS代考加微信: assignmentchef QQ: 1823890830 Email: [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS代考 CPS 721 Quiz 6
30 $