Congratulations! You have built an entire B-Tree from scratch!

To review, we have implemented the following methods in BTree and BTreeNode classes:

  • split()
  • _is_leaf()
  • _is_full()
  • add_key()
  • add_child()
  • find_correct_child_node()
  • insert()
  • search()


Your fully functioning B-Tree code is in the code editor. Feel free to create your own B-Trees and practice using the methods.

For some guidance, here are some ways you can play around with the code:

btree = BTree(3) btree.insert(2) btree.insert(3) btree.insert(4) btree.insert(5) btree.insert(6) btree.insert(1) print(btree.root.keys) print(btree.root.children) print(btree.search(2))

Alternative way:

node1 = BTreeNode(5) node1.keys = [1, 4, 29] node2 = BTreeNode(5) node2.keys = [2,3] node3 = BTreeNode(5) node3.keys = [5,6] node1.children = [node2, node3] node4 = BTreeNode(5) node4.keys = [30] node1.add_child(node4)

Feel free to try out both of these code blocks and get creative. Happy coding!

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?