How do Python dictionary lookup algorithms work internally?
mydi[\'foo\']
If the dictionary has 1,000,000 terms, is a tree search execut
Answer 1: Internal working is explained in this video
Answer 2: No, a tree search is not done if you have a million records in a dictionary.
Answer 3: As there might be key collisions you will expect performance in terms of the size of the dictionary, and not in terms of the length of the key string.
Answer 4: Consider the dictionary as an array (contiguous memory locations), but there might be blocks within the array which are not used. Hence, dictionaries tend to waste a lot of memory space as compared to trees. But, for better run-time performance dictionaries might be better than trees. Key collisions can sometime degrade performance. You should read about Consistent Hashing.