Answered step by step
Verified Expert Solution
Question
1 Approved Answer
It is a previous year assignment and according to professor will be similiar to the final in 12 hours. So need urgent help Part 2
It is a previous year assignment and according to professor will be similiar to the final in 12 hours. So need urgent help
Part 2 The questions in this part of the assignment will be graded. Question 1: Playing with permutations (100 points) Before starting this question, we strongly recommend that you complete all thetwo warm- up exercises if you have not already done so. These warm-up questions will be the best way to start the assignment. A permutation of length n is a list of the numbers 1 through n but in some rearranged order. So "12 3' is a permutation of length 3, and so is 2 13, but 5 364 12' is a permutation of length 6. Notice that every number between 1 and n appears in the permutation. Permutations are employed in different fields and they have practical real-life use. For this assignment we will play a bit with permutations, but to do that we will need the following methods (Please create the following methods in a Class called Permutations). la. Random Permutation (10 points) The first method that we will need is a method to generate a permutation. Then, you must create a method called randonPernutation that takes as input an integer n and return an array with a random permutation of the integers 1 through n. The easiest way to produce a (pseudo-)random permutation is to create an array of length n and insert into it the integers 1 n. Next, we can randomly select two indexes in the array to swap them. We will completely shuffle the array by performing the random selection (and the swapping) for a total of n times. 1b. Visualizing a Permutation (10 points) A checkerboard visualization is a common method to visualize permutations. The general idea is to generate a grid (ie., 2D-array) to place in the grid (using the rows as a reference) each element of the permutation. As an example, the permutation 5, 2, 4, 1, 3 corresponds to the following 5 x 5 2D-array: Page 3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started