@nakurapad In my opinion, the time complexity of the solution is O(n), where n is the number of nodes in the tree which we visit once. Also, the space complexity is O(n) due to the recursive stack being used.
@xuanyige Agree!! But level order transversal is general explanation. In my opinion, preorder DFS should transverse node itself first, than left node, then right node. But this code shows that the priority of the left node and right node are the same. So, this will not be a strictly defined DFS in my opinion.
Thank you very much for your explanation. I'm learning Algorithm in Python. Recently I'm starting learning binary tree. I know the function definition, but I have no idea about class. This is the thing I need to learn. I don't know when I should use class. In my previous coding for list and array, I never see this kind of format like "self.function". That's why I think it should be like this without self.
if not root: