I understand that the runtime of BFS and DFS on the general graph is O (n + m), where n is the number of nodes and m is the number of edges, and this is because for each node its adjacency list should be considered. However, what is the BFS and DFS runtime environment when it runs on a binary tree? I believe this should be O (n), because the possible number of edges that can exit the node is constant (i.e. 2). Please confirm if this is correct. If not, then please explain what is the correct time complexity of BFS and DFS on a binary tree?
algorithm time-complexity breadth-first-search depth-first-search binary-tree
gmemon
source share