Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

In lisp programming

Consider the two versions of the function computing the combinations. Add a global variable counter and increment it by one at the top of both functions. This will count the number of function calls required to complete the calculations in each case. Try the two versions of the function for a few pairs of numbers n and m and print out the value of the counter after each of them. Don't forget to reset the counter to 0 before each call. Comment on the observed difference between the numbers of function calls.

Transcribed Image Text:Combinations C(n, m) = n!/(m! (n-m)!) C(n, m) = C(n-1, m) + C(n-1, m-1) (defun comb (nm) (cond ((= nm) 1) ((= m 0) 1) ((= m 1) n) (t (+ (comb (- n 1) m) (comb (- n 1) (- m 1)))))) (comb 3 2); 3 (comb 5 2); 10 Improved version with DP: (defun el10 (nm) (+ (* n 10) m)) ; 10*n+m (setq C (make-vector 100 mil)) (defun comb1 (nm) (let ((res 0)) (if (setq res (elt C (el10 n m))) res (setq res (cond ((= nm) 1) ((= m 0) 0) ((= m 1) n) (t (+ (comb1 (- n 1) m) (- n 1) (comb1 (- m 1)))))) (aset C (el10 nm) res)))) (comb1 7 3) ; 35 (comb1 10 5); 252
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education