java中HashMap.containsKey()的时间复杂度是多少? [英] What is the time complexity of HashMap.containsKey() in java?

查看:1211
本文介绍了java中HashMap.containsKey()的时间复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道:在Java中HashMap.containsKey()的时间复杂度是多少?

解决方案

a href =http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html =noreferrer> 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 ofHashMap:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆