Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a983f8c

Browse files
committed
Minor improvements
1 parent 63160f0 commit a983f8c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/main/java/com/rampatra/common/MaxHeap.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.util.Arrays;
66

77
/**
8-
* Created by IntelliJ IDEA.
9-
* <p/>
108
* A HEAP is a specialized tree-based ABSTRACT DATA TYPE that satisfies the heap property:
119
* min-heap: All non-leaf elements are either smaller than or equal to their left and right child.
1210
* max-heap: All non-leaf elements are either greater than or equal to their left and right child.
@@ -19,11 +17,10 @@
1917
* Therefore, buildMaxHeap() would take O(n log n) time BUT IF OBSERVED CAREFULLY IT TAKES 0(N) TIME.
2018
* <p/>
2119
* Used in the HeapSort algorithm. Also can be used to implement a PriorityQueue.
20+
* <a href="@see http://staff.ustc.edu.cn/~csli/graduate/algorithms/book6/chap07.htm">Learn more</a>
2221
*
23-
* @author: ramswaroop
24-
* @date: 8/2/15
25-
* @time: 11:57 AM
26-
* @see: http://staff.ustc.edu.cn/~csli/graduate/algorithms/book6/chap07.htm
22+
* @author rampatra
23+
* @since 8/2/15
2724
*/
2825
public class MaxHeap {
2926

src/main/java/com/rampatra/common/MinHeap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Each successor can be found in O(log n). The algorithm in minHeapify() takes O(log n) time
1515
* Therefore, buildMinHeap() would take O(n log n) time BUT IF OBSERVED CAREFULLY IT TAKES 0(N) TIME.
1616
* <p/>
17-
* Used in the HeapSort algorithm. Also can be used to implement a PriorityQueue.
17+
* Used in the HeapSort algorithm. Also can be used to implement a PriorityQueue.
1818
* <a href="@see http://staff.ustc.edu.cn/~csli/graduate/algorithms/book6/chap07.htm">Learn more</a>
1919
*
2020
* @author rampatra
@@ -68,7 +68,7 @@ public void buildMinHeap() {
6868
}
6969

7070
public void insert(int elem) {
71-
heap = Arrays.copyOf(heap, 2 * size);
71+
heap = Arrays.copyOf(heap, size + 1);
7272
int i = size;
7373
int parentIndex = (int) Math.floor((i - 1) / 2);
7474
while (i > 0 && elem < heap[parentIndex]) {

0 commit comments

Comments
 (0)