Computation of the mid point in fork/join
Moderator: admin
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Computation of the mid point in fork/join
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)?
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)?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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.
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.
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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.
As it is not possible find out mid in terms of computation cost, we just split in the middle of collection.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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.
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
For example for given array of Integers how will you find mid of computation cost?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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.
-Paul.
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
But computation cost for square of 2 and square of 20 is not the same.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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?
2. You can pick another example. How about 2*x? Or how about checking whether the number is odd or even?
-
- Posts: 197
- Joined: Mon Jun 20, 2016 5:06 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
Computing 2 x 2 and 20 x 20 would cost the same?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1271 :
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.
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.
Who is online
Users browsing this forum: No registered users and 4 guests