Best sorting strategy for online median?

Status
Not open for further replies.

anasimtiaz

Junior Member level 1
Joined
Oct 21, 2006
Messages
19
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,424
I'm trying to implement an online running median filter. It is supposed to give out the median value from a list of 101 elements. When a new input is available, the oldest value is dumped, newest taken and median produced. Now, initially the sorting will be expensive but once the array is sorted computational load should decrease. I have two questions here:
1) What algorithm is best for sorted or mostly sorted array?
2) Since I need to remove the oldest value, I also need to store the index of the sorted array right? Is there a better way of doing thinks.

Any pointers would be much appreciated.


Many thanks.
 

if u use bubble sort it will take O. On the other hand, divide and conquer algorithms like quick sort, merge sort will take O(log n) time which is comparatively quicker. and maybe u can use an array or queue to implement
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…