Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU . Recursion Definition for Permutation An ordered tupie ... of k out of the objects,

PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU

image text in transcribed

. Recursion Definition for Permutation An ordered tupie ... of k out of the objects, where 0 Sto.....nare different indices, is an ak-permutation of items do......-1. A permutation of n objects is simply referred to as an n-permutation. The list of (3-) permutations of 1,2,3 1(1, 2, 3), (1, 3, 2), and (1, 3, 3) (2, 1, 3). (2,3), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1) (1,3,2). The following are the two-permutations of 1,2,3: (1, 2), (1,3), (2, 1), (2,3), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 1), (3, 2) We used in the preceding a list delimited by Il such as t(1, 2, 3), (1, 3, 2), (2, 1,3), (2, 3, 1), (3, 1, 2), (3, 2, 1) to store all the permutations, and a tuple delimited by() such as (1,2,3) to store items of a permutation, and in computing and combinatorias, generating permutations is a key challenge. Recursion is an easy approach to produce permutations (There are also other algorithms.) The recurrence relation is satisfied by the proposition Ak-permutation of n:. Removing the first element of a k-permutation of n objects yields a distinct (k-l-permutation of the remaining 1-1 objects., (Q0 (k-1) permutation of a k-permutation of a k-permutation of a k- permutation of a k-permutation of a k-permutation of a k-permutation of a k-permut The preceding removal method can be reversed to create a k-permutation from a (k-1)-permutation. For example, the permutations of 1, 2, and 3 can be built as follows: add to the permutations of 2 3. To permutations of 1, add 2 to the end. 3. add 3 to 12 permutations (1,2,3), (1,3,2), (2,1,3), (2,3,1) (3,1,2). (3,2,1)] The recursion is implemented as follows: Construct all k-permutations of the position arguments using 11 det permutation (-a, kone). a: object, object.... items designated as positional arguments ant: k The size of each permutation is an optional input. n is the default number of itens in a Returns are as follows: There is a list of all permutations. The recursion is implemented as follows: [1: define permutation (ea, k. None): Build all (-) permutations of the position arguments. *a: elements specified as positional arguments (object, object.... n) k: integer The size of each permutation is an optional input. The default number of items is n, which is defined in *3. List of returns: n len(a) output - if k is None: list of all k-permutations expressed as ordered tuples of the n objects extend fali).) - p for p in permutation-al:11. ali 1. kk- + elif in range(n): output. kk- + elif in range(n): output. Return to the return output with KO. permutation(1, 2, 3) print(permutation(1, 2, 3)) print(permutation(1, 2, permutation (1, 2, 3, k-2) print(permutation (1, 2, 3, k-2) print(permutation (1, 2, 3, k The for loop is used to implement the recurrence. The for loops for lin range(n) implement the recurrence: output. extend(t(a[i].) - D for p in permutational:i), ali. 1.), kok- 1)]) extend(t(a[i].) - D for p in permutational:i)]) extend(t(a[i].)- D for p in permutational:i). singleton tuple (a[i].) and.ac - 1-permutation of all elements except ail.) in the above code (a[1].) constructs a k-permutation of the components in a by concatenating for each index (See the cample in the previous recurrence connection.). The comma in ([1]) isn't a mistake. There are no commas. (...) does not result in a tuple) a[@] up to and excluding alil produces a tuple of a[@[i] unpacks the tuple so that each of its components is a separate permutation argument. Similarly, starting with a[11], until the last item in an ... for..., *a[i+1:] supplies items as independent inputs, generating a list of permutations and output. extend [...]) appended the list to the output list's end. Exercise When there is just one permutation, namely the empty tuple, one of the base cases of the recusion occurs, and the function returns to. There is another recursion base cate. Explain the condition of the base case and the value of the return

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago