Question: [ 1 . 4 ] [ 5 marks ] The numpy module contains functions to generate random permutations. Given a non - negative integer n
marks The numpy module contains functions to generate random permutations. Given a nonnegative integer n every permutation of n
numbers can be turned into a matching by taking the first n half of the permutation entries ie the first n numbers and connecting each of them to the corresponding entry in the second half ie the last n numbers Use this method to write a function randommatching that takes n and returns a randomly selected matching of n numbers in the form of a list of n tuples, where each tuple contains two integers.
Note: Ensure that the tuples are returned such that the first integer is less than the second integer.
To demonstrate that your code works, draw the arc diagrams for five randomly chosen matchings of
numbers.
marks The moduletimeit imported above allows you to compute the time a function call takes. Verify your answer about the time complexity from Exercise by computing the run time for randomly chosen arc diagrams of suitable sizes and producing an appropriate plot of the average run times against the lengths of the matchings.
Interpret your results.
marks Now that you understand the code well, here is an alternative function written by some crazy Python programmer who loves to write oneline lambda functions.
countcrossnest lambda arcs: tuplemapsumzipFalseFalsei
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
