# The Code Marathon. (1 Viewer)

#### SpiralFlex

##### Well-Known Member
my array is not sorted
You're solution assumes the middle elements (averaged) is the median, this is not the median.

#### turntaker

##### Well-Known Member
You're solution assumes the middle elements (averaged) is the median, this is not the median.
What is the median

#### InteGrand

##### Well-Known Member
Median means middle when the array is sorted so the numbers are in ascending order (taking average of two middle I case of even no. of elements).

E.g. What is the median of 2,6,2,8,7? When sorted, the numbers are 2,2,6,7,8, so the median is 6 (middle number).

( https://www.mathsisfun.com/median.html )

Last edited:

#### Flop21

##### Well-Known Member
what does unsorted mean

also I don't understand your given question
You are confused by 'linked lists'? Or something else? Because it's understandable if you're confused with linked lists if you haven't been taught that concept yet.

It's a way of storing data, you point to a 'node' which stores the value and the pointer to the next node... so on until it reaches the end (points to nothing/NULL).

#### turntaker

##### Well-Known Member
Median means middle when the array is sorted so the numbers are in ascending order (taking average of two middle I case of even no. of elements).
Ah ok, so i just need to sort my array and then find the average of the two middle numbers?

#### Drsoccerball

##### Well-Known Member
I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)

#### turntaker

##### Well-Known Member
You are confused by 'linked lists'? Or something else? Because it's understandable if you're confused with linked lists if you haven't been taught that concept yet.

It's a way of storing data, you point to a 'node' which stores the value and the pointer to the next node... so on until it reaches the end (points to nothing/NULL).
yeah I haven't done Linked lists yet

#### turntaker

##### Well-Known Member
I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)
use a sorting algorithm

#### SpiralFlex

##### Well-Known Member
I have a solution but its wayyyyyyyy to long. It involves sorting the array an then finding the middle term. (I havn't done sorting before so maybe thats why im so bad at it)
That's understandable sorting is 2nd semester work. This is a solution, however this isn't the optimal one.

#### Drsoccerball

##### Well-Known Member
That's understandable sorting is 2nd semester work. This is a solution, however this isn't the optimal one.
Is there a simple 1st sem solution

#### SpiralFlex

##### Well-Known Member
Is there a simple 1st sem solution
The naive solution most 1917 student's would give would probably be sort it then take the median as you are doing. Just bare in mind in computing it is never the first solution that comes in mind that is the most efficient, you will learn this if you take further comp courses in unsw.

#### KingOfActing

##### lukewarm mess
Unless your sorting algorithm is better than O(nlogn) you're better off using Arrays#sort (in Java, at least)

#### turntaker

##### Well-Known Member
How is this related?
he probably implies that I may have covered sorting algorithms, which I have.

#### turntaker

##### Well-Known Member
Unless your sorting algorithm is better than O(nlogn) you're better off using Array#sort (in Java, at least)
yea, but I think thats kinda cheating lol (since C probably doesn't have a method that sorts)

#### turntaker

##### Well-Known Member
Alright I should take a break from this since I have an exam tomorrow and I haven't really studied for it.
But I will be back after exams

#### KingOfActing

##### lukewarm mess
yea, but I think thats kinda cheating lol (since C probably doesn't have a method that sorts)
Why rewrite code that already exists? Besides, C has qsort that's basically the same thing

#### turntaker

##### Well-Known Member
Why rewrite code that already exists? Besides, C has qsort that's basically the same thing
On yeah true haha

#### porcupinetree

##### not actually a porcupine
Ooooh this is a good idea for a thread