Wednesday, September 3, 2014

Frequently used Java class

  1. TreeMap
    1. Red-black tree based
    2. Ordered for key
  2. LinkedHashMap
    1. Hashtable and linked list based
    2. Insertion order preserved
  3. HashMap
    1. Hashtable based map
    2. Allow null value and null key
    3. Unsynchronized 
    4. No order of key or value
  4. ConcurrentHashMap
    1. More modern than hashtable
    2. Use more buckets therefore less likely to be blocked
  5. Hashtable
    1. Synchronized
  6. Blocking queue

Saturday, August 30, 2014

Wednesday, August 27, 2014

Distributed system design

  1. ACP in 12 years
  2. Memcached
    1. Distributed in-memory key-value store for small chunks of arbitrary data
    2. Membase, later changed to CouchDB
    3. Caveat:
      1. Volatile due to eviction, full, service crashing
      2. Too many items may cause thrashing
      3. Non-transactional
  3. UDP vs TCP
    1. UDP is connection-less protocol and faster than TCP, especially when occasional loss is not a big issue such as video stream, VoIP. UDP is very good for pub-sub used in Tibco. Good for heartbeat too. Packages may arrive out of order. Package based
    2. TCP has very huge overhead for handshaking and is bytestream based, therefore merging them back is a big overhead. Point-to-point connection has to be maintained
    3. http://stackoverflow.com/questions/1099672/when-is-it-appropriate-to-use-udp-instead-of-tcp
  4. Scatter-gather IO
    1. readv, writev
    2. facebook uses it cut down CPU by 50%
  5. Tinyurl

Reference

  1. http://n00tc0d3r.blogspot.com
  2. UIUC professor notes
  3. Professional code style
    1. http://google-styleguide.googlecode.com/svn/trunk/cppguide.html
    2. http://google-styleguide.googlecode.com/svn/trunk/javaguide.html
    3. http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

DP

  1. Longest increasing sequence (LIS)
    1. There is always a DAG of computation underlying every dynamic program but it is not always clear
    2. http://bix.ucsd.edu/bioalgorithms/book/excerpt-ch6.pdf
    3. http://wordaligned.org/articles/patience-sort.html (not sure correctness)
  2. Given n houses and m colors. The cost of painting different house with different color might be different. Find out the min cost of painting all houses such that no adjacent houses have same color.

 

Graph