algorithm - What's the name of this array data structure? -
implement array of size n
array of sqrt(n)
pointers.
to insert item @ i
, go pointer @ i/sqrt(n)
. if pointer null
, assign new array of size sqrt(n)
. insert item in new array @ position i mod sqrt(n)
.
the advantage simple: allows create large array takes o(sqrt(n))
space. can access element in constant time, , allows fill portions of array without needing allocate space n
positions.
this may used hash-tables, , have application in mind. question is: there name this? common implementation can use?
this data structure closely related hashed array tree (hat) data structure. hashed array tree structured you've described above - have top-level array of size √n, each entry pointer array √n elements. makes insertions , lookups reasonably fast , has o(√n) memory overhead compared o(n) memory overhead of traditional dynamic array.
your structure differs hat in few ways. starters, structure not appear have way grow structure if need more space, whereas hat designed growable. additionally, structure allows random insertions, whereas hat designed sequential insertions. said, there's no fundamental reason hat has behave way, can think of data structure slight modification on hat. in fact, might want @ how hat grows in order make data structure support growth.
hope helps!
Comments
Post a Comment