The Code Marathon. (1 Viewer)

InteGrand

Well-Known Member
Joined
Dec 11, 2014
Messages
6,109
Gender
Male
HSC
N/A
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
Joined
May 12, 2013
Messages
2,810
Gender
Female
HSC
2015
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
Joined
May 29, 2013
Messages
3,910
Gender
Undisclosed
HSC
2015
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
Joined
May 28, 2014
Messages
3,657
Gender
Undisclosed
HSC
2015
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
Joined
May 29, 2013
Messages
3,910
Gender
Undisclosed
HSC
2015
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
Joined
May 29, 2013
Messages
3,910
Gender
Undisclosed
HSC
2015
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
Joined
Dec 18, 2010
Messages
6,960
Gender
Female
HSC
N/A
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.
 

SpiralFlex

Well-Known Member
Joined
Dec 18, 2010
Messages
6,960
Gender
Female
HSC
N/A
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
Joined
Oct 31, 2015
Messages
1,016
Location
Sydney
Gender
Male
HSC
2016
Unless your sorting algorithm is better than O(nlogn) you're better off using Arrays#sort (in Java, at least) :p
 

turntaker

Well-Known Member
Joined
May 29, 2013
Messages
3,910
Gender
Undisclosed
HSC
2015
Unless your sorting algorithm is better than O(nlogn) you're better off using Array#sort (in Java, at least) :p
yea, but I think thats kinda cheating lol (since C probably doesn't have a method that sorts)
 

turntaker

Well-Known Member
Joined
May 29, 2013
Messages
3,910
Gender
Undisclosed
HSC
2015
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
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top