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 EXPLANATION
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 NStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started