Skip to content

Implement Binary Tree to Binary Search Tree Conversion #95

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

Closed
wants to merge 273 commits into from
Closed

Implement Binary Tree to Binary Search Tree Conversion #95

wants to merge 273 commits into from

Conversation

k88manish
Copy link
Contributor

No description provided.

ashokdey and others added 30 commits January 4, 2019 13:28
--update : add test file for merge-two-sorted-arrays
2nd approach for product-of-elements
Copy link
Member

@ashokdey ashokdey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k88manish please go through the changes requested and make the changes where required.

Comment on lines 3 to 7
const tree = {
data: 10,
left: { data: 30, left: { data: 20 } },
right: { data: 15, right: { data: 5 } },
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the Node structure and adhere to it for all the things you do with BST.
Find the Node Implementation here: BST Node

Comment on lines 12 to 27
expect(tree).toEqual({
data: 15,
left: {
data: 10,
left: {
data: 5,
},
},
right: {
data: 20,
right: {
data: 30,
},
},
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the tree traversal method to verify the result

Comment on lines 20 to 32
function storeInorder(root, inorder) {
// Base case
if (!root) return;

// First store the left subtree
storeInorder(root.left, inorder);

// Append root's data
inorder.push(root.data);

// Store right subtree
storeInorder(root.right, inorder);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to return an array instead of accepting an array as an argument. For help, you can go through the various traversal algorithms and problems on BST from the README

storeInorder(root.right, inorder);
}

// Helper function that copies of sorted array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more detailed information here

@ashokdey
Copy link
Member

@TheSTL please look into this.

@k88manish k88manish requested a review from ashokdey October 19, 2019 19:55
@k88manish
Copy link
Contributor Author

@ashokdey I have made some changes as per your review. Please review it whenever possible.

Manish Kumar and others added 3 commits October 20, 2019 15:37
@k88manish
Copy link
Contributor Author

Closing this PR because of messed up Author info. Will open a new one for the same

@k88manish k88manish closed this Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.