Binary Tree Inorder Traversal
Given the root of a binary tree, return the inorder traversal of its nodes' values.
Solution
Time Complexity: The time complexity of this algorithm is O(n), where n is the number of nodes in the binary tree. This is because the algorithm visits each node twice: once when it first reaches the node and again when it returns to the node after visiting its left subtree.
Space Complexity: The space complexity of this algorithm is O(1), because it doesn't use any additional data structures, such as a stack or a queue, to perform the traversal. The only additional space used by the algorithm is the constant amount of space required for the
currandprevpointers and theanslist to store the result.
Last updated