Data structures and applicability

The data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data

Lists

Sets –

  1. Doesn’t maintain order and doesn’t allow repeated elements.

Stacks –

  1. Depth-first search, behave similar to recursion and can be a replacement for it.

Queues –

  1. Breadth-first search

Heaps – (Priority queue)

  1. Supports
    1. Insertion – O(logn)
    2. Extract min/max – O(logn)
    3. Heapify – O(n)
    4. Delete – O(logn)
  2. Applications:
    1. Scheduled event managing.
    2. Median maintenance – using two heaps, one max heap, and one min heap.
    3. Dijkstra Algorithm – O(m log n)

Search trees –

Trees :

  1. All the nodes should be connected.
  2. should not have cycles.

 

  1. Balanced binary search trees:
    1. Red-black trees.
    2. AVL trees.
    3. Splay trees.

Hash tables –

  1. When you don’t need to remember ordering, minimum or maximum.
  2. To check whether an element exists – O(1)
  3. Insertions and deletions – O(1)
  4. Applications:
    1. 2-sum problem.
  5. Hash function:
  6. Resolving collisions:
    1. Chaining: Linked lists inside each bucket.
    2. open addressing (probe sequence) – one object per bucket.
  7. Choose num of buckets as a prime number.
  8. Load factor: Num of objects/ Num of buckets.
  9. Every hash function has a pathological data set.
  10. Randomization from a family of hash functions at runtime.

Hashing

  1. Use a hash function which deduces the index in which to store the value based on the digits of the value itself (usually last few digits). Store the value in the provided index. when you want to look up, it is of O(1), since lookup from an indexed array is of constant time.

Bloom filters –

  1. More space efficient than hash tables.
  2. No deletions.
  3. Small false positive probability – might say x has been inserted even though it hasn’t been.
  4. Operations:
    1. Fast inserts and lookups.
    2.  
  5. Applications:
    1. Spell-checker.
    2. List of forbidden passwords.
    3. Network routers – Limited memory, need to be super fast.

 

 

Leave a Reply

%d bloggers like this: