js-priority-queue
js-priority-queue copied to clipboard
Hi, I found some problems in the implementation
Here are some potential problems I found when I do the refactor to TypeScript, if some of these concerns are already taken care of by language features, please ignore.
- in heap implementation, bubble down may do something wrong, it should get the biggest one between (itself, left child, right child), however, the implementation check the left one, check it without exchange it when compare < 0; then go to the right one. So it is very likely that the left one is bigger, right one is smaller, and we exchange the right one(assume a ">" heap), this picture will explain
1 2
| \ => |
3 2 3 1 please exchange when you find it is smaller, then the logic will be good. - Don't we get track of length inside each implementation, and throw exception from the very concrete classes?
Sorry, I think I found out the first trick, close it.