1. Engineering
  2. Computer Science
  3. please any help with this question...

Question: please any help with this question...

Question details

please any help with this question

QUESTION 6 Short description: A. Write a function which determines if a given array of n integers is a permutation of 0..n-1) B. Write a function which takes a permutation of n integers and construct inverse. Background: recall that a permutation of a set of integers is just an orde listing of the elements For example, consider the set S-10, 1, 2}. example permutations of S These are not permutations of Suppose an array of n integers is indeed a permutation of (0.n-1}. We cai such an array as a bijective function f from POSITION-to-ELEMENT-AT-INDEX Since f is a bijection, it also has an inverse which is a function from ELEMENT-to-POSITION-OF-ELEMENT 2 Examples of permutations of e,1,2} and their inverses as array diagrams: Permutation Inverse val 1 val 2 idx 0 1 idx 0 val 2 1 val2 1 idx e 1 val 2 1 val 1 idx eFinally, your tasks: A. Write a C++ function is_perm which determines if a given array of n Wnteeers is a permutation ers rmtnan nction will allocat integers is a permutation of 0..n-1). B. Write a function which takes a permutation as an array of n integers constructs its inverse (also as an array). Your function will allocat storage for the inverse array and returns it as an integer pointer. I array it receives is not a permutation of e..n-1), it returns nullptr instead. Templates given below. bool is_perm(int all, int n) ( int * perm2inverse(int a[], int n) { if (!is_perm(a, n)) // to get you started... return nullptr; otherwise, al] is a permutation of 0. .n-1; allocate and popul // inverse array (and return it

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution