r/AskComputerScience • u/likejudo BSCS • Nov 25 '24
Binary Search Trees: Are the leaves nodes or NULL pointers in the parent node?
Let's say this is 19 and let's say here it has to be greater than 20, less than 25, let's say 23, 21, 24 greater than 20 but less than equal to 25. Let's say 29, 31, and then let's say nil, nil, nil, nil, nil, nil, nil, nil those are going to be the leaves. I will still soon stop writing these leaves, but for now I will write these leaves.
I am doing the CU-Boulder Coursera course on Trees and Graphs.
It is confusing why he is referring to the leaves as NIL.
Are the leaves nodes or NULL pointers in the parent node?
see screenshot here https://imgur.com/a/fkkQ4OK
Edit: Unfortunately, the course as with Coursera courses is abandoned and instructors do not reply in the discussion forums. Hence I am posting here. Thanks to all for your help.
2
u/[deleted] Nov 25 '24
Nil is another word for null
It might be helpful to treat null values as a placeholder value. "MinValue" should be sufficient for sorting purposes.
These values will likely end up being a leaf.
1
u/johndcochran Nov 25 '24 edited Nov 25 '24
Consider the following code:
vs
In the above code, does one of them consider a pointer value of NULL to indicate that it's pointing to a NIL leaf, or does it consider a value of NULL to mean that there's no leaf? Is one version of print_tree more efficient than the other? Is one of them clearer than the other? Do both questions about efficiency or better have the same function as the answer?