简体   繁体   中英

Load factor in HashMap with linkedList

For load factor, I know it's the total number of elements divided by the space available. For the picture below, at index 2 for example, does it count as 1 spot or 6?

在此处输入图片说明

for load factor, I know it's the total number of elements divide by the space available

Yes, the load factor is the total number of entries divided by the number of bins. That's the average number of entries stored in each bin of the HashMap . This number should be kept small in order for the HashMap to have expected constant running time for the get(key) and put(key,value) methods.

at index 2 for example, does it count as 1 spot or 6

Each index represents 1 bin of the HashMap , regardless of how many entries are stored in it.

Therefore, in your example (the image you linked to), you have 10 entries and 5 bins, and the load factor is 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM