Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use python to implement it, i have given the steps and algorithm Ster A sorted list is a list that is in a sorted state

Use python to implement it, i have given the steps and algorithm

Ster A sorted list is a list that is in a sorted state at all times. Implement a class called SortedList that has the following methods: a) _init__: initializes an instance variable called content to an empty list. This list is going to represent our sorted list. b) add: this method accepts an element x and insert it in the correct position in the list. Here, the list is already assumed to be sorted, and we have to insert x in a position that keeps the list sorted. For example, if the list is [3, 12, 12, 28], then adding 9 to the list results in the new list [3, 9, 12, 12, 28]. This can be done by comparing x to the elements of the list, starting from position 0, until we find the correct position. c) remove: this method accept an integer pos, and remove the element at position pos. Hint: see the built-in function del in Python. This method should not do anything if the list is empty. d) search: this method accepts a value x and returns the position of x in the list. If no such element exists, the method returns None. Since, the list is sorted, you can perform binary search here. e) get_list: this method returns the list content. - If the current length of a sorted list is n, what are the complexities of the methods in parts b, lin 1. and d in

Step by Step Solution

3.39 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

python code sortedList class class SortedList initiali... 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_2

Step: 3

blur-text-image_3

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

Introductory Statistics

Authors: Prem S. Mann

8th Edition

9781118473986, 470904100, 1118473981, 978-0470904107

More Books

Students also viewed these Programming questions