Hash Table, Map, Object, Set (JS)

Hash Table

  • A dictionary-like structure key-value pairs.

  • Location in memory of each pair is determined by a hash function, which accept keys and return the address of the pair.

  • Hash Function

    • Hash Code: keys -> integers

    • Compression function: integers -> [0, N], e.g. y mod N

  • Collision Handling

    • Separate Chaining: each cell point to a linked list of entries

    • Linear Probing: put in next available cell

    • Double Hashing: use second hash function

  • Worst Case: when all keys insert to the map collide – O(n)

  • Average Case: O(1)

  • Representation

Map

  • a iterable collection of key-value entries, unique keys

Object

  • Pairs of names(strings) and values(any value)

Set

  • Store unique values of any type

Last updated

Was this helpful?