Question: PYTHON 3 WITH COMMENTED EXPLANATION Problem Write a function that recursively computes how many unique words we can make of length k, if we are

PYTHON 3

WITH COMMENTED EXPLANATIONPYTHON 3 WITH COMMENTED EXPLANATION Problem Write a function that recursively computes

Problem

Write a function that recursively computes how many unique words we can make of length k, if we are to choose from a set of N letters.

In mathematics, this is known as Permutations: P(N, k) = N!/(N - k)!

For example, if we had 3 letters "a", "b", and "c", and we are asked how many two letter words we can make with them, the answer is 6:

"ab"

"ac"

"ba"

"bc"

"ca"

"cb"

Intuitively, we have three letters to choose from for the first position in our word, and 2 letters to choose from for the 2nd position in our word, so in total, there are 6 possibilities.

Mathematically, P(3, 2) = 3!/1!, which is 6.

Your task is to compute this recursively, without using factorial. It would help you greatly if you write the recursive mathematical relationship before you try to write the code. Think about how P(N, k) can be written in terms of N-1.

Instructions from your feacher 1- def P(n, k): Problem Write a function that recursively computes how many unique words we can make of length k, if we are to choose from a set of N letters In mathematics, this is known as Permutations: P(N, k)N!KN - k)! For example, if we had 3 letters "a", "b", and "c", and we are asked how many two letter words we can make with them, the answer is 6: ac "ba "bc" ca "cb" Intuitively, we have three letters to choose from for the first position in our word, and 2 letters to choose from for the 2nd position in our word, so in total, there are 6 possibilities. Python 3.6.1 (default, Dec 2015, 13:05:11) IGCC 4.8.2] on linux Mathematically, P(3, 2) 31, which is 6 Your task is to compute this recursively, without using factorial. It would help you greatly if you write the recursive mathematical relationship before you try to write the code. Think about how P(N, k) can be written in terms of N

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!