-
Notifications
You must be signed in to change notification settings - Fork 269
Implement Binary Tree to Binary Search Tree Conversion - Solution #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to return null meaning the tree is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can re-use the Node class already present in the codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better way to do this is to create a file inside Problems/tree-traversal directory nd have the following:
- inorderTraversal(root) : returns array of elements
- preorderTraversal(root) : returns array of elements
- so on...
And re-use the function here.
Alternatively, I am going forward to create these as helpers inside DataStructures/Trees/traversal so that they can be re-used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention the runtime complexity of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheSTL, shouldn't it return a new BST?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashokdey Yes, it should return the root node of new created BST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary Tree implementation is already present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@k88manish, you can use this Binary Tree using level order to create the tree here.
- Return null value - Using Node Class already existed - Mentioned Runtime complexity of function - Return BST root node - Used BinaryTree implementation to create the tree.
@k88manish, ok for me. waiting for @TheSTL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @k88manish for PR
@ashokdey @TheSTL - Raised a new PR because the last PR was raised with the wrong Author information