demilev / median

Implementation of data structure for finding median.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Median Data Structure

This repo contains c++ implementation of data structure for finding median. The implementation is done with two heaps(max_heap & min_heap). The invariant is that on every insertion in the data structure the max_heap has one element more than the min_heap and the top of the max_heap is the median or that both heaps have the same number of elements and the median is the average of the top elements of the heaps. This implementation gives O(lgn) time complexity on insertion and O(1) time complexity on getting the median.

Requirements

In order to use the project you will need C++ compiler and CMake version >= 3.5.

Building

 $ # clone the repo 
 $ cd median
 $ mkdir build && cd build
 $ cmake ..
 $ make

After that you can run the tests.

$ make test

Interface

The data structure provides the following interface:

class MedianStructure
{ 
  public:
      MedianStructure& insert(const double);
      double getMedian(); 
};

License

This program is provided under an MIT open source license, read the LICENSE file for details.

About

Implementation of data structure for finding median.

License:MIT License


Languages

Language:C++ 82.5%Language:CMake 17.5%