Skip to content
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

BST to max heap #224

Closed
Utkarsh-Aggarwal opened this issue Oct 2, 2024 · 2 comments
Closed

BST to max heap #224

Utkarsh-Aggarwal opened this issue Oct 2, 2024 · 2 comments
Assignees
Labels
DSA Hacktoberfest contribute for hacktoberfest 2024

Comments

@Utkarsh-Aggarwal
Copy link
Contributor

Given a Binary Search Tree. Convert a given BST into a Special Max Heap with the condition that all the values in the left subtree of a node should be less than all the values in the right subtree of the node. This condition is applied on all the nodes in the so converted Max Heap.

Example 1:

Input :
4
/
2 6
/ \ /
1 3 5 7

Output : 1 2 3 4 5 6 7
Exaplanation :
7
/
3 6
/ \ /
1 2 4 5
The given BST has been transformed into a
Max Heap and it's postorder traversal is
1 2 3 4 5 6 7.

Your task :
You don't need to read input or print anything. Your task is to complete the function convertToMaxHeapUtil() which takes the root of the tree as input and converts the BST to max heap.
Note : The driver code prints the postorder traversal of the converted BST.

Expected Time Complexity : O(n)
Expected Auxiliary Space : O(n)

Constraints :
1 ≤ n ≤ 105

@Saloni6111 Saloni6111 added Hacktoberfest contribute for hacktoberfest 2024 DSA labels Oct 2, 2024
@Saloni6111
Copy link
Owner

Given a Binary Search Tree. Convert a given BST into a Special Max Heap with the condition that all the values in the left subtree of a node should be less than all the values in the right subtree of the node. This condition is applied on all the nodes in the so converted Max Heap.

Example 1:

Input : 4 / 2 6 / \ / 1 3 5 7

Output : 1 2 3 4 5 6 7 Exaplanation : 7 / 3 6 / \ / 1 2 4 5 The given BST has been transformed into a Max Heap and it's postorder traversal is 1 2 3 4 5 6 7.

Your task : You don't need to read input or print anything. Your task is to complete the function convertToMaxHeapUtil() which takes the root of the tree as input and converts the BST to max heap. Note : The driver code prints the postorder traversal of the converted BST.

Expected Time Complexity : O(n) Expected Auxiliary Space : O(n)

Constraints : 1 ≤ n ≤ 105

@Utkarsh-Aggarwal assigned to you!

@Saloni6111 Saloni6111 mentioned this issue Oct 2, 2024
@Saloni6111
Copy link
Owner

merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DSA Hacktoberfest contribute for hacktoberfest 2024
Projects
None yet
Development

No branches or pull requests

2 participants