Complete the code to traverse the left subtree first in postorder traversal.
function postorder(node) {
if (node === null) return;
postorder(node.[1]);
// Continue traversal
}In postorder traversal, we visit the left subtree first, so we call postorder(node.left).
Complete the code to traverse the right subtree second in postorder traversal.
function postorder(node) {
if (node === null) return;
postorder(node.left);
postorder(node.[1]);
// Continue traversal
}In postorder traversal, after the left subtree, we visit the right subtree by calling postorder(node.right).
Fix the error in the code to visit the root node last in postorder traversal.
function postorder(node) {
if (node === null) return;
postorder(node.left);
postorder(node.right);
console.log(node.[1]);
}We print the value of the node after visiting left and right subtrees in postorder traversal.
Fill both blanks to complete the recursive postorder traversal function.
function postorder(node) {
if (node === null) return;
postorder(node.[1]);
postorder(node.[2]);
console.log(node.value);
}Postorder traversal visits the left subtree, then the right subtree, and finally the root node.
Fill all three blanks to create a postorder traversal that collects values in an array.
function postorder(node, result) {
if (node === null) return;
postorder(node.[1], result);
postorder(node.[2], result);
result.[3](node.value);
}We recursively visit left and right subtrees, then add the node's value to the result array using push.