algorithm - Floating point hash table -


i want construct lookup table using floating point value key. when query table given floating point key, want return value key closest query key.

however don't know beforehand if floating point keys evenly distributed or not.

for example, table might be:

key     value 1.0     "red" 1.25    "blue" 2.0     "green" 

if query 1.5, want "blue".

is there way construct table has o(n) memory , o(1) lookup? (that is, hash table). there's o(log(n)) algorithm if store key/value pairs sorted, i'm curious if bound can improved.

you can ignore fact key floating-point number doesn't effect answer. answer same if input 32-bit (equivalent float) or 64-bit (equivalent double) integer. and, believe answer 'no'.

in order find nearest neighbor need keys sorted. when have 32-bit or 64-bit key (it helpful clarify which) means have no choice have sorted data structure (tree? heap? sorted array?) o(log(n)) search in.

it's easy constant-time access specific entry, getting constant-time access nearest neighbor specific entry either requires lookup table 4 billion entries (for floats) or magic.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -