median

Research data analysis in Excel: Median of x times column value

可紊 提交于 2019-12-08 13:29:00
问题 I need to analyze empirical research data. Question Fully agree (1) Agree (2) Neither(3) Disagree (4) Q1 7 3 2 5 Q2 10 7 0 0 Q3 4 3 3 7 Q4 15 0 2 0 So for Question Q1, 7 people fully agree, 4 agree, etc. I have to calculate the median for all questions. The result should look like this: Question Fully agree (1) Agree (2) Neither(3) Disagree (4) Median Q1 7 3 2 5 2 Q2 10 7 0 0 1 For Question Q1, 7 people answered with "fully agree", 3 with "agree", 2 with "Neither" and 5 with "Disagree". I

Find median in four (individually) sorted arrays with O(1) space

守給你的承諾、 提交于 2019-12-08 10:06:32
问题 I have an assignment to find a median in 4 individually sorted arrays. A median is defined as the element that is in the middle of the array (at index floor(N/2)) Requirements: time complexity: linear to the size of the combined array space complexity: O(1) I know how to find a median in 2 sorted arrays with O(1) space and O(logn) time, but I cant find a good solution for 4 arrays that meets the requirement of O(1) space. I have tried to adjust the algorithm for 3 arrays but it didn't work

given 5 numbers, what is the minimum number of comparisons needed to find the median?

六月ゝ 毕业季﹏ 提交于 2019-12-07 21:50:35
问题 how do you setup minimum number of comparisons in general? 回答1: To cite Donald Knuth (by way of Wikipedia, since I don't have my copy of TAOCP at the moment), the lower bound for the number of comparisons is six: http://en.wikipedia.org/wiki/Selection_algorithm (scroll down to the section entitled "Lower Bounds"). Your goal is, effectively, to find the k lowest values where k is half the size of the list, rounded up, (so, k = 3; n = 5) and then take the max of those. Plugging that into the

Get median from AVL tree?

☆樱花仙子☆ 提交于 2019-12-07 10:29:44
问题 If you have an AVL tree, what's the best way to get the median from it? The median would be defined as the element with index ceil(n/2) (index starts with 1) in the sorted list. So if the list was 1 3 5 7 8 the median is 5. If the list was 1 3 5 7 8 10 the median is 5. If you can augment the tree, I think it's best to let each node know the size (number of nodes) of the subtree, (i.e. 1 + left.size + right.size). Using this, the best way I can think of makes median searching O(lg n) time

interviewstreet median challenge

本小妞迷上赌 提交于 2019-12-07 00:54:00
问题 Problem The median of M numbers is defined as the 1) if M is odd middle number after sorting them in order 2) if M is even the average number of the middle 2 numbers (again after sorting) You have an empty number list at first. Then you can add or remove some number from the list. For each add or remove operation, output the median of numbers in the list. Example : For a set of m = 5 numbers, { 9, 2, 8, 4, 1 } the median is the third number in sorted set { 1, 2, 4, 8, 9 } which is 4.

Calculating median - javascript

对着背影说爱祢 提交于 2019-12-06 17:19:23
问题 I've been trying to calculate median but still I've got some mathematical issues I guess as I couldn't get the correct median value and couldn't figure out why. Here's the code; class StatsCollector { constructor() { this.inputNumber = 0; this.average = 0; this.timeout = 19000; this.frequencies = new Map(); for (let i of Array(this.timeout).keys()) { this.frequencies.set(i, 0); } } pushValue(responseTimeMs) { let req = responseTimeMs; if (req > this.timeout) { req = this.timeout; } this

Running or sliding median, mean and standard deviation

别等时光非礼了梦想. 提交于 2019-12-06 12:45:53
问题 I am trying to calculate the running median, mean and std of a large array. I know how to calculate the running mean as below: def running_mean(x, N): cumsum = np.cumsum(np.insert(x, 0, 0)) return (cumsum[N:] - cumsum[:-N]) / float(N) This works very efficiently. But I do not quite understand why (cumsum[N:] - cumsum[:-N]) / float(N) can give the mean value (I borrowed from someome else). I tried to add another return sentence to calculate the median, but it does not do what I want. return

running median of constant size array

强颜欢笑 提交于 2019-12-06 11:50:25
I am trying to find median of constant size array. But array is always uptading. I mean new numbers are replaced with old numbers. I call this process running median, or we can say on the fly median.. Here is my code and inside the code, when rand() function generates 78, the code cannot find the correct median. (Before 78; 41, 67, 34, 0, 69, 24 was generated) #include <iostream> #include <stdlib.h> #include <algorithm> #define MAX_SIZE 5 using namespace std; bool isOdd( int integer ) { if ( integer % 2 == 0 ) return false; else return true; } int main() { int median; int *minArray ; int

given 5 numbers, what is the minimum number of comparisons needed to find the median?

馋奶兔 提交于 2019-12-06 04:34:11
how do you setup minimum number of comparisons in general? James McNellis To cite Donald Knuth (by way of Wikipedia, since I don't have my copy of TAOCP at the moment), the lower bound for the number of comparisons is six: http://en.wikipedia.org/wiki/Selection_algorithm (scroll down to the section entitled "Lower Bounds"). Your goal is, effectively, to find the k lowest values where k is half the size of the list, rounded up, (so, k = 3; n = 5) and then take the max of those. Plugging that into the formula there on the page, you get: (5 - 3) + 1 + 1 + 2 = 6 In this case, the actual minimum

Complexity of finding the median using 2 heaps

社会主义新天地 提交于 2019-12-06 02:06:40
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>>a; if (left.empty()) left.push(a); else if (left.size()<=right.size()) { if (a<=right.top()) left.push