# Questions tagged [median]

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

34 questions
Filter by
Sorted by
Tagged with
1k views

### Calculating the median and mode of a list of integers

Going through the Rust book for the second time as I've been wrapped up in Typescript for a while and I want to build a personal project in Rust. In chapter 8.3, there's an exercise: Given a list of ...
65 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 ...
875 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 ...
336 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 ...
217 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 ...
568 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 ...
1 vote
65 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. ...
812 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 ...
146 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 ...
309 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 ...
427 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 ...
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 ...
1 vote
4k 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....
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). ...
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? ...
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 ...
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 ...
102 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 ...
470 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 ...
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 <...
2k views

### Median Calculator

This is just a simple median calculator that calculates the median for a given array/list. ...
868 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. ...
975 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 ...
174 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. ...
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 ...
3k views

### Find median of two sorted arrays

Problem statement There are two sorted arrays nums1 and nums2 of size m and ...
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. (...
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 ...
139 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 ...
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. ...
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 ...
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++ ...