Computation of the mid point in fork/join

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Computation of the mid point in fork/join

Post 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)?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post by johnlong »

For example for given array of Integers how will you find mid of computation cost?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post by johnlong »

But computation cost for square of 2 and square of 20 is not the same.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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?

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post by johnlong »

Computing 2 x 2 and 20 x 20 would cost the same?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1271 :

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests