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

Some doubt in BuildMaxHeap #1

Closed
krishnaexplore opened this issue May 12, 2018 · 1 comment
Closed

Some doubt in BuildMaxHeap #1

krishnaexplore opened this issue May 12, 2018 · 1 comment
Labels

Comments

@krishnaexplore
Copy link

seems not working BuildHeap

https://github.com/ramswaroop/Algorithms-and-Data-Structures-in-Java/blob/master/src/me/ramswaroop/common/MaxHeap.java#L49:L50
if we do some change here it is working
leftIndex = 2 * i ;
rightIndex = 2 * i + 1;

for input {5,12,64,1,37,90,91,97};
output should be : [97, 91, 90, 12, 37, 64, 5, 1]

@rampatra
Copy link
Owner

rampatra commented May 21, 2018

The output from the code buildMaxHeap() is [97, 37, 91, 12, 5, 90, 64, 1] is correct as per my understanding. What makes you think otherwise?

Note: Max heap is a heap with root greater than or equal to left and right children (except for leaf nodes) and this property is satisfied in the output [97, 37, 91, 12, 5, 90, 64, 1].

@rampatra rampatra changed the title some mistake in BuildHeap Some doubt in BuildMaxHeap May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants