
Problem
Solution
Submissions
Binary Tree Traversals
Certification: Advanced Level
Accuracy: 33.33%
Submissions: 6
Points: 15
ite a Python function that performs inorder, preorder, and postorder traversal of a binary tree. Each traversal should return a list of node values in the order they are visited.
Example 1
- Input:
[1,null,2,3]
Tree: - Output:
Inorder: [1, 3, 2]
Preorder: [1, 2, 3]
Postorder: [3, 2, 1]
Example 2
- Input:
[1,2,3,4,5]
Tree: - Output:
Inorder: [4, 2, 5, 1, 3]
Preorder: [1, 2, 4, 5, 3]
Postorder: [4, 5, 2, 3, 1]
Constraints
- 0 ≤ nodes ≤ 100
- -100 ≤ Node.val ≤ 100
- Time Complexity: O(n)
- Space Complexity: O(h)
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use recursive approach for simplicity
- Inorder: left subtree, current node, right subtree
- Preorder: current node, left subtree, right subtree
- Postorder: left subtree, right subtree, current node
- Can be implemented iteratively using a stack for O(1) space complexity