Reputation: 1
I am fairly new to dynamic programming, i have seen people, memoize in javascript using objects. But i would like to know what will be the most efficient way to memoize in c++. Which data structure should i use, is map good? orr is there something better, please let me know.
Upvotes: 0
Views: 326
Reputation: 880
I think you should use unordered_map instead of map.
The reason is that the time complexity for the search operation are as follow:
The reason is that unordered_map works as a hash table while map works as a binary tree.
Similarly, you can also use unordered_set instead of set for the same reason:
The time complexity for the search operation are as follow:
Upvotes: 2