Relative Content

Tag Archive for efficiency

Fastest way to determine if a value is in a list?

I’m aware there may not be a good solution to this problem. I’m looking for a fast algorithm that determines whether or not a value (let’s say an integer) exists in a set of values, however I need the algorithm to also be fast if the value is not in the set. I.e.: Most methods I can think of right now that determine if a value is in a list will take longer to determine that it is not as they will not exit early.

Fastest way to determine if a value is in a list?

I’m aware there may not be a good solution to this problem. I’m looking for a fast algorithm that determines whether or not a value (let’s say an integer) exists in a set of values, however I need the algorithm to also be fast if the value is not in the set. I.e.: Most methods I can think of right now that determine if a value is in a list will take longer to determine that it is not as they will not exit early.

How does modulus work?

I am not asking asking how the mathematical concept of modulus works, or how 20 % 3 == 2 I understand this fine. I’m more curious how the compiler/interpreter determines this. I can think of a very naive way to do it, like so:

Is there any technical reason to be concerned with casting speed?

So, I’m working on a project that takes a very complex entity from a third party framework and converts it into the native object that defines that entity. This entity has several one-to-many relationships, and a few of those have some one-to-many relationships. I’ve often been told nested loops are the worst, just absolute worst, as far as efficiency is concerned, but I really can’t help it in this situation, as I’m working on a base object that’s not going to change just to please me. The upshot to this, is this conversion only happens once per entity.