When called on a Map, is the time complexity of clear O(1) or O(n) on the size of the map?
When called on a Map , is the time complexity of clear O(1) or
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.
In the case of immutable maps don’t have clear since they are immutable but they do have empty which returns a new empty map of that type. Since it is just an object creation it is O(1). Mutable maps however are O(n) where n is based on the underlying data structure since they have to clear out that data structure. For the typical mutable HashMap this will be a table. The table size will be between 0.75 and 1.5 the maximum size the Map has been in the past.