Click to See Complete Forum and Search --> : The Best Structure


Melvik12
November 7th, 2005, 11:56 PM
Hi,
What is the Best Structure for this goal!
the Add function in O(n) and fetch-meddian in O(1)?
Thanks!

mehdi62b
November 8th, 2005, 12:03 AM
a min-max heap (http://www.codeguru.com/forum/showthread.php?t=358351)!

http://kmh.ync.ac.kr/comScience/general/DS/Heap/gifs/minmaxhe.gif

its add would take O(n) but for finding its Meddian you should pick the max and min number and divide them on 2 which would take in O(1)
//I'm not sure what is your meaning from fetch-median?

RoboTact
November 11th, 2005, 06:46 PM
What is add function complexity? if it's one of adding of just one element, you can as well use simple sorted array, inserting new element by bubble sort and picking median as center element of that array. :)

Yves M
November 11th, 2005, 06:57 PM
I read it the same way as Robotact. A sorted array seems like the easiest solution.