Question: Time compleity of add() function is O(log(n)), so if n elements are added to the sorted list object then overall time complexity to build sorted

Time compleity of add() function is O(log(n)), so if n elements are added to the sorted list object then overall time complexity to build sorted list is O(nlog(n))

# code

from sortedcontainers import SortedList

# read list from user

user=[int(i) for i in input("Enter list: ").split()]

# create sorted list

testing=SortedList()

# add elements 1 by 1

for i in user:

testing.add(i)

print(list(testing))

Can the method add in the SortedList class be improved? Hint: the list is already in a sorted state. What would the complexit

How can this be done using python?

Can the method add in the SortedList class be improved? Hint: the list is already in a sorted state. What would the complexity of an improved add be?

Step by Step Solution

3.43 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To improve the efficiency of adding multiple elements to a sorted list especially when the input lis... 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!