This is For Programming Language Concept. Please answer accurately 1) Suppose th
ID: 3905908 • Letter: T
Question
This is For Programming Language Concept. Please answer accurately
1) Suppose that the equal_lists function (page 49 of Sebesta) is called with the lists((A B ) C (D E))and((A B ) C (D E))as the arguments. How many calls ofequal_lists will be performed all together, including the original call and all recur- sive calls?
The following is an example of a Lisp program: Example functionines a Lisp predicate : The following code defines a Lisp predicate function i that takes two lists as arguments and returns True i if the two lists are equal, and NIL (false) otherwise DEFUN equal_lists (lisl lis2) COND (ATOM 1is1) (EQ lisl lis2)) (ATOM lis2) NIL) (equal_lists (CAR lisl) (CAR lis2)) (equal_lists (CDR lis1) (CDR lis2))) (T NIL)Explanation / Answer
a)For two equal list having 1 elements perform 3 calls
equal_list((A), (A) ) =>equal_list(A, A) +equal_list(() , ())
=> equal_list(B, B) +equal_list(() () )
b) for 2 equal list having 2 elements will perform 5 calls
equal_list ((A, B), (A, B )) =>equal_list(A, A) +equal_list((B), (B) )
THEREFORE:
equal_list( ((A, B) , C, (D, E)) , ((A, B), C, (D, E) ) ) [1 call] =>equal_list ((A, B) , (A, B)) [5 calls] +equal_list((C, (D, E) ), (C, (D, E) )) [1 call] =>equal_list(C, C) [1 calls] +equal_list(((D, E) ) , ((D, E)) )[1 call] =>equal_list ((D, E), (D, E)) [5 calls] +equal_list ((), () ) [1 call]
total=15 calls
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.