Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am attempting to downheap on an array from the last interior node all the way up to the root, so that I am making mini-heaps from the bottom up. I have an algorithm that I believe will do this though I far from 100% certain at this point.

I cannot figure out how index errors in my code are happening. My immediate concern here is for this downheap algorithm to work, but I'm not able to get any meaningful output, and any help would be greatly appreciated.

As reference, I don't get index errors when I use index of i in the recursive call. As soon as I replace i with bkIndex , I get those IndexErrors. If I use i, in the recursive call, I get an output of

Array:
3 6 12 7 2 1 5 8 4 10 11 0 13 9 14
Heap:
13 13 12 13 10 11 13 8 4 10 11 0 13 9 14

Which is still wrong, but at least I wasn't getting an index error.

And now I'm questioning if I'm even close to getting this algorithm down. If it's really that far off, I might just scrap the whole thing and start over... Does it look ok? If it does, and I am close, how would I make it ok?

What I have tried:

http://www.pasteall.org/64356/python
Posted
Comments
Patrice T 7-Feb-16 19:14pm    
Show your code !
Sergey Alexandrovich Kryukov 7-Feb-16 20:13pm    
Why having a section "what I have tried" without telling us what have you tried.
We got a number "questions" with the same structure and attitude, and I wonder: is it the same person under different accounts? The common characteristics are: no effort, having not clue on what to do, something creating a lot of doubt if you should do this work at all...
Such questions are not answerable, it the answers cannot be useful to anyone. Just one advice: get to work.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900