add dynamic median algorithm