median

Find median in binary search tree

混江龙づ霸主 提交于 2019-12-01 02:15:13
问题 Write the implementation of the function T ComputeMedian() const that computes the median value in the tree in O(n) time. Assume that the tree is a BST but is not necessarily balanced. Recall that the median of n numbers is defined as follows: If n is odd, the median is x such that the number of values smaller than x is equal to the number of values greater than x. If n is even, then one plus the number of values smaller than x is equal to the number of values greater than x. For example,

Conditional median in MS Excel

点点圈 提交于 2019-11-30 22:31:10
问题 I'm trying to calculate the conditional median of a chart that looks like this: A | B ------- x | 1 x | 1 x | 3 x | y | 4 z | 5 I'm using MS Excel 2007. I am aware of the AVERAGEIF() statement, but there is no equivalent for Median. The main trick is that there are rows with no data - such as the 4th "a" above. In this case, I don't want this row considered at all in the calculations. Googling has suggested the following, but Excel won't accept the formula format (maybe because it's 2007?)

Standard sorting networks for small values of n

吃可爱长大的小学妹 提交于 2019-11-30 13:21:08
问题 I'm looking for a sorting network implementation of a 5-element sort, but since I couldn't find a good reference on SO, I'd like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A good answer should at least list them as sequences of "swap" (sort on 2 elements) operations, but it might also be nice to see the recursive decomposition in terms of lower-order sorting networks. For my application, I actually only care about the

Matlab Median Filter Code

▼魔方 西西 提交于 2019-11-30 10:39:56
I am required to implement median filtering in MATLAB for images. However, I'm not allowed to use the medfilt2 or ordfilt2 functions in MATLAB. We also have recently started learning MATLAB. Is there any code available for the median filter or Gaussian filter available? rayryeng NB: This assumes that the Image Processing Toolbox is installed. The basic premise behind median filtering is to analyze pixel neighbourhoods in your image, sort their intensities, then choose the middle intensity as the result. One suggestion I can make is to use im2col to transform each pixel neighbourhood into a

Add hline with population median for each facet

旧城冷巷雨未停 提交于 2019-11-30 08:22:32
问题 I'd like to plot a horizontal facet-wide line with the population median of that facet. I tried the approach without creating a dummy summary table with the following code: require(ggplot2) dt = data.frame(gr = rep(1:2, each = 500), id = rep(1:5, 2, each = 100), y = c(rnorm(500, mean = 0, sd = 1), rnorm(500, mean = 1, sd = 2))) ggplot(dt, aes(x = as.factor(id), y = y)) + geom_boxplot() + facet_wrap(~ gr) + geom_hline(aes(yintercept = median(y), group = gr), colour = 'red') However, the line

Explanation of the Median of Medians algorithm

。_饼干妹妹 提交于 2019-11-30 07:26:14
问题 The Median of medians approach is very popular in quicksort type partitioning algorithms to yield a fairly good pivot, such that it partitions the array uniformly. Its logic is given in Wikipedia as: The chosen pivot is both less than and greater than half of the elements in the list of medians, which is around n/10 elements (1/2 * (n/5)) for each half. Each of these elements is a median of 5, making it less than 2 other elements and greater than 2 other elements outside the block. Hence, the

Standard sorting networks for small values of n

一笑奈何 提交于 2019-11-30 06:52:38
I'm looking for a sorting network implementation of a 5-element sort, but since I couldn't find a good reference on SO, I'd like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A good answer should at least list them as sequences of "swap" (sort on 2 elements) operations, but it might also be nice to see the recursive decomposition in terms of lower-order sorting networks. For my application, I actually only care about the median of 5 elements, not actually putting them in order. That is, the order of the other 4 elements

ggplot2 boxplot medians aren't plotting as expected

谁说我不能喝 提交于 2019-11-29 19:14:20
问题 So, I have a fairly large dataset (Dropbox: csv file) that I'm trying to plot using geom_boxplot . The following produces what appears to be a reasonable plot: require(reshape2) require(ggplot2) require(scales) require(grid) require(gridExtra) df <- read.csv("\\Downloads\\boxplot.csv", na.strings = "*") df$year <- factor(df$year, levels = c(2010,2011,2012,2013,2014), labels = c(2010,2011,2012,2013,2014)) d <- ggplot(data = df, aes(x = year, y = value)) + geom_boxplot(aes(fill = station)) +

Add a Median Method to a List

你说的曾经没有我的故事 提交于 2019-11-29 17:31:18
问题 I would like to override the List object in C# in order to add a Median method like Sum or Average. I already found this function: public static decimal GetMedian(int[] array) { int[] tempArray = array; int count = tempArray.Length; Array.Sort(tempArray); decimal medianValue = 0; if (count % 2 == 0) { // count is even, need to get the middle two elements, add them together, then divide by 2 int middleElement1 = tempArray[(count / 2) - 1]; int middleElement2 = tempArray[(count / 2)];

Fast Median Filter in C / C++ for `UINT16` 2D Array

故事扮演 提交于 2019-11-29 14:49:01
问题 Does anyone know a fast median filter algorithm for 16-bit (unsigned short) arrays in c++? http://nomis80.org/ctmf.html This one seems quite promising, but it only seems to work with byte arrays. Does anyone know either how to modify it to work with shorts or an alternative algorithm? 回答1: The technique in the paper relies on creating a histogram with 256 bins for an 8 bit pixel channel. Converting to 16 bits per channel would require a histogram with 65536 bins, and a histogram is required