Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help for part B www.cs.uni.edu/~fienup/cs1520s19/labs/lab6.zip Word Pro- lab6.lwp 1/2 to calculate the number of combinations of n choose k, i.c., the number of ways to

Help for part B

www.cs.uni.edu/~fienup/cs1520s19/labs/lab6.zip

image text in transcribed

Word Pro- lab6.lwp 1/2 to calculate the number of combinations of "n choose k," i.c., the number of ways to choose k objects from n objects. For example, when calculating the number of unique 5-card hands from a standard 52-card deck (c.g., C(52, 5)) we need to calculate 52!5! 47! 2,598,960. Implement the function C(n, k) using formula (2) above and your recursive factorial function. Completed your factorial and binomial coefficient functions, raise your hand and demonstrate your code. Part B: One problem with using formula (2) in most languages is that n! grows very fast and overflows the integer representation before you can do the division to bring the value hack to a value that can he represented. (NOTE: Python does not suffer from this problem, but lets pretend that it does.) For example, when calculating C(52, 5) we need to calculate 52!/5! 471. However, the value of 52! = 80.658, I 75. I 70.943.878.571 ,660,636.856,403,766.975,289,505.440.883 ,277.824.000.000.000.000 is much, much bigger than can fit into a 64-bit integer representation. Fortunately, another way to view C(52, 5) is recursively by splitting the problem into two s maller problems by focusing on: the hands containing a specific card, say the ace of clubs, and . the hands that do not contain the ace of clubs. For those hands that do contain the ace of clubs, we need to choose 4 more cards from the remaining 51 cards, i.e.. C(51, 4). For those hands that do not contain the ace of clubs, we need to choose 5 cards from the remaining 51 cards, i.., (151, 5). Therefore. (152, 5)-(151, 4) + C151, 5). In general, (NOTE: When implementing your recursive code, be sure to use DC for the recursive calls) Cn, C-1, k-1)+C(-1, k) for lsks1), and fork-0ork-n Implement the recursive function DC (n, k) for "divide-and-conquer". Notice the difference in run-time between calculating the binomial coefficient using C(24, 12) vs. DC(24, 12), C(26, 13) vs. DC(26, 13). and C(28, 14) vs. DC(28, 14). binomial coefficient function using cquation (3). Call your Completed your binomial cocfficient function, DC, raise your hand and demonstrate your code. 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 DCS, 3) DC4, 2) DC(4, 3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Describe your ideal working day.

Answered: 1 week ago