Difficult computer science problem
-
it was a pseudo code...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
why does that matter? the original post said "no arrays".
-
why does that matter? the original post said "no arrays".
because even if "iterate" is not the correct word, he can still traverse the array he'd have built...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
because even if "iterate" is not the correct word, he can still traverse the array he'd have built...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
:~ sorry, don't get you...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
while number received != -1
store the number
end while
calculate the average
iterate through the array constructed below
if number in the iteration is above the average
increment counter
end if
end iterationsbut the question is, WHY don't you want to use the STL ?? managing your own memory with such growing arrays are not good things to do by yourself...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
toxcct wrote:
store the number
To what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
:~ sorry, don't get you...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
toxcct wrote:
store the number
To what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
to the paper next to the keyboard...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
While you can certainly compute the average without any additional storage, you'd still need to be able to go back through the set of numbers to pick out those greater than the average. Just for our edificaton, why the restriction? Is this your post, too?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
You just can't use arrays! You have no array at the beggining, the user writes for you the input number by number-NO ARRAYS!
SnaidiS(Semion)
WTF !! even if you had a console program, by which the user typed all the values in a single line, you could still create an array (or an STL container), parse the string to extract the values, and store them then... if you don't explain your problem exactly, how can we guess what you're doing ? :confused:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
WTF !! even if you had a console program, by which the user typed all the values in a single line, you could still create an array (or an STL container), parse the string to extract the values, and store them then... if you don't explain your problem exactly, how can we guess what you're doing ? :confused:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
to the paper next to the keyboard...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
That'll work! It satisfies the requirements of not using a list, array, etc. :-D
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
the problem says that you mustn't use arrays or other allocation of memory.
SnaidiS(Semion)
then, no chance to resolve it ;P
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
So what kind of storage are you allowed to use?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
So what kind of storage are you allowed to use?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
then, no chance to resolve it ;P
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
You say that there is no chanse to resolve it so can you prove it mathematiclly?
SnaidiS(Semion)
i'm tired with your thread... go find someone else to bore
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
-
Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?
led mike
missing something calculating the average "on the run" is easy to do with a float and an integer. but to tell how many of the inputs were upper than the average... no chance if you don't store the datas...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Does anyone know an algorithm that recieves an unknown amount of numbers(it stops when it recieves -1) and calculates how many of them are above the average without using an array, list, vector, stack, file ect.? Is it even possible?
SnaidiS(Semion)
it's not possible; as soon as you receive a new number the average will be modified, and since you cannot keep an history of the values already read, there is no way of determining what numbers that you already read that are above or below the average. (unproven, and unverified ) The problem with the average is that you can have a new value that will completly "unbalance" the computed average, for example you have a series of values in the [1, 10] range, the average will be between those 2 values, but if at some point you have a very large value, it will mess the result, and statistically the result will not be valid, unless you can filter out those bad values. ( but I expect someone to come with a brilliant mathematical answer that will awe us )
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Can't you keep a running total and the number of inputs in two variables. Then you can calculate the average and of course half the number of variables is above the average. Or am I missing something?
led mike
led mike wrote:
...of course half the number of variables is above the average. Or am I missing something?
That outliers can skew things quite a bit. Given the set {1, 2, 5, 7, 10, 18}, the average is 7.1. Four numbers in the set are below this, and two numbers are above.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb