java - Cost of merging two hashmaps -


let's have 2 hashmaps follow

hashmap<character, integer> map1 = new hashmap<character, integer>(); hashmap<character, integer> map2 = new hashmap<character, integer>(); 

now want merge these 2 , put them hashmap map3

what best way in terms of asymptotic complexity.

in terms of asymptotic complexity means creating new map , adding elements of each map it. t(insertion) * (m + n) (i won't reveal answer in case homework!). java hash map no more efficient text book hash map, there no shortcuts there. finally, if can arbitrarily modify either 1 of 2 maps, recommend merging smaller larger. save time spent iterating through large map , might save time spent in memory allocation.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -