Why it is faster to search data using hash table? Because hash function converts string keys to integer keys, but integer numbers can be sorted making search faster?
For example I have associative array:
array
(
[str.key1] => value1
[str.key2] => value2
[str.key3] => value3
[str.key4] => value4
);
So to find value3 by using str.key3, it is necessary to run over all str.keys to compare, and therefore search has complexity O(n). But if I hash every str.key I receive numbers:
array
(
[5] => value1
[2] => value2
[7] => value3
[3] => value4
);
then occur sorting:
array
(
[2] => value1
[3] => value2
[5] => value3
[7] => value4
);
And therefore it is faster to find value. Do I understand correctly?