PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 20, 2022

[FIXED] How to calculate the average fill rate of a hash table?

 September 20, 2022     hashmap, hashtable     No comments   

Issue

I'm looking at a hash table implementation and it says that the table will grow by doubling in size when it's 75% full, which gives it an average fill rate of:

(75 + 75 / 2) / 2 = 56%.

How did the author arrive at this formula? If the table tripled in size, would the 2's become 3's?


Solution

(75 + 75 / 2) / 2 = 56%.

It's basically saying that when it comes times for resizing, the table will be 75% full (the first 75), but the prior resizing would have happened when the table was half as big, so at that time the number of elements would have been half as much as needed for this resize, so 75 / 2. Outside the parentheses, the trailing / 2 takes the average of these two load factors.

If the table tripled in size, then we'd have:

(75 + 75 / 3) / 2 = 50%.

That reflects the load factor after a resize being only 25% now, but we still have a trailing / 2 to get an average over that initial 25% load factor and the 75% load factor at which it will resize again.



Answered By - Tony Delroy
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing