Accessing array information
-
Let’s say I have an array of 1000 variables and each one of them is a set of 2 random numbers
Example
Var[0] = {563,228}
Var[1] = {1145,105}
Var[2] = {3,447}
And so onHow can I see if there’s a variable with a specific set of numbers without checking them all?
-
If the numbers are stored in a simple array as you have described you would have to just check them all.
However it is possible to build a fast look up table that can find the variable with a set of numbers without looking at them all.
https://en.wikipedia.org/wiki/Hash_tableIt is even possible to go a step further. At the cost of false positives you can use a bloom filter that can check to see if a set of numbers is present without actually storing all of them in a table thus saving time and memory.
https://en.wikipedia.org/wiki/Bloom_filter -
Very interesting topic! I'm used to simply using Java's HashMap object which implements things for you. I've always been curious about how to implement the same thing in cases where this isn't a built-in feature of a language.