I know that this class uses a Red-Black tree but does that mean that it is O(log(n)) to get the least element or is it O(1) or something else?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given it is a binary search tree, it must traverse the height of the tree (which is O(log n)) in order to reach the first (i.e. least) entry, so indeed the method is O(log n).
You can see how it is implemented in OpenJDK here.
If you’re looking for a structure supporting constant-time find-minimum, maybe look into using a binary min heap, where the root node corresponds to the minimum. Note this is a totally different data structure with different semantics.