Question: Need help for part C Word Pro -lab6.lwp 2/2 Part C: Much of the slowness of your divide-and-conquer binomial coefficient function, DC(n, k), is due
Need help for part C


Word Pro -lab6.lwp 2/2 Part C: Much of the slowness of your "divide-and-conquer" binomial coefficient function, DC(n, k), is due to redundant calculations performed due to the recursive calls. For example, the recursive calls associated with DC(5, 3) = 10 would be: Lab 6-1 Data Structures (CS 1520) Lab 6 Name: DC(5, 3) DC4. 2) DC14. 3) DC(3, 1) DC(2, 0) DC(2, I) DC(2, I) DC(2,2 DC2,) DC(2, 2) Pascal's triangle (named for the 17vr Fench mathematician Blaise Pascal, and for whom the programming language Pascal was also named) is a "dynamic programming" approach to calculating binomial coefficients. Row # 10 10 Recall that dynamic programming solutions eliminate the redundancy of recursive divide-and-conquer algorithms by calculating the solutions to smaller problems first, storing their answers, and looking up their answers if later needed instead of recalculating it. Abstractly, Pascal's triangle relates to the binomial cocfficient as in: Row # c(0,0) C(2,0) C(2,1 C2,2) C(3,0 C3,1) C(3,2) C(3,3) C(4,0) C(4,1) C(4,2) C(4.3) C(4.4) C(5,0) C(5,1) C(5,2) C53) C54) C(5,5) C(n-1k-1) C(p-1,k) n-1 Word Pro - lab6.lwp 2/2 DC13, 1) DO3, 2) DC(3, 2) DC3, 3) ) DC(2.2 DC(2. DCI2,2) DC(1,0) DC( 1,1 ) DC 1,0) DE( 1,1 ) DC 1,0) DC( 1,1 ) Pascal's triangle (named for the 17-century French mathematician Blaise Pascal, and for whom the programming language Pascal was also named) is a "dynamic programming" approach to calculating binomial coefficients. Row # 10 10 Revall that dynamic programming solutions eliminate the redundancy of recursive divide-and-conquer algorithms by calculating the solutions to smaller problems first, storing their answers, and looking up their answers if later needed i triangle relates to the binomial coefficient as in: instead of recalculating it. Abstractly, Pascal's Row # C(0,0) C(,0 CI,I) C(2.0) C2,1) C(2,2) C(3,0 C3,1) C3,2) C33) C(4,0) C4,1) C4,2) C(4,3) C(4,4) C(5,0 C(5,1) C(3,2) C5,3) C5.4) C(5,3) C(n-l,k-1) C(p-1,k) C(n,0) C(n C(n,2) C(n,k) Cn, n-) C(n,n) For Part C, your job is to implement the "dynamic programming" binomial coefficient function using a Python list of lists to store Pascal's triangle and loops (no recursion needed). Call your function DP (n, k) for "dynamic programming". Hints for Part C: Review the dynamic programming fibonacci example from Lecture 9. File lab6/fibonacci py contains the recursive divide-and-conquer, and two dynamic programming versions of fibonacci. The first dynamic programming version, fib_DP, stores the answers to all of the smaller problems. The second dynamic programming version, fib_DP2, reduces the amount of memory used by only storing the answers for the previous two smaller problems. Notice the difference in run-time between calculating the binomial coefficient using DC(24, 12) vs. DP(24, 12) DC(26, 13) vs. DP(26, 13), and DC(28, 14) vs. DP(28, 14). Completed your binomial coefficient function, DP, raise your hand and demonstrate your code. Word Pro -lab6.lwp 2/2 Part C: Much of the slowness of your "divide-and-conquer" binomial coefficient function, DC(n, k), is due to redundant calculations performed due to the recursive calls. For example, the recursive calls associated with DC(5, 3) = 10 would be: Lab 6-1 Data Structures (CS 1520) Lab 6 Name: DC(5, 3) DC4. 2) DC14. 3) DC(3, 1) DC(2, 0) DC(2, I) DC(2, I) DC(2,2 DC2,) DC(2, 2) Pascal's triangle (named for the 17vr Fench mathematician Blaise Pascal, and for whom the programming language Pascal was also named) is a "dynamic programming" approach to calculating binomial coefficients. Row # 10 10 Recall that dynamic programming solutions eliminate the redundancy of recursive divide-and-conquer algorithms by calculating the solutions to smaller problems first, storing their answers, and looking up their answers if later needed instead of recalculating it. Abstractly, Pascal's triangle relates to the binomial cocfficient as in: Row # c(0,0) C(2,0) C(2,1 C2,2) C(3,0 C3,1) C(3,2) C(3,3) C(4,0) C(4,1) C(4,2) C(4.3) C(4.4) C(5,0) C(5,1) C(5,2) C53) C54) C(5,5) C(n-1k-1) C(p-1,k) n-1 Word Pro - lab6.lwp 2/2 DC13, 1) DO3, 2) DC(3, 2) DC3, 3) ) DC(2.2 DC(2. DCI2,2) DC(1,0) DC( 1,1 ) DC 1,0) DE( 1,1 ) DC 1,0) DC( 1,1 ) Pascal's triangle (named for the 17-century French mathematician Blaise Pascal, and for whom the programming language Pascal was also named) is a "dynamic programming" approach to calculating binomial coefficients. Row # 10 10 Revall that dynamic programming solutions eliminate the redundancy of recursive divide-and-conquer algorithms by calculating the solutions to smaller problems first, storing their answers, and looking up their answers if later needed i triangle relates to the binomial coefficient as in: instead of recalculating it. Abstractly, Pascal's Row # C(0,0) C(,0 CI,I) C(2.0) C2,1) C(2,2) C(3,0 C3,1) C3,2) C33) C(4,0) C4,1) C4,2) C(4,3) C(4,4) C(5,0 C(5,1) C(3,2) C5,3) C5.4) C(5,3) C(n-l,k-1) C(p-1,k) C(n,0) C(n C(n,2) C(n,k) Cn, n-) C(n,n) For Part C, your job is to implement the "dynamic programming" binomial coefficient function using a Python list of lists to store Pascal's triangle and loops (no recursion needed). Call your function DP (n, k) for "dynamic programming". Hints for Part C: Review the dynamic programming fibonacci example from Lecture 9. File lab6/fibonacci py contains the recursive divide-and-conquer, and two dynamic programming versions of fibonacci. The first dynamic programming version, fib_DP, stores the answers to all of the smaller problems. The second dynamic programming version, fib_DP2, reduces the amount of memory used by only storing the answers for the previous two smaller problems. Notice the difference in run-time between calculating the binomial coefficient using DC(24, 12) vs. DP(24, 12) DC(26, 13) vs. DP(26, 13), and DC(28, 14) vs. DP(28, 14). Completed your binomial coefficient function, DP, raise your hand and demonstrate your code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
