Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER WITH C++ CODE QUESTION 6 Short description: A. Write a function which determines if a given array of n integers is a permutation

image text in transcribed

image text in transcribed

PLEASE ANSWER WITH C++ CODE

QUESTION 6 Short description: A. Write a function which determines if a given array of n integers is a permutation of fe..n-1) B. Write a function which takes a permutation of n integers and constructs its nverse Background: recall that a permutation of a set of integers is just an ordered listing of the elements. For example, consider the set S={0, 1, 2). example permutations of S These are not permutations of S Suppose an array of n integers is indeed a permutation of (0n-1. We can view 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: Examples of permutations of (e,1,2} and their inverses as array diagrams: Permutation Inverse val val idx val val idx idx val val idx Finally, your tasks: A. write a Cfunction is perm which determines if a given array of integers is a permutation of fe..n-1}. B. Write a function which takes a permutation as an array of n integers and constructs its inverse (also as an array) Your function will allocate storage for the inverse array and returns it as an integer pointer. If the array it receives is not a permutation of (e..n-1), it returns nullptr instead Templates given below. bool is_perm(int al], int n) t int perm2inverse(int a[], int n)f if(lis perm(a, n // to get you started... return nullptr; // otherwise, a[] is a permutation of e.n-1; allocate and populate its // inverse array (and return it)

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

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions

Question

What is the difference between fundamental risk and price risk?

Answered: 1 week ago