File tree 4 files changed +52
-1
lines changed
4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 83
83
"etc" : {
84
84
"name" : " Uncategorized" ,
85
85
"list" : {
86
- "flood_fill" : " Flood Fill"
86
+ "flood_fill" : " Flood Fill" ,
87
+ "pascal_triangle" : " Pascal's Trangle"
87
88
}
88
89
}
89
90
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "Pascal's Triangle" : " Pascal's triangle is a triangular array of the binomial coefficients." ,
3
+ "Applications" : [
4
+ " Binomial Expansion" ,
5
+ " Probability"
6
+ ],
7
+ "Complexity" : {
8
+ "time" : " O(N<sup>2</sup>)" ,
9
+ "space" : " O(N<sup>2</sup>)"
10
+ },
11
+ "References" : [
12
+ " <a href='https://en.wikipedia.org/wiki/Pascal%27s_triangle'>Wikipedia</a>"
13
+ ],
14
+ "files" : {
15
+ "pascal_triangle" : " Pascal's Triangle"
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ for ( var i = 0 ; i < N ; i ++ ) {
2
+ for ( var j = 0 ; j <= i ; j ++ ) {
3
+ if ( j === i || j === 0 ) { // First and last values in every row are 1
4
+ A [ i ] [ j ] = 1 ;
5
+
6
+ tracer . _notify ( i , j , A [ i ] [ j ] ) . _wait ( ) ;
7
+ tracer . _denotify ( i , j ) ;
8
+ } else { // Other values are sum of values just above and left of above
9
+ tracer . _select ( i - 1 , j - 1 ) . _wait ( ) ;
10
+ tracer . _select ( i - 1 , j ) . _wait ( ) ;
11
+
12
+ A [ i ] [ j ] = A [ i - 1 ] [ j - 1 ] + A [ i - 1 ] [ j ] ;
13
+
14
+ tracer . _notify ( i , j , A [ i ] [ j ] ) . _wait ( ) ;
15
+ tracer . _denotify ( i , j ) ;
16
+ tracer . _deselect ( i - 1 , j - 1 ) ;
17
+ tracer . _deselect ( i - 1 , j ) ;
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ var N = 9 ;
2
+ var A = new Array ( N ) ;
3
+ for ( var i = N - 1 ; i >= 0 ; i -- ) {
4
+ A [ i ] = new Array ( N ) ;
5
+ }
6
+
7
+ for ( var i = N - 1 ; i >= 0 ; i -- ) {
8
+ for ( var j = N - 1 ; j >= 0 ; j -- ) {
9
+ A [ i ] [ j ] = ' ' ;
10
+ }
11
+ }
12
+
13
+ var tracer = new Array2DTracer ( 'Pascal\'s Triangle' ) . _setData ( A ) ;
You can’t perform that action at this time.
0 commit comments