Time compleity of add() function is O(log(n)), so if n elements are added to the sorted list
Fantastic news! We've Found the answer you've been seeking!
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 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?
Related Book For
Introductory Econometrics A Modern Approach
ISBN: 978-0324660548
4th edition
Authors: Jeffrey M. Wooldridge
Posted Date: