Skip to content

Commit 8d668cc

Browse files
committed
update heap complexities
1 parent 29b5a3a commit 8d668cc

File tree

4 files changed

+15
-165
lines changed

4 files changed

+15
-165
lines changed

02-heap/heapsort.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
/**
2-
* @file heapsort.cpp
3-
*
4-
* @brief this file contians source code for heap sort
5-
*
6-
* @author Oleksiy Nehlyadyuk
7-
* Contact: [email protected]
8-
*
9-
*/
10-
#include "./heapsort.h"
11-
121
// hack for descending sort
132
void negateArray(int A[], int n) {
143
for (int i=0; i<n; ++i){
@@ -31,10 +20,11 @@ void maxHeapify(int A[], int n, int i) {
3120
}
3221
}
3322

34-
// take an ordinary array and convert into heap
23+
// convert array into heap
3524
void buildMaxHeap(int A[], int n) {
36-
for (int i = n / 2 - 1; i >= 0; i--)
25+
for (int i = n/2-1; i >= 0; i--) {
3726
maxHeapify(A, n, i);
27+
}
3828
}
3929

4030
// sort elements in Ascending order

03-binary-search-tree/bs-tree-v2.cpp

-59
This file was deleted.

03-binary-search-tree/bs-tree.cpp

-79
This file was deleted.

heap/README.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
### what is it
77

8-
A binary search tree is a tree data structure where:
8+
a binary tree where the smallest value is always on the top. used to implement a ***priority queue** or **heap sort**
99

10-
- The nodes to the left are smaller than the current node.
11-
- The nodes to the right are larger than the current node.
1210
### costs
1311

1412
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
@@ -23,45 +21,45 @@ A binary search tree is a tree data structure where:
2321
</colgroup>
2422
<thead>
2523
<tr>
26-
<th scope="col" class="org-left">BST</th>
27-
<th scope="col" class="org-left">avarage</th>
24+
<th scope="col" class="org-left">Heap</th>
2825
<th scope="col" class="org-left">worst</th>
2926
</tr>
3027
</thead>
3128

3229
<tbody>
3330
<tr>
34-
<td class="org-left">Access</td>
35-
<td class="org-left">O(log(n))</td>
36-
<td class="org-left">O(n)</td>
31+
<td class="org-left">Get Min</td>
32+
<td class="org-left">O(1)</td>
3733
</tr>
3834

3935

4036
<tr>
41-
<td class="org-left">Search</td>
37+
<td class="org-left">Remove Min</td>
4238
<td class="org-left">O(log(n))</td>
43-
<td class="org-left">O(n)</td>
4439
</tr>
4540

4641

4742
<tr>
4843
<td class="org-left">Insertion</td>
4944
<td class="org-left">O(log(n))</td>
50-
<td class="org-left">O(n)</td>
5145
</tr>
5246

5347

5448
<tr>
55-
<td class="org-left">Deletion</td>
56-
<td class="org-left">O(log(n))</td>
49+
<td class="org-left">Heapsort</td>
50+
<td class="org-left">O(n*log(n))</td>
51+
</tr>
52+
53+
54+
<tr>
55+
<td class="org-left">Heapify</td>
5756
<td class="org-left">O(n)</td>
5857
</tr>
5958
</tbody>
6059

6160
<tbody>
6261
<tr>
6362
<td class="org-left">Space</td>
64-
<td class="org-left">&#xa0;</td>
6563
<td class="org-left">O(n)</td>
6664
</tr>
6765
</tbody>

0 commit comments

Comments
 (0)