Finding the $p$ Closest Elements to Median of Set $M$ in $O(m)$ Time

Click For Summary

Discussion Overview

The discussion centers around developing an algorithm with a time complexity of $O(m)$ to find the $p$ closest numbers to the median of a set $M$ containing $m$ numbers. Participants explore the feasibility of this task, considering both sorted and unsorted lists, and the implications of median finding algorithms.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • One participant proposes an algorithm to find the $p$ closest numbers to the median of set $M$ with a time complexity of $O(m$).
  • Another participant questions whether the list of numbers is pre-sorted, suggesting that the algorithm should work for both sorted and unsorted cases.
  • A different participant expresses doubt about the possibility of achieving this in $O(m)$ time, initially stating that no sorting algorithm runs in that time, but later corrects themselves, acknowledging that finding the median can be done in $O(n)$ time.
  • One participant outlines a recursive algorithm structure involving the median of medians and asks how to refine the result to find the $p$ nearest elements to the median from an interval that may contain $2p$ elements.

Areas of Agreement / Disagreement

Participants express differing views on the feasibility of the proposed algorithm, with some uncertainty about the conditions under which it can be implemented. There is no consensus on the final approach or solution.

Contextual Notes

Participants note the complexity of finding the median and the implications of working with sorted versus unsorted data. The discussion includes references to specific algorithms, such as the median of medians, without resolving the mathematical steps involved.

Who May Find This Useful

This discussion may be useful for those interested in algorithm design, particularly in the context of median finding and proximity searches within data sets.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)
I want to describe an algorithm with time complexity $O(m)$ that, given a set $M$ with $m$ numbers and a positive integer $p \leq m$, returns the $p$ closest numbers to the median element of the set $M$.

How could we do this? (Thinking)
 
Last edited:
Technology news on Phys.org
What could we do in order to find the $p$ closest numbers to the median element of the set $M$ ? Could you give me a hint? (Thinking)
 
evinda said:
Hello! (Wave)
I want to describe an algorithm with time complexity $O(m)$ that, given a set $M$ with $m$ numbers and a positive integer $p \leq m$, returns the $p$ closest numbers to the median element of the set $M$.

How could we do this? (Thinking)

Complexity $O(m)$ algorithm operating on a list of size $m$ implies that you're only allowed to do a single pass of the list. Is this list of numbers pre-sorted or not?
 
PvsNP said:
Complexity $O(m)$ algorithm operating on a list of size $m$ implies that you're only allowed to do a single pass of the list. Is this list of numbers pre-sorted or not?

No, I think that the algorithm should work for each case... (Thinking)
 
evinda said:
No, I think that the algorithm should work for each case... (Thinking)

Without thinking about it in depth, I'm not sure that this is possible. Median is the "middle" value on a set of ranked values, and no sorting algorithm runs in $O(n)$ time.

EDIT: I'm wrong. It's possible to find the median in $O(n)$ time. See if this helps you: Median of medians - Wikipedia, the free encyclopedia
 
Doing it like that:

Code:
low=m/2-(p-1)
high=(m-1)/2+(p-1)
Algorithm(A,begin,end,low,high){
  if (begin<end){
      k=medianofMedians(A,low,high)
      q=hoare(A,start,begin,end,k)
      if (q>low) Algorithm(A,begin,q-1,low,high)
      if (q<high) Algorithm(A,q+1,end,low,high)
   }
}

we will have the interval to which the $p$ elements we are looking for belong.
But this interval will contain $2p$ elements.
How can we find the $p$ nearest elements to the median? (Sweating)
 

Similar threads

Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 27 ·
Replies
27
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
25
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K