Embercode
✕
Binary TreesQuick quiz

Serialize round trips

7 questions. Covers Serialize and deserialize a binary tree in Python.

Questions 1 to 5 of 7

  1. 1. The serialize function from this lesson runs on this tree. What does it print? ``python tree = TreeNode(5, TreeNode(3, None, TreeNode(4)), TreeNode(8)) print(serialize(tree)) ``
  2. 2. The read_preorder function from this lesson runs on the words below and then prints two lines. What is the second line? ``python from collections import deque tokens = deque('1,2,null,null,3,null,null,9'.split(',')) root = read_preorder(tokens) print(f'root {root.val}, right {root.right.val}') print(f'words left: {len(tokens)}, first left: {tokens[0]}') ``
  3. 3. Why does the writer add the word null for an empty tree, instead of writing an empty string?
  4. 4. A tree has 9 real nodes. How many null words does its serialized text contain?
  5. 5. This reader has the check for the word null removed. It is given the words of 1,2,null,null,3,null,null. What happens? ``python def read_preorder(tokens): token = tokens.popleft() node = TreeNode(int(token)) node.left = read_preorder(tokens) node.right = read_preorder(tokens) return node ``

5 question(s) left on this page.