From cde6e8a2291bb97e08b28dedf093942e664eaa09 Mon Sep 17 00:00:00 2001 From: Balaji Saravanan Date: Sun, 29 May 2022 12:01:08 +0530 Subject: [PATCH] Update heap.js Fix proper parent index fetching --- src/data-structures/heaps/heap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data-structures/heaps/heap.js b/src/data-structures/heaps/heap.js index 54863c39..537894ee 100644 --- a/src/data-structures/heaps/heap.js +++ b/src/data-structures/heaps/heap.js @@ -59,7 +59,7 @@ class Heap { */ bubbleUp() { let index = this.size - 1; - const parent = (i) => Math.ceil(i / 2 - 1); + const parent = (i) => Math.ceil(i / 2) - 1; while (parent(index) >= 0 && this.comparator(parent(index), index) > 0) { this.swap(parent(index), index); index = parent(index);