java中HashMap.containsKey()的时间复杂度是多少? [英] What is the time complexity of HashMap.containsKey() in java?
问题描述
我需要知道:在Java中HashMap.containsKey()的时间复杂度是多少?
a href =http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html =noreferrer> $ c $的API文档c> HashMap :
$ b
这个实现为基本的
操作提供了恒定的性能(get和put) ,假设散列函数将
元素恰当地分散到桶中。
由于 containsKey()
只是一个抛出检索值的 get()
,它是O(1)(假设散列函数再次正常工作) / p>
I need to know: What is the time complexity of HashMap.containsKey() in java?
From the API doc of
HashMap:
This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets.
Since containsKey()
is just a get()
that throws away the retrieved value, it's O(1) (assuming the hash function works properly, again).
这篇关于java中HashMap.containsKey()的时间复杂度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!