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

Commit 1d72593

Browse files
author
Ram swaroop
committed
minor corrections
1 parent 566ddd4 commit 1d72593

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/me/ramswaroop/arrays/sorting/QuickSort.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public static int partition(int[] ar, int low, int high) {
2828
for (int i = low; i < high; i++) {
2929
/**
3030
* if ith element is smaller than pivot element then
31-
* swap it with the last larger element known.
31+
* swap it with the last larger element known
3232
*/
3333
if (ar[i] < ar[pivot]) {
34+
// swap a[low] with a[i]
3435
temp = ar[low];
3536
ar[low] = ar[i];
3637
ar[i] = temp;
@@ -48,7 +49,8 @@ public static int partition(int[] ar, int low, int high) {
4849

4950
/**
5051
* Recursive Quick sort.
51-
* NOTE: This function is tail-recursive.
52+
* NOTE: This function is tail-recursive (doesn't use
53+
* extra stack space per recursive call).
5254
* <p/>
5355
* Time complexity:
5456
* Best Case: O(nlogn)

src/me/ramswaroop/arrays/sorting/SelectionSort.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SelectionSort {
1919
* element is chosen and placed at the appropriate position and then again the
2020
* logic is applied on rest of the elements till the entire array is sorted.
2121
* <p/>
22-
* Time complexity: O(n) for all cases.
22+
* Time complexity: O(n*n) for all cases.
2323
* <p/>
2424
* NOTE: Advantage of this sort is that it requires minimum number of memory writes
2525
* like Cycle sort.

src/me/ramswaroop/common/MaxHeap.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,22 @@ public void buildMaxHeap() {
7373
}
7474
}
7575

76+
/**
77+
* Insert a new element into the heap satisfying
78+
* the heap property.
79+
*
80+
* Time complexity: O(log n) where 'n' is total no. of
81+
* elements in heap or O(h) where 'h' is the height of
82+
* heap.
83+
*
84+
* @param elem
85+
*/
7686
public void insert(int elem) {
87+
// increase heap size
7788
heap = Arrays.copyOf(heap, size + 1);
7889
int i = size;
7990
int parentIndex = (int) Math.floor((i - 1) / 2);
91+
// move up through the heap till you find the right position
8092
while (i > 0 && elem > heap[parentIndex]) {
8193
heap[i] = heap[parentIndex];
8294
i = parentIndex;

0 commit comments

Comments
 (0)