OK, let's find out whether a binary tree's depth of search is typically log2(N).
Example: if you have a tiny 3-element binary tree with root = 5, left child = 7 and right child = 3,
then has_depth(5) -> 1, has_depth(7) -> 2 and has_depth(20) -> 2
Example: if the input file contains the following 2 lines:
5,2,4,2,10,8,1,16,5,1 4,8,7,5,16,1,9,2,10Process() should yield the following line that it will write to the output file (verify this):
3,3,3,1,3,3,3,2,2If, instead, you get the following output, then the error is that you have not converted the string versions of the input numbers to integers, but left tham as strings:
3,2,2,1,4,4,2,2,3
Along the way, let's test the log2ishness of this algorithm. Find the average of the output numbers and compare it to the log2(number of values in the tree). Print these two numbers and put them into the Comments-to-Teacher.
Since, ultimately, we want to drive the whole process from the command-line, after testing in an IDE (preferably Jupyter), you'll need a .py file that can be called from the command-line like this:
$ python3 BinTree2.py infred.csv outfred.csv
Then you can drive the whole process with a main function that looks like this:
import sys
def main():
Process(sys.argv[1],sys.argv[2])