Joseph Jang
Joseph Jang

Reputation: 33

Why is TreeSet.remove's time complexity O(in N)?

A treeset is already sorted... so why isn't the time complexity to remove an object O(Log N) through binary search? Am I missing something?

Upvotes: 0

Views: 813

Answers (1)

Hulk
Hulk

Reputation: 6573

It is O(log N) according to the JavaDocs for TreeSet:

This implementation provides guaranteed log(n) time cost for the basic operations (add, remove and contains).

Upvotes: 1

Related Questions