Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do you fill (insert nodes into) a binary tree (not binarysearch tree)? Is is

ID: 3614490 • Letter: H

Question

How do you fill (insert nodes into) a binary tree (not binarysearch tree)?
Is is just like a priority queue, left to right, level by level? Idon't really see any other way to do it, since the BT doesn't havethe "left is less, right is greater" quality of the BST.

Explanation / Answer

You have to remember, order does not matter if your tree is not abinary search tree. In most implementations of the tree structure, the binary structureis really the result of a user/implementer adding a maximum of twonodes to the root node, and each successive node after that. Hence,which side the data goes to when you fill in the nodes of a binarytree really depends on the end implementation. For example, if I made the node structure have two data structuresto hold the each branch, the side that the branching node is addedonto depends on how I wrote the add function/method. Normally,since we have a tendency to read left --> right, implementationsthat I have seen generally add a node to the left, and add thesecond node to the right. Unless there is an order-specific data structure used (such as aqueue or stack), the order of adding nodes would be based on howthe adding method is implemented. Otherwise, it would follow thespecifications of what data structure is used to hold thesuccessive nodes. If you are implementing the code for a tree structure, I wouldsuggest adding it left to right for the sake of simplicity andstandardization. You would obviously have to add it level by level,as there is no way you can add a sublevel before you add the rootlevel. Good luck!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote