Complete the code to visit the left subtree first in postorder traversal.
void PostorderTraversal(Node node) {
if (node == null) return;
PostorderTraversal(node.[1]);
// Continue traversal
}In postorder traversal, we visit the left child first.
Complete the code to visit the right subtree second in postorder traversal.
void PostorderTraversal(Node node) {
if (node == null) return;
PostorderTraversal(node.left);
PostorderTraversal(node.[1]);
// Continue traversal
}In postorder traversal, after the left subtree, we visit the right subtree.
Fix the error in the code to print the node value after visiting left and right subtrees.
void PostorderTraversal(Node node) {
if (node == null) return;
PostorderTraversal(node.left);
PostorderTraversal(node.right);
Console.[1](node.value);
}Use Console.WriteLine to print the node value on its own line.
Fill both blanks to complete the recursive postorder traversal method.
void PostorderTraversal(Node node) {
if (node == null) return;
PostorderTraversal(node.[1]);
PostorderTraversal(node.[2]);
Console.WriteLine(node.value);
}Postorder visits left subtree, then right subtree, then the node itself.
Fill all three blanks to create a dictionary mapping node values to their postorder index.
Dictionary<int, int> postorderIndex = new Dictionary<int, int>(); int index = 0; void PostorderTraversal(Node node) { if (node == null) return; PostorderTraversal(node.[1]); PostorderTraversal(node.[2]); postorderIndex[node.[3]] = index++; }
Traverse left and right children, then store the node's value with its postorder index.
