2015年12月10日星期四

Data Structure -- 3. HashMap

Unlike other sequential data structure(List, Array, String), Hash is not sequential(no order) without direct index access. But it provides map access, which is O(1). And its mapping is very flexible and key can be many things.

HashMap does two important usecases
  • translate original set to a different value set
    • The value normally has certain designed pattern for comparison
  • partition a large set into subgroup. each subgroup shared the same key/signature.
    • The value/subgroup can be a set for storage, comparison, output
Sometimes, bi-directional HashMap(two) can solve binding problems.
The HashMap translate usages are duplicates in a set/string/array, Palindrome, StringIsAnagram
The HashMap subgroup usages are below HashMap can also run multiple scans or bi-directional to handle complex logic

没有评论:

发表评论