Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.

Get a Professional Answer

Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.

100% Satisfaction Guarantee

Rate the answer you receive.

Ask Leela-TheProgrammer Your Own Question

Leela-TheProgrammer, Computer Software Engineer

Category: Programming

Satisfied Customers: 474

Experience: Post Grad in CS (Gold Medal)

21067471

Type Your Programming Question Here...

Leela-TheProgrammer is online now

TheProgrammer Only. sorry I need your help again, yesterday

Customer Question

For Leela-TheProgrammer Only. Hi, sorry I need your help again, yesterday I asked to help for fixing my program, and you replied me that you are able to do this. I need someone help me to fix the program, It runs fine but looks like there are some logical program to the calculation of sorting the latitude and longitude. The purpose of the program is given n and the location of each store in terms of latitude and longitude, then report the closest pair of stores(in alphabetical order) and the distance between them to the nearest 0.1km. But when I test the program with a very large number of n, It will promote a OutOfMemoryError: Java heap space, and I also keep getting a wrong answer from other test cases as well, so I think the issue must related to the latitude and longitude. I've been told that the latitude is unique in the range [-90,90] degrees but -180 and 180 longitude are the same, so I was suggested that I should think hard about which to map to which of the planar coordinates as in class, but I've no idea what is this exactly meaning, I am assuming it have to do with the fact that if i have a point on the very left edge and one on the right edge then they could also be candidates. I was also suggested that try to think about slicing it by latitude or longitude. With one I have to worry about the poles and having 2 connected points for the first cut. Now I've another new problem which is my program will throw a NumberFormatException when the cities have two words (e.g. "New York", "San Antonio") I've attached a small test case which is the sample input and output, another one is a sample input test case which contain "two words city", and also a large test case which is the one that cause a OutOfMemoryError to my program... Can you help me with this please ? Thank you

Submitted: 1 year ago.

Category: Programming

Share this conversation

Customer:replied 1 year ago.

Update: Hi, the "wrong answer" problem has been resolved, so please ignore it. The only problem in the program is the OutOfMemoryError: Java heap space error...and I still cannot find out a solution...

Hello Leela,I have some extra information here, which for avoiding the TimeLimitExceeded when you modifying the program:Rather than caching the distance calculation, cache some of the intermediate terms that will get reused for many distances (e.g. the sine and cosine of the latitude). Also store everything in radians will be an option. But, moreover: An efficient algorithm will minimise the total number of calls to the distance method, i.e. it will calculate as few distances as possible while still guaranteeing a correct result. That is, after all, why divide-and-conquer algorithm are recommended for this problem. See if there is still room for improvement in the implementation. Make sure you are not using the distance method to construct the strip of points within delta or the boxes.Hope that help, thank you.

The error you have reported is "OutOfMemoryError: Java heap space error", most of the time this has nothing to do with program (unless there is lot of memory leaks), this problem is related to JVM heap space. This is fixed by setting proper heap space while starting the program.

We can set JVM heapspace as follows:

-Xmx2048m

Add the -Xmx to the java command you are running and let me know how things go.

If needed we can do a quick remote session so that I can check how you are running the program and also help you change JVM heap settings.