Question: #Given a positive integer n between 1 and 9, generate the #permuations of the set {1,2,3,4,...,n} *USING the JOHNSON-TROTTER #ALGORITHM.* #Using 'import time' and 'time.clock()',

#Given a positive integer n between 1 and 9, generate the #permuations of the set {1,2,3,4,...,n} *USING the JOHNSON-TROTTER #ALGORITHM.*

#Using 'import time' and 'time.clock()', determine how many seconds #passes when running this code for n=3, 4, 5, and 6.

#Hints:I wrote the following helper functions. You may find this approach useful. #1. Is a given element mobile? Given a permutation with arrows #and a position, return true if the element in that position is #mobile and false if it is not mobile. #2. Is any element mobile? Given a permutation with arrows, #return true if any element is mobile and false if no element is #mobile. #3. What is the position of the largest mobile element? Given a #permutation with arrows, return the position of the largest mobile #element. #4. What is the next permutation? Given a permutation with arrows, #return the next permutation with arrows.

import time

#Given a number n from 1 to 9, print each of the permuations of #1, 2, ... n to the screen. Calculate the time required to do so, #and print that time to the screen as well.

def permute(n): startTime=time.clock() # BODY OF python FUNCTION i need GOES HERE using # desriptive variable names and comments so i can follow endTime= time.clock() print endTime-startTime # HELPER FUNCTIONS MAY GO HERE if needed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!