-1

I am trying to write code for a binary search tree that has some basic functions. I am just having trouble with what an empty tree would look like. I know that with a linked list that there is a head that points to a nullptr. But since a binary search tree's root is an actual node, what value will be held in the root?

Gray
  • 7,050
  • 2
  • 29
  • 52
Suede
  • 416
  • 2
  • 5
  • 16

2 Answers2

0

That depends on your tree implementation, but usually if the root itself is an empty node (e.g. nullptr) then it's an empty tree. If your root doesn't have a value even if the tree is non-empty, then look for the left and right child instead. But as said, you should know that already since it's your implementation, I guess. And if not, the type surely has an is_empty() method.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

An empty tree is the exact same as no tree at all. see here

Programmatically spoken, the pointer itself that would generally hold the address of the trees root element is null.

Community
  • 1
  • 1
user2900170
  • 75
  • 2
  • 5