Question: 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

Ster A sorted list is a list that is in a sorted

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

1 Expert Approved Answer
Step: 1 Unlock

Heres the implementation of the SortedList class in Python following the given steps and alg... View full answer

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 Programming Questions!