views:

65

answers:

1

Its just a question out of curiosity. Suppose we have an associative array A. How is A["hello"] actually evaluated , as in how does system map to a memory location using index "hello"?

+3  A: 

Typically it uses a data structure that facilitates quick lookup in mostly constant time.

One such typical approach is to use a hashtable, where the key ("hello" in your case) would be hashed, and by that I mean that a number is calculated from it. This number is then used as an index into an array, and in the element with that index, the value exists.

Different data structures exists, like binary trees, tries, etc.

You can google for keywords: hashtable, binary tree, trie.

Lasse V. Karlsen
Got it! Thanks!
Carlin