microsoft / ALEX

A library for building an in-memory, Adaptive Learned indEX
MIT License
662 stars 114 forks source link

The meaning of expected shifts approximation formula #27

Open Losk-x opened 2 years ago

Losk-x commented 2 years ago

https://github.com/microsoft/ALEX/blob/0f3af042b497e10acce2a5cb348622ec4140d97d/src/core/alex_base.h#L253

The paper said that in the assumption that "inserts are done according to the existing key distribution", the "average number of shifts for inserts is computed as the average distance to the closest gap in the Gapped Array for all existing keys".

I dont know how to deduce this formula (n-1)/2 * ((n-1)/2+1) from above. Can anybody explain it in detail? Thanks.