A look-up operation OR contains for single can be O(n) in worst-case right ? So, for n elements look up in hashSet will be O(n^2)?
A look-up operation OR contains for single can be O(n) in worst-case right ?
Share
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.
Yes, but it’s really the worst case: if all the elements in the
HashSethave the same hash code (or a hash code leading to the same bucket). With a correctly writtenhashCodeand a normally distributed key sample, a lookup is O(1).