Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 EXPLANATIONimage text in transcribed

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

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

Comment on the influence of the Internet on public opinion.

Answered: 1 week ago