educative.io

BST example is broken

Hi, I think the question with BST is misleading. You can’t assign a value to root parameter like this. Java is pass-by-value. It will have no effect.

B)
if (root == null)   {    root = newTreeNode(data);    return;  }

Type your question above this line.

Course: https://www.educative.io/collection/10370001/5996180548878336
Lesson: https://www.educative.io/collection/page/10370001/5996180548878336/4903821299941376

Hello @Jan_Verner

Basically, this is the base case of the insert function of BST. This case is only be executed if the root is null. And Yes, you are right that java is a pass-by-value. But the variable data contains the value that is assigned to the newTreeNode(data) when this case is executed. Also, if we call the insert function multiple times, this case will be true or executed only once.

I hope I have answered your query; please let me know if you still have any confusion.

Thank You :blush: