What is the 'Load Factor' in a Map?

Updated Apr 28, 2026

Short answer

The load factor of a map (hash table) measures how full the table is by comparing the number of stored entries to the number of available buckets. It is calculated as `number of entries / number of buckets`. A higher load factor saves memory but increases the chance of collisions, while a lower load factor improves performance but uses more memory.

Deep explanation

A map (also called a hash map or hash table) stores data as key-value pairs.

Example:

TEXT
Key Value
"name" -> "Alice"
"age" -> 25
"city" -> "London"

Internally, a hash map uses an array of buckets. A hash function converts each key into an index where the value should be stored.

Example:

TEXT
Hash Function:
"apple" -> 3
"banana" -> 1
"orange" -> 5
Buckets:
Index:
0 1 2 3 4 5
--------------------------------
| |banana | |apple | |orange|
--------------------------------

The load factor tells us how much of this bucket array is occupied.

Load Factor Formula

The formula is:

TEXT
Load Factor = Number of Stored Entries / Number of Buckets

Example:

TEXT
Entries stored = 7
Number of buckets = 10
Load Factor = 7 / 10
Load Factor = 0.7

This means the hash table is 70% full.

Why Load Factor Matters

As more elements are added, the number of entries increases while the number of buckets remains the same.

Example:

Initially:

TEXT
Buckets:
0 1 2 3 4
-----------------
| | | | |
-----------------
Entries: 0
Load Factor: 0

After adding elements:

TEXT
Buckets:
0 1 2 3 4
-----------------
|A |B |C |D |
-----------------
Entries: 4
Load Factor: 4/5 = 0.8

As the load factor increases, collisions become more likely.

Effect of High Load Factor

A high load factor means many entries are stored in a relatively small number of buckets.

Example:

TEXT
Bucket 2:
[Key A]
|
[Key B]
|
[Key C]

Multiple keys map to the same bucket. This is called a collision.

Hash maps handle collisions using techniques such as:

  • Separate chaining: Store multiple entries in a linked list or tree inside a bucket.
  • Open addressing: Find another empty location in the table.

Too many collisions reduce performance because searching within a bucket takes additional time.

Average complexity may change:

OperationGood Load FactorVery High Load Factor
InsertO(1) averageCan approach O(n)
SearchO(1) averageCan approach O(n)
DeleteO(1) averageCan approach O(n)

Effect of Low Load Factor

A low load factor means fewer entries are stored relative to the number of buckets.

Example:

TEXT
Entries = 2
Buckets = 100
Load Factor = 2/100 = 0.02

Advantages:

  • Fewer collisions.
  • Faster lookups.

Disadvantages:

  • Wastes memory because many buckets remain empty.

Resizing and Rehashing

Most hash maps automatically resize when the load factor exceeds a certain threshold.

Example:

TEXT
Initial:
Buckets = 10
Entries = 8
Load Factor = 8/10 = 0.8

If the threshold is 0.75, the map grows:

TEXT
Old table:
10 buckets
New table:
20 buckets

The entries are then redistributed using the hash function. This process is called rehashing.

Rehashing is expensive because every existing entry must be moved.

However, because resizing happens occasionally, insertion remains amortized `O(1)`.

Choosing a Load Factor

A typical load factor is around:

TEXT
0.75

This provides a balance between:

  • Memory usage.
  • Number of collisions.
  • Lookup performance.

A lower load factor may be chosen when:

  • Fast lookups are critical.
  • Memory is available.

A higher load factor may be chosen when:

  • Memory usage is more important.
  • Slightly slower operations are acceptable.

Load Factor in Common Languages

Different programming languages use different default load factors.

Examples:

  • Java's HashMap commonly uses a default load factor of 0.75.
  • Other implementations may choose different values depending on their resizing strategy and performance goals.

The exact value is an implementation detail, but the trade-off remains the same: fewer collisions versus lower memory usage.

Real-world example

Consider a username lookup system.

A map stores usernames and user IDs:

Python
users = {
"alice": 101,
"bob": 102,
"charlie": 103
}

Internally, the map may have:

TEXT
Buckets: 8
Entries: 3
Load Factor = 3 / 8
Load Factor = 0.375

The table has plenty of empty space, so collisions are unlikely and lookups are fast.

If thousands of users are added:

TEXT
Buckets: 8
Entries: 20
Load Factor = 20 / 8
Load Factor = 2.5

The map becomes overcrowded, causing many collisions. The implementation will usually resize the table and redistribute the entries.

Common mistakes

  • * Thinking load factor represents the percentage of memory used instead of the ratio of entries to buckets.
  • * Assuming a higher load factor always improves performance because it uses fewer buckets.
  • * Forgetting that a high load factor increases the chance of hash collisions.
  • * Assuming resizing happens every time an element is inserted.
  • * Confusing load factor with the size of the map.
  • * Believing hash maps always have `O(1)` performance regardless of collisions.
  • * Ignoring the memory trade-off when choosing a load factor.
  • * Forgetting that rehashing temporarily takes `O(n)` time.

Follow-up questions

  • Why does a high load factor increase collisions?
  • What happens when a hash map exceeds its load factor threshold?
  • Why is a load factor of around 0.75 commonly used?
  • Does a lower load factor always make a hash map faster?
  • What is the difference between load factor and capacity in a hash map?
  • How does rehashing affect the complexity of inserting into a hash map?

More Heaps and Maps interview questions

View all →