Post here clarifications about q 3
when i init the tree, what the key of the root suppose to be?
Im asking because your test functions expect something (maybe nothing, like in the recitation? not possible in this case…)
and it gives me an error on 'heavy_path()' and it makes me feel sad… :>(
Try to find the answer yourself. This is one of the question's goals…
You did not define what should min return when the tree has only an empty node/no nodes at all
When there are no nodes at all min should return None.
What do you mean by "an empty node"?
Thank you the this clarification, it helped me.
when I said "an empty node", I meant when `BSearch_tree` is initiated the first time, and before the first node has been inserted, the attribute (that would later contain the first node) would still be initiated in `init`
but must be the singleton value of "nothing" or "empty node", "a node without any value" or in my case `None`.
Just to make sure I'm not going crazy: When I apply mirror() to a binary search tree, it is no longer a standard binary search tree, correct?
correct.
היי
האם הפונקציה insert צריכה להחזיר את העץ (כמו הinsert שמימשתם בכיתה?)? או פשוט לשנות אותו וזהו?
That's a good question.
Recall the major disadvantage of the non-OOP version of trees we saw in class: an unnatural distinction between insertion into an empty and a non-empty tree. Only in the first case we actually used the return value of insert.
The OOP version is aimed at eliminating this inconsistency. Therefore, insert should only change the tree, and return nothing.
האם במימוש המחלקה BSearch_tree מותר לי להחזיק משתנה שיכיל את מספר הצמתים בעץ? (כדי להקל בהמשך?)
You can decide on any reasonable internal representation.
I doubt this is really needed, however.
האם אנו יכולים להוסיף ל- Tree_node מתודות נוספות כדי לממש את המתודות של BSearch_tree?
בסעיף ג' בדוגמא של הפונקציה מירור,
אני חושבת שהצומת עם המפתח 4 צריך להיות בצד ימין, ולא בצד שמאל
It seems you are wrong.
Please read again the 3 specifications of the mirror operation.
האם כשאתם מבקשים שבאתחול העץ הוא יהיה ריק מצמתים הכוונה היא
לNone
או T=Tree_node(None,None)
כי למעשה בשני המקרים הוא ריק מצמתים, פשוט יותר נוח לעבוד עם הראשון אך זה לא לגמרי מספק את ההגדרה שהשורש יהיה מסוג טרי נוד…
ועם זאת האפשרות הראשונה מתיישבת יותר טוב עם איך שהגדרתם את הפונקציות בתרגול.. תודה
First, note that a tree (empty or not) is an object of class BSearch_tree. This class has one field, root, which represents the root of the tree.
It's for YOU to decide about the internal implementation, including in the case of an empty tree, as long as it fulfills all the requirements.
Hi Amir,
[content deleted] The question is, what if the user wants to update one of the nodes in the tree to Tree_node(None,None)? can I assume that Tree_node(None,None) is invalid node for a tree that is not empty?
Thanks,
Omer.
Omer,
I deleted part of your post, because you wrote a possible solution. Please abstain from this.
Yes, None in Python is reserved for representing "nothing", and you may assume it cannot be a legal value of a node.
In skeleton 5 the function min() is marked in purple, which means python is calling the regular min function, is this ok?
>>> def min(): return 6 >>> min() 6
So you were wrong…