What is the time complexity for looking up an item in a Perl hash? -
suppose have file n words. read each word in file, store in hash (in perl). when go , word in hash, time complexity of looking string(word) in hash?
for example:
my %seen = (); @arr=("one","two","three"); foreach $item (@arr){ if($seen{$item}) {//do something} }
in program, looking item in hash. time complexity of looking string in hash?
also, elaborate on how hash implemented in perl? (internally happens in hash? or associative array)
perl hashes provide constant-time lookups. implemented true hash tables (with automatic retuning necessary), not associative arrays.
Comments
Post a Comment