Here a map <T, bool>
has been used to keep track of visited nodes. Can an unordered_set<T>
be used instead? Or does using a map has some other significance?
Can we use a set to store the visited nodes?
map is east to handle and more efficent
to check whethe a node is visited or not you have to just write
if( m[node]){}
but in case of set you have to search to all examplesusing
s.find(node)
yes for unordered_set it is O(1)
use can use set
but map is in more practice by people
1 Like