WingMan20-10 - 1 year ago 177

C# Question

I need to write function that will accept array of decimals and it will find the median.

Is there a function in the .net Math library?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Is there a function in the .net Math library?

No.

It's not hard to write your own though. The naive algorithm sorts the array and picks the middle (or the average of the two middle) elements. However, this algorithm is `O(n log n)`

while its possible to solve this problem in `O(n)`

time. You want to look at selection algorithms to get such an algorithm.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**