In BFS, you typically have something like
while q:
popped_node = q.popleft()
res.append(do_work(popped_node))
for child in popped_node.children:
q.append(child)
return res
But say for some reason you needed to iterate over the children in order based on some key, so you would have
while q:
popped_node = q.popleft()
res.append(do_work(popped_node))
for child in sorted(popped_node.children, key=lambda x: x._id):
q.append(child)
return res
Typically the time complexity of BFS is O(N), number of nodes. How does adding this sorting portion affect the time complexity?