Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time complexity of operations in SortedList - Python

What is the time complexity of operations in SortedList implementation of sortedcontainers module? As I understand, the underlying data structure is an array list. So does insertion takes O(n) time since the index can be found in O(logn) and then insert the element at the correct location is O(n)? Similarly, popping an element from an index must be O(n) as well.

like image 395
Damanpreet kaur Avatar asked Jun 24 '26 05:06

Damanpreet kaur


1 Answers

Insert, remove, get index, bisect right and left, find element inside list, are all log(n) operations. Its similar to treeset and multiset in java and c++, implemented with AVL tree or red black tree.

like image 102
JohnZ Avatar answered Jun 26 '26 19:06

JohnZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!