Page 1 of 1
Computation of the mid point in fork/join
Posted: Thu Jun 30, 2016 2:57 pm
by johnlong
About Question enthuware.ocpjp.v8.2.1271 :
Hello
The logic for computing mid should be such that it divides the task into two equal parts in terms of cost of computation.
How can you know in advance cost of computation?
For example we've got Collection of Integers, and computation is required.
How can we know beforehand how to split Collection so it would be divided into two equal parts (in terms of computation cost)?
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Thu Jun 30, 2016 8:52 pm
by admin
It is a guideline to make optimum use of the fork/join framework, not an inviolable rule. You can subdivide the tasks into lopsided groups but that won't be very efficient good.
In many cases, the cost of computation is same for each element so you just split the tasks in half.
If you cannot figure out the cost of computation, you can take an educated guess. There is no other way.
-Paul.
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Mon Jul 04, 2016 6:50 pm
by johnlong
Then, correct answer does not make sense.
As it is not possible find out mid in terms of computation cost, we just split in the middle of collection.
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Mon Jul 04, 2016 8:35 pm
by admin
It is indeed possible (may be not always, depends on the problem domain) to find out mid in terms of computation costs. The fact that it might be same as the midpoint of the collection is irrelevant. You should go by the computation cost, if you can't do that then the mid point of the collection is no better guess than any other point in the collection.
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Tue Jul 05, 2016 7:39 pm
by johnlong
For example for given array of Integers how will you find mid of computation cost?
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Wed Jul 06, 2016 12:09 am
by admin
I already mentioned that. It depends on what you want to do with them that matters. For example, if you want to compute the square of the numbers, mid point of the list is same as mid point from computational perspective.
-Paul.
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Wed Jul 06, 2016 5:28 pm
by johnlong
But computation cost for square of 2 and square of 20 is not the same.
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Wed Jul 06, 2016 6:35 pm
by admin
1. Why do you think computing x*x will be different for two different integers?
2. You can pick another example. How about 2*x? Or how about checking whether the number is odd or even?
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Sat Jul 09, 2016 8:42 pm
by johnlong
Computing 2 x 2 and 20 x 20 would cost the same?
Re: About Question enthuware.ocpjp.v8.2.1271 :
Posted: Sat Jul 09, 2016 8:54 pm
by admin
Why would it be different?? It is the same instruction for both i*i. But again, it doesn't matter. What if your computation involves multiplying each by a constant number?
If you do not agree with this, I would suggest you to take a second opinion from another website such as JavaRanch or StackOverflow.
I think this discussion is getting diverted away from the exam perspective and is not too useful. So I am separating it from the main thread.
thank you,
Paul.