TreeSet icon indicating copy to clipboard operation
TreeSet copied to clipboard

TreeSet `remove` method time complexity is O(n)

Open GaoangLiu opened this issue 5 years ago • 1 comments

From your implementation code, https://github.com/fukatani/TreeSet/blob/5e24a515148c9cc2947b392518413a76b9885453/treeset.py#L67 I believe you're using Python list built-in remove method to remove an element. The time complexity of this method is O(n).

However, Java TreeSet.remove() is O(log n), I wonder is there any way to speed up the remove operation?

GaoangLiu avatar Aug 14 '20 08:08 GaoangLiu

This would require a custom class because the list and linked list implementations in Python have O(n) stopgaps for trying to deleting an arbitrary value or index respectively.

alanyee avatar Oct 02 '20 19:10 alanyee