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))

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
To improve the efficiency of adding multiple elements to a sorted list especially when the input lis... View full answer
Get step-by-step solutions from verified subject matter experts
