Friday, January 2, 2015

Real Life Application of HashTable

There are so many situations where you have one piece of information (key) and want a system to give you more information based on that key.



This is the need behind the evolution and implementation of several computing structures such as databases, binary trees, hash tables, and supporting algorithms.




Hash Tables have the following features:


  1. They facilitate a quick and sometimes inexpensive way to retrieve information. They consume little CPU and if small-enough can fit in RAM. The speed is gained from the way the data location is calculated from the key, this is done in almost a linear fashion which outperforms other methods like binary search and linear search
  2. They can store information based on a key.
  3. They are language/technology independent. They don't require special hardware or software to implement them as the majority of programming languages would be sufficient to create the necessary algorithms for them.
  4. They have friendly interface - to get data, you pass a key and to store data, you pass a key in addition to the data.
  5. The theory allows the storage and retrieval of data based on numeric as well as non-numeric key values.
    Hash tables are used in memory during the processing of a program (they can be persisted to disk but that is a different topic), some usages are  :
  6. Facilitation of Associative Arrays - 
  7. Lookup values (states, provinces, etc.). You could load small amounts from database into hash tables for quick lookups (decoding an encoding of data) - This is of paramount effect in large batch jobs for Extract Load and Transform scenarios. It is also very valuable for data validation.
  8.  Data Buffering. You could store frequently used data from a database in a hash table to facilitate quick access.
  9.  Uniqueness Checking - You can use hash tables to ensure that no value is duplicate in a list.
  10. Keyword Recognition - In cases you want to identify if a given text has certain keywords in it or not, instead of checking the database with each value, you could use a hash table
  11.  Decision tables - Large conditional flows may be stored in an array where given a condition id, you could retrieve and execute related code segments (this may be used in interpreted languages).
  12. Game programming could use Hash tables to keep track of player scores, weapons of a player, etc.