Complete the code to print the root node's value first in preorder traversal.
def preorder(node): if node is None: return print(node[1]) preorder(node.left) preorder(node.right)
The root node's value is accessed using .value. This prints the root first in preorder traversal.
Complete the code to recursively traverse the left subtree in preorder.
def preorder(node): if node is None: return print(node.value) preorder(node[1]) preorder(node.right)
In preorder traversal, after the root, we visit the left subtree first using node.left.
Fix the error in the code to correctly traverse the right subtree in preorder.
def preorder(node): if node is None: return print(node.value) preorder(node.left) preorder(node[1])
The right subtree is traversed by calling preorder(node.right) after the left subtree.
Fill both blanks to complete the preorder traversal function that prints root, left, then right.
def preorder(node): if node is None: return print(node[1]) preorder(node[2]) preorder(node.right)
First print the root's value with .value, then recursively traverse the left subtree with .left.
Fill all three blanks to complete the preorder traversal that prints root, left subtree, then right subtree.
def preorder(node): if node is None: return print(node[1]) preorder(node[2]) preorder(node[3])
Print the root's value, then recursively traverse the left subtree, then the right subtree.
