Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help for 6.1, design. there is the file: Description: Contains description for permutation class Still to do: printtwoline method printcyclenotation method improve order

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

I need help for 6.1, design. there is the file: Description: Contains description for permutation class Still to do: printtwoline method printcyclenotation method improve order method to decrease runtime? """ class Permutation(): def __init__(self, L=[]): """ L must be a valid one-line notation for a permutation stored as a Python list. Valid one-line notation is an arrangement of the integers 1, 2, ..., n for some positive integer n. """ n = len(L) for x in range(1,n+1): if L.count(x) == 1: continue else: raise ValueError("Invalid initial value for Permutation.") self.P = L def __str__(self): """ Converts permutation to string format for one-line notation """ return str(self.P) def __len__(self): """ Returns n, where self is a permutation of {1, 2, ... n} """ return len(self.P) def __mul__(self, other): """ Computes self * other as permutations """ # Note: This method is O(n) where n = len(self) n = max([len(self), len(other)]) answer = [] for i in range(n): if len(other) == n: # right perm (other) is bigger or equal to left (self) # Check if other.P[i] - 1 is valid index in self if other.P[i] - 1 >= len(self): answer.append(other.P[i]) else: answer.append(self.P[other.P[i]-1]) else: # right perm (other) is strictly smaller than left (self) if i 

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

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

What are the purposes of promotion ?

Answered: 1 week ago