The fundamentals of Hash tables?

前端 未结 11 796
灰色年华
灰色年华 2020-12-07 08:23

I\'m quite confused about the basic concepts of a Hash table. If I were to code a hash how would I even begin? What is the difference between a Hash table and just a normal

11条回答
  •  抹茶落季
    2020-12-07 08:50

    The question, I believe, is answered quite clearly and in many different ways by now.

    I would just like to add another perspective (which may confuse a new reader as well)

    At a level of least abstraction, arrays are just contiguous block of memory. Given the starting address (startAddress), size (sizeOfElement) and the index of a single element, the address of element is computed as:

    elementAddress = startAddress + sizeOfElement * index
    

    The interesting thing to note here is that arrays can be abstracted/viewed as hash tables with index as key and the above function as a hash function which calculates the location of a value in O(1)

提交回复
热议问题