Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Python program to create a class for a list-based array. The class must implement all the following methods methods are allowed!) : def
Write a Python program to create a class for a list-based array. The class must implement all the following methods methods are allowed!) : def _init__(self, capacity=10): \# You cannot change this line "" "Constructor for the class. It initializes the array with a list of None elements. The size of the initial array is provided by the user It also initializes the length of the array. Parameters --apacity : int The initial capacity for the array den isefmpty(self): in" Method to check if the array is empty The method returns True or False if the array is empty "n" def append(self, new_item): \# You cannot change this line ""l" Method to append a new item at the end of the array The metod receives a new item and append it to the array The method needs to check if the array is full and call the resize() method The new size is the double of the current size. Parameters new_item: int The new item to be appended def remove_at(self, index): \# You cannot change this line """ Method to remove an item at a specific index from the array The metod receives an index and removes that element from the array The method needs to check if the array is empty and it shows "The array is empty" message if it is empty and returns - 1 The method needs to check if the index is in the correct range The method needs to resize the array if the length has fall below 25% The new size is the rounded to 25% of the current size. Parameters index: int The index of the element to remove def remove(self): \# You cannot change this line """ Method to remove an item from the end of the array The method needs to check if the array is empty and it shows "The array is empty" message if it is empty and returns - 1 The method needs to resize the array if the length has fall below 25% The new size is the rounded to 25% of the current size. def __len__(self): \# You cannot change this line Running time: For each method calculate the running time. Express the running time using Big-o notation. Write your answer for each method as an additional comment at the beginning of the method. How to test your class? I am giving you a tester program. Use it and understand how it works. Please, check the Figure below
Step 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