0
0
DSA Javascriptprogramming~10 mins

Tree Traversal Postorder Left Right Root in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to traverse the left subtree first in postorder traversal.

DSA Javascript
function postorder(node) {
  if (node === null) return;
  postorder(node.[1]);
  // Continue traversal
}
Drag options to blanks, or click blank then click option'
Aparent
Bright
Croot
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' for the first recursive call.
Trying to access a non-existent 'parent' property.
2fill in blank
medium

Complete the code to traverse the right subtree second in postorder traversal.

DSA Javascript
function postorder(node) {
  if (node === null) return;
  postorder(node.left);
  postorder(node.[1]);
  // Continue traversal
}
Drag options to blanks, or click blank then click option'
Aright
Bparent
Cchild
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' or 'parent' instead of 'right'.
Skipping the right subtree traversal.
3fill in blank
hard

Fix the error in the code to visit the root node last in postorder traversal.

DSA Javascript
function postorder(node) {
  if (node === null) return;
  postorder(node.left);
  postorder(node.right);
  console.log(node.[1]);
}
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cvalue
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Printing 'left' or 'right' instead of the node's value.
Printing before traversing subtrees.
4fill in blank
hard

Fill both blanks to complete the recursive postorder traversal function.

DSA Javascript
function postorder(node) {
  if (node === null) return;
  postorder(node.[1]);
  postorder(node.[2]);
  console.log(node.value);
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cparent
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right.
Using non-existent properties like 'parent' or 'child'.
5fill in blank
hard

Fill all three blanks to create a postorder traversal that collects values in an array.

DSA Javascript
function postorder(node, result) {
  if (node === null) return;
  postorder(node.[1], result);
  postorder(node.[2], result);
  result.[3](node.value);
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cpush
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' instead of 'push' to add values.
Mixing up left and right children.