Questions tagged [median]
For code which finds the statistical median of a set of values.
37 questions
1
vote
2
answers
301
views
Median of two sorted arrays in Python
Problem Statement
(Source: Leetcode Problem 4: Median of Two Sorted Arrays [Hard])(Topics: [Array] [Binary Search] [Divide and Conquer])
Given two sorted arrays ...
5
votes
1
answer
73
views
Compute median of a histogram
Another look at finding median value. This time the input is a histogram represented as an ordered range of (value, count) pairs, or simply as a range of counts, with value inferred from position. I'...
7
votes
2
answers
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 ...
6
votes
2
answers
69
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 ...
7
votes
2
answers
1k
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 ...
4
votes
1
answer
476
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 ...
3
votes
2
answers
220
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 ...
6
votes
3
answers
716
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
1
answer
76
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.
...
3
votes
1
answer
970
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
...
5
votes
2
answers
161
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 ...
4
votes
2
answers
335
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 ...
3
votes
1
answer
474
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 ...
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 ...
1
vote
1
answer
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....
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).
...
3
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?
...
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 ...
0
votes
3
answers
2k
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 ...
4
votes
1
answer
107
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 ...
7
votes
5
answers
6k
views
Computing mean and median
I have written a program to compute mean and median. Please review my code and give suggestions.
I have a confusion about this temps[temps.size()/2] when temps....
6
votes
4
answers
480
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
...
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 <...
10
votes
6
answers
2k
views
Median Calculator
This is just a simple median calculator that calculates the median for a given array/list.
...
5
votes
1
answer
901
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. ...
3
votes
2
answers
998
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 ...
3
votes
1
answer
175
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.
...
4
votes
2
answers
26k
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 ...
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 ...
16
votes
3
answers
8k
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.
(...
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
...
6
votes
2
answers
141
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 ...
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.
...
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 ...
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++
...
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 ...
29
votes
4
answers
21k
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.
<...