Programming Exercises

Most of the exerices here are open ended in that one can spend days implement an advanced and efficient versions. However, the idea is these can be used as quick exercises for fun where you come up with a simplistic toy implementation. The solution code for most problems can be found at https://github.com/sharvanath/generalcsproblems. However, note that the solution codes have been written by me quickly and not been tested thoroughly.

  • [LRUCache] Implement an in-memory fixed size cache of objects with LRU replacement policy that supports.
    • Put(int key, value)
    • Get(int key)
  • [Memtable] Implement a serializable memtable which supports:
    1. Put(int key, int value)
    2. Get(int key)
    3. Flush to disk
    4. Read from disk
  • [ReaderWriterLock] Implement reader writer lock that avoids starvation.
  • [ResourceAllocator] Implement a resource allocator that supports allocating contiguous resources from a fixed size pool (much like malloc):
    1. int AllocateResources(int amount). Return the index of the first resource.
    2. void FreeResources(int index, int amount).
  • [VersionedVector] Implement a fixed sized vector that supports snapshotting.
    1. void Set(int index, int value)
    2. void Get(int index)
    3. int TakeSnapshot. Returns the snapshot id.
    4. int Get(int index, int snapshot_id)