473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Finding the Median in an Array

Hello,

I have several jagged arrays which have been sorted.
I'm trying to find the median of each array. Any tips appreciated.

TIA.
Bhads.

Mar 22 '07 #1
7 35973
On Mar 22, 3:56 pm, "Bhadan" <m...@here.comwrote:
I have several jagged arrays which have been sorted.
I'm trying to find the median of each array. Any tips appreciated.
Well, which bit are you stuck on? Completely stuck for ideas, or just
unsure of implementation?

Are you trying to find the median of each part of each jagged array,
or each jagged array "as a whole"?

I'd start by thinking of how you'd do it for a "normal" array...

Jon

Mar 22 '07 #2
Hello Bhadan,
>I have several jagged arrays which have been sorted.
I'm trying to find the median of each array. Any tips appreciated.
Hm... are you asking how to calculate a median over a list of values? Look
here: http://www.statcan.ca/english/edu/po...ian/median.htm
Oliver Sturm
--
http://www.sturmnet.org/blog
Mar 22 '07 #3
"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
>>I have several jagged arrays which have been sorted.
I'm trying to find the median of each array. Any tips appreciated.

Hm... are you asking how to calculate a median over a list of values?
I sort of assumed he wasn't, since he mentioned jagged arrays, or "arrays of
arrays" if you prefer...
http://msdn2.microsoft.com/en-us/library/2s05feca.aspx
Mar 22 '07 #4
Hello Mark,
>I sort of assumed he wasn't, since he mentioned jagged arrays, or "arrays
of arrays" if you prefer...
http://msdn2.microsoft.com/en-us/library/2s05feca.aspx
I had the same thoughts, but then he says rather clearly "I'm trying to
find the median of each array".

If we're talking several arrays, I don't think there's a clear-cut
algorithm anyway - he'd just have to calculate a value per array and take
it from there. Then what value would that be? Another median maybe? Or a
mean? Depends, I guess...
Oliver Sturm
--
http://www.sturmnet.org/blog
Mar 22 '07 #5
Oliver Sturm <ol****@sturmnet.orgwrote:
I sort of assumed he wasn't, since he mentioned jagged arrays, or "arrays
of arrays" if you prefer...
http://msdn2.microsoft.com/en-us/library/2s05feca.aspx

I had the same thoughts, but then he says rather clearly "I'm trying to
find the median of each array".
Unfortunately that's not terribly clear, as he has "several jagged
arrays". If he had a single jagged array, then the meaning of "each
array" would be clear. As it is, he could mean each "subcomponent"
array or he could mean each "top-level" jagged array.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 22 '07 #6
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
Unfortunately that's not terribly clear, as he has "several jagged
arrays". If he had a single jagged array, then the meaning of "each
array" would be clear. As it is, he could mean each "subcomponent"
array or he could mean each "top-level" jagged array.
Perhaps he'll let the group know...
Mar 22 '07 #7
On 22 Mar, 17:55, Jon Skeet [C# MVP] <s...@pobox.comwrote:
Oliver Sturm <oli...@sturmnet.orgwrote:
>I sort of assumed he wasn't, since he mentioned jagged arrays, or "arrays
>of arrays" if you prefer...
>http://msdn2.microsoft.com/en-us/library/2s05feca.aspx
I had the same thoughts, but then he says rather clearly "I'm trying to
find the median of each array".

Unfortunately that's not terribly clear, as he has "several jagged
arrays". If he had a single jagged array, then the meaning of "each
array" would be clear. As it is, he could mean each "subcomponent"
array or he could mean each "top-level" jagged array.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Comically I had the same confusion but not until I'd written the
following. Figured I'd post anyway.

using System;
using System.Collections;
namespace ConsoleApplication3
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,2,4,7,9,11})); //5.5
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,2,10,9,11})); //10
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,8,10,9,11,15,15})); //9
Console.WriteLine("Median = {0}",GetMedian(new int[]
{1,4,10,12,33,88})); //11

Console.WriteLine("Median = {0}",GetMedian(new ArrayList(new int[]
{1,2,3,100}))); //2.5

Console.ReadLine();
}
static double GetMedian(int[] pNumbers)
{
int size = pNumbers.Length;
int mid = size /2;
double median = (size % 2 != 0) ? (double)pNumbers[mid] :
((double)pNumbers[mid] + (double)pNumbers[mid-1]) / 2;
return median;
}
static double GetMedian(ArrayList pNumbers)
{
return GetMedian((int[])pNumbers.ToArray(typeof(int)));
}
}
}

Mar 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PhilC | last post by:
Hi Folks, If I have an array holding a pair of numbers, and that pairing is unique, is there a way that I can find the array index number for that pair? Thanks, PhilC
2
by: Bob | last post by:
I have been looking at the code for MedianFind(pDte As String) from the following thread from UtterAccess.com: "Finding Median average grouped by field" I have been able to get it to run using...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
5
by: zfareed | last post by:
I created a program to determine the medians of arrays, be it of type int or float. I have used a template function and the problem I'm having is returning the float median for even arrays. Can...
16
by: ronaldchua | last post by:
Hi ppl, I'm very new to coding in Access and my task now involves finding median values for all Areas, given a table with "Area", "Units Sold" and "Price" Example: "Area" "Units...
3
by: mehwishobaid | last post by:
i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include...
13
by: pereges | last post by:
I've an array : {100,20, -45 -345, -2 120, 64, 99, 20, 15, 0, 1, 25} I want to split it into two different arrays such that every number <= 50 goes into left array and every number 50 goes...
1
by: Richard Harter | last post by:
On Fri, 27 Jun 2008 09:28:56 -0700 (PDT), pereges <Broli00@gmail.comwrote: There are some obvious questions that should be asked, e.g., is the contents of your array already sorted as your...
3
by: utab | last post by:
Dear all, I have the below template (1) which I would like to implement to accept either a vector or an array. I thought on it some time and came with a solution as in (2) , however the call of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.