Skip to content
Advertisement

Tag: optimization

Is JVM or JIT able to reduce duplicate method calls?

I have a function that checks if a map has some value for key (map.get(key) != null) and then returns the value, or else create new value. I’m wondering is there any JVM or JIT magic that doesn’t have to do 2 map lookups when the value exists for the given key? According to my benchmark, it seems no optimisation

Using Knapsack approach without value?

Regarding to question, I am wondering that according to the following approach: Assume that there is no value and I am wondering that which approach or algorithm should be used for a Knapsack problem when the values are equal and there is a parameter (called n) that describes times for carrying items in a time? For example, the bag has

How do I count numbers that contain one digit, but not another?

I recently came across an interview question which although had an immediately obvious solution, I struggled to find a more efficient one. The actual question involved counting numbers from a to b (up to 2^64) which satisfied having either the digit 6 or 8, but not both. They called it a ‘lucky number’. So for example: The obvious thought was

For loop inside for loops code optimisation

I have an loop inside loop to remove the elements from the seconde loop, and what is present in the list has to perform certain actions. I wish to optimize the iteration and comparisons, can it be done? How do I optimize my logic shown below to avoid so many lines of code Answer After minLenghtOfEntities += field.getFieldLength(); a break

How can this Java tree be 1000 x faster?

I am programming an AI for a chess-like game, based on two types of pieces on a 8 x 8 grid. I want to build a kind of minmax tree, which represents each possible move in a game, played by white players in first, and by black players in second. I have this generate() method which is call recursively. I

Advertisement