Back to Freecodecamp

Step 8

curriculum/challenges/english/blocks/learn-tree-traversal-by-building-a-binary-search-tree/65c4f0d32ca17ad4b1636b0e.md

latest1.0 KB
Original Source

--description--

Inside the __init__ method, delete pass and initialize root to the value None.

The root attribute represents the root node of the binary search tree. Since this is the constructor when a new BinarySearchTree object is created, it starts with an empty tree, so the root attribute is set to None.

--hints--

You should remove the pass statement from the __init__ method.

js
({
  test: () => {
    const pyClassStr = runPython(
      `str(_Node(_code).find_class("BinarySearchTree"))`
    );
    assert.notInclude(pyClassStr, "pass");
  },
});

You should initialize the root attribute to None using self.root.

js
({ test: () => assert.match(code, /^\s{8}self\.root\s*=\s*None/m) })

--seed--

--seed-contents--

py
class TreeNode:
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
--fcc-editable-region--
class BinarySearchTree:
    def __init__(self):
        pass
--fcc-editable-region--