File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change
1
+ // TODO: Add unit test
2
+
1
3
import BHNode from "./bHNode" ;
2
4
3
5
class MinHeap < T > {
@@ -67,7 +69,7 @@ class MinHeap<T> {
67
69
} else {
68
70
smallIdx = l ;
69
71
}
70
- // swap element from idx with greater
72
+ // swap parent and smaller child
71
73
[ this . values [ idx ] , this . values [ smallIdx ] ] = [
72
74
this . values [ smallIdx ] ,
73
75
this . values [ idx ] ,
@@ -108,6 +110,7 @@ class MinHeap<T> {
108
110
// In this case second param <keys> is not used
109
111
// In any case the Heap is build in linear time
110
112
// Returns: this Heap
113
+ // TODO: static method
111
114
buildHeap = ( arr : number [ ] | Map < T , number > , keys : T [ ] ) => {
112
115
// Returns false if this heap is not empty
113
116
if ( ! this . isEmpty ( ) ) return false ;
Original file line number Diff line number Diff line change
1
+ // TODO: needlemanWunsch implementation! already done in another repo
2
+
1
3
// inputs: Stirng X and Y
2
4
// sigma for gap penalty
3
5
// Alpha: matrix for mismatch cost
@@ -15,7 +17,7 @@ const sq = (
15
17
16
18
// for empty strings
17
19
for ( let i = 0 ; i < m ; i ++ ) arr [ i ] [ 0 ] = i * sigma ;
18
- for ( let j = 0 ; j < m ; j ++ ) arr [ 0 ] [ j ] = j * sigma ;
20
+ for ( let j = 0 ; j < n ; j ++ ) arr [ 0 ] [ j ] = j * sigma ;
19
21
20
22
// case 1: match cost + Xi-1 Yj-1
21
23
// case 2: sigma + Xi-1 Yj
Original file line number Diff line number Diff line change 1
1
import MinHeap from "../data-structures/heaps/minHeap" ;
2
2
3
+ // TODO: use Heap interface so it's possible to use any heap implementation
4
+ // EG, Fibonacci heap
3
5
const heapSort = ( arr : number [ ] ) => {
4
6
const minHeap = new MinHeap ( ) ;
5
7
const result = [ ] ;
You can’t perform that action at this time.
0 commit comments