Questions tagged [median]

For code which finds the statistical median of a set of values.

Filter by
Sorted by
Tagged with
5 votes
2 answers
51 views

Flexible median evaluator

I recently posted an externally-evaluating median algorithm (i.e. not requiring move or copy of elements), and the feedback encouraged me to develop it further. One simple suggestion was to handle NaN ...
user avatar
  • 57.9k
7 votes
2 answers
459 views

Median cut algorithm

I have implemented a simple version of the median cut algorithm. It takes a vector of Color structs representing pixel in an image. I also use the ...
user avatar
4 votes
1 answer
85 views

Find median of values without copying

For practice, I've been playing with calculating median values. This time, I wanted to make something that works well without copying the input values (perhaps because they are bulky, or of a type ...
user avatar
  • 57.9k
3 votes
2 answers
208 views

Generic implementation of median #2: Follow up

Follow on from this codereview: generic implementation of median As before the vector2 class is just for illustrative purposes and not the focus. I have ...
user avatar
5 votes
3 answers
410 views

generic implementation of median

Below is a generic implementation of the summary statistics function Median. Discussion of efficient use of std::nth_element and ...
user avatar
1 vote
1 answer
44 views

Stream that computes running median value

I was solving a DSA question, running median in a stream. And I decided to design my own stream class with additional features. ...
user avatar
3 votes
1 answer
509 views

LeetCode: Sliding Window Median C#

https://leetcode.com/problems/sliding-window-median/ Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean ...
user avatar
  • 5,309
5 votes
2 answers
131 views

Rolling median function (Daily Coding Problem 377)

Given an array of numbers arr and a window of size k, print out the median of each window of size k starting from the left and moving right by one position each time. For example, given the ...
user avatar
4 votes
2 answers
208 views

Finding median of sub arrays taking too much time

I'm trying to solve a programming challenge where I have to find the median of given subarrays of an array. I have used std::vector's ...
user avatar
  • 185
3 votes
1 answer
317 views

Find Median of Two Sorted Arrays in JS

The task is taken from leetcode There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should ...
user avatar
  • 3,955
6 votes
2 answers
2k views

Finding median from unsorted array with duplicate elements without sorting it

I am implementing a method to find the median of an unsorted array using a counting sort. I would happily go for a median of medians or selection algorithm for better performance but they are ...
user avatar
  • 429
1 vote
1 answer
2k views

Median of a Vector assignment

I've been reading Bjarne's Principles in Programming and was given some code to demonstrate the usage of vectors and how we can return specific values for certain functionality such as mean and median....
user avatar
  • 117
2 votes
1 answer
1k views

Median of two sorted arrays JavaScript

Trying to find the median of two sorted arrays in O(log(m+n)) or better. I believe this is O(log(m+n) or O(log(m)) or O(n). ...
user avatar
  • 596
2 votes
1 answer
1k views

Median of two sorted arrays

The task is to find the median of two Arrays. I have an O(n) solution. Can it be written in a better time complexity? ...
user avatar
  • 439
7 votes
4 answers
1k views

Median Calculation of List of Integers without using heap

References Using those references: rolling median implementations benchmark FAST RUNNING MEDIAN USING AN INDEXABLE SKIPLIST Calculate the median of a billion numbers Find running median from a ...
user avatar
0 votes
3 answers
1k views

Calculate median of a matrix

I am solving interview questions from here. Problem : Given a N cross M matrix in which each row is sorted, find the overall median of the matrix. Assume N*M is odd. Note: No extra memory is ...
user avatar
4 votes
1 answer
92 views

Find median of two sorted arrays, with complexity of min(log(m),log(n))

I wrote a program which gets two sorted arrays a and b (with sizes m and ...
user avatar
  • 41
6 votes
4 answers
462 views

Find median of two sorted ranges

Given two sorted ranges of elements, compute a median of all the elements in O(log(n+m)) time. This solution contains only one call to std::lower_bound ...
user avatar
3 votes
1 answer
2k views

Median of numbers stored in array

Problem is to calculate median of numbers. My idea is : Fill array of integer with numbers using Arraymake() function copy the address into a pointer created in <...
user avatar
  • 199
10 votes
6 answers
2k views

Median Calculator

This is just a simple median calculator that calculates the median for a given array/list. ...
user avatar
  • 101
5 votes
1 answer
801 views

Find the running median with 2 heaps

I wrote code to solve the running median challenge using 2 heaps, and I'd appreciate any and all feedback. Here is the problem: You have a list of numbers and are scanning them one by one. ...
user avatar
  • 321
3 votes
2 answers
857 views

Find median of list of integers

This code is meant to find the median of a list of integers. The list is assumed to be of odd length. This is based on this HackerRank question. I'm doing this to improve my style and to improve my ...
user avatar
3 votes
1 answer
169 views

Generic Median Heap using PriorityQueues

I've implemented a generic data structure to keep track of the median in a streaming list of numbers. I was hoping to gather the community's feedback on code style and taste. ...
user avatar
4 votes
2 answers
25k views

Find the median value of a list

I am taking an online training course on Python, and am at the following question: Write a function called median that takes a list as an input and returns the median value of the list. For ...
user avatar
  • 43
5 votes
2 answers
3k views

Find median of two sorted arrays

Problem statement There are two sorted arrays nums1 and nums2 of size m and ...
user avatar
  • 3,443
16 votes
3 answers
7k views

The median of the given AVL tree

A long time ago I found this question and asked about an algorithm here. My code is also available on GitHub. Given a self-balancing tree (AVL), code a method that returns the median. (...
user avatar
8 votes
1 answer
4k views

Calculate the running median

I'm trying to solve a challenge where you need to calculate the median every time you add a number. say you have a list of numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ...
user avatar
  • 1,416
6 votes
2 answers
132 views

Median function using min()

I am writing a routine to calculate median using the minimum of the numbers and then changing the value of the minimum to a large value outside the range of numbers (assuming you know the nature of ...
user avatar
2 votes
2 answers
4k views

Calculate median and quartile in C without sorting the array

Here's a piece of working code wrote in C to calculate the median without putting all values in an array and sorting them. It reads values from a file. ...
user avatar
  • 293
3 votes
4 answers
2k views

Median of two sorted equal sized arrays on combination

The comprehensive description of the problem can be found here. I'm looking for code review, clever optimizations, adherence to best practices. etc. This code is also a correction of code previously ...
user avatar
10 votes
2 answers
2k views

Rolling median solution

I was implementing a rolling median solution and was not sure why my Python implementation was around 40 times slower than my C++ implementation. Here are the complete implementations: C++ ...
user avatar
  • 238
2 votes
4 answers
8k views

Improving performance hacker rank Median

I'm trying to compete on HackerRank and my answer got accepted, but the times are not so good. I have a friend who sent the answer in C# too but somehow made it a lot faster. I'm wondering what can I ...
user avatar
28 votes
4 answers
20k views

Calculate a median

I got this as an implementation of "get me the median of those values". But it sort of doesn't feel right (too long, too many branch points) so I thought I'll post it here to see what you think. <...
user avatar
  • 1,536