Complexity of finding the median using 2 heaps
问题 A way of finding the median of a given set of n numbers is to distribute them among 2 heaps. 1 is a max-heap containing the lower n/2 (ceil(n/2)) numbers and a min-heap containing the rest. If maintained in this way the median is the max of the first heap (along with the min of the second heap if n is even). Here's my c++ code that does this: priority_queue<int, vector<int> > left; priority_queue<int,vector<int>, greater<int> > right; cin>>n; //n= number of items for (int i=0;i<n;i++) { cin>