Content-Length: 934637 | pFad | http://github.com/algorithm-visualizer/algorithms/commit/ef4636934f3ac98e2256ac0fbd3cb5c7b10c5cd3

57 Adjust to the updated Randomize functions in tracers.js · algorithm-visualizer/algorithms@ef46369 · GitHub
Skip to content

Commit ef46369

Browse files
committed
Adjust to the updated Randomize functions in tracers.js
1 parent f310721 commit ef46369

File tree

38 files changed

+63
-55
lines changed

38 files changed

+63
-55
lines changed

Branch and Bound/Binary Search Tree/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const T = [ // mapping to G as a binary tree , [i][0] indicates left child, [i][
2828
[9, -1],
2929
];
3030

31-
const key = new Randomize.Integer(0, G.length - 1).create(); // item to be searched
31+
const key = Randomize.Integer({ min: 0, max: G.length - 1 }); // item to be searched
3232
const tracer = new GraphTracer(' Binary Search Tree ');
3333
const logger = new LogTracer(' Log ');
3434
Layout.setRoot(new VerticalLayout([tracer, logger]));

Branch and Bound/Binary Search/iterative.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chart = new ChartTracer();
44
const tracer = new Array1DTracer();
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
7-
const D = new Randomize.Array1D(15, new Randomize.Integer(0, 50)).sorted().create();
7+
const D = Randomize.Array1D({ N: 15, value: () => Randomize.Integer({ min: 0, max: 50 }), sorted: true });
88
tracer.set(D);
99
tracer.chart(chart);
1010
Tracer.delay();
@@ -44,7 +44,7 @@ function BinarySearch(array, element) { // array = sorted array, element = eleme
4444
return -1;
4545
}
4646

47-
const element = D[new Randomize.Integer(0, D.length - 1).create()];
47+
const element = D[Randomize.Integer({ min: 0, max: D.length - 1 })];
4848

4949
logger.println(`Using iterative binary search to find ${element}`);
5050
BinarySearch(D, element);

Branch and Bound/Binary Search/recursive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chart = new ChartTracer();
44
const tracer = new Array1DTracer();
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
7-
const D = new Randomize.Array1D(15, new Randomize.Integer(0, 50)).sorted().create();
7+
const D = Randomize.Array1D({ N: 15, value: () => Randomize.Integer({ min: 0, max: 50 }), sorted: true });
88
tracer.set(D);
99
tracer.chart(chart);
1010
Tracer.delay();
@@ -46,7 +46,7 @@ function BinarySearch(array, element, minIndex, maxIndex) { // array = sorted ar
4646
return -1;
4747
}
4848

49-
const element = D[new Randomize.Integer(0, D.length - 1).create()];
49+
const element = D[Randomize.Integer({ min: 0, max: D.length - 1 })];
5050

5151
logger.println(`Using binary search to find ${element}`);
5252
BinarySearch(D, element, 0, D.length - 1);

Branch and Bound/Depth-Limited Search/code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ function DLSCount(limit, node, parent) { // node = current node, parent = previo
3737
}
3838
return child;
3939
}
40+
4041
logger.println(`Number of descendant is ${DLSCount(2, 0)}`);

Brute Force/Breadth-First Search/shortestPath.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const tracer = new GraphTracer().directed(false).weighted();
44
const logger = new LogTracer();
55
Layout.setRoot(new VerticalLayout([tracer, logger]));
66
tracer.log(logger);
7-
const G = new Randomize.Graph(5, 1).directed(false).weighted().create();
7+
const G = Randomize.Graph({ N: 5, ratio: 1, directed: false, weighted: true });
88
tracer.set(G);
99
Tracer.delay();
1010

@@ -36,10 +36,10 @@ function BFS() {
3636
return W[e];
3737
}
3838

39-
let s = new Randomize.Integer(0, G.length - 1).create(); // s = start node
39+
let s = Randomize.Integer({ min: 0, max: G.length - 1 }); // s = start node
4040
let e; // e = start node
4141
do {
42-
e = new Randomize.Integer(0, G.length - 1).create();
42+
e = Randomize.Integer({ min: 0, max: G.length - 1 });
4343
} while (s === e);
4444
let MAX_VALUE = 0x7fffffff;
4545
logger.println(`finding the shortest path from ${s} to ${e}`);

Brute Force/Breadth-First Search/tree.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ function BFS(s) { // s = start node
3737
}
3838
}
3939
}
40+
4041
BFS(0);

Brute Force/Bubble Sort/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chart = new ChartTracer();
44
const tracer = new Array1DTracer();
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
7-
const D = new Randomize.Array1D(15).create();
7+
const D = Randomize.Array1D({ N: 15 });
88
tracer.set(D);
99
tracer.chart(chart);
1010
Tracer.delay();

Brute Force/Comb Sort/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chart = new ChartTracer();
44
const tracer = new Array1DTracer();
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
7-
const D = new Randomize.Array1D(15).create();
7+
const D = Randomize.Array1D({ N: 15 });
88
tracer.set(D);
99
tracer.chart(chart);
1010
Tracer.delay();

Brute Force/Cycle Sort/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chart = new ChartTracer();
44
const tracer = new Array1DTracer();
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
7-
const D = new Randomize.Array1D(15).create();
7+
const D = Randomize.Array1D({ N: 15 });
88
tracer.set(D);
99
tracer.chart(chart);
1010
Tracer.delay();

Brute Force/Depth-First Search/graph.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const visitedTracer = new Array1DTracer('visited');
55
const logger = new LogTracer();
66
Layout.setRoot(new VerticalLayout([graphTracer, visitedTracer, logger]));
77
graphTracer.log(logger);
8-
const G = new Randomize.Graph(8, .3).directed(false).create();
8+
const G = Randomize.Graph({ N: 8, ratio: .3, directed: false });
99
graphTracer.set(G);
1010
Tracer.delay();
1111

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/algorithm-visualizer/algorithms/commit/ef4636934f3ac98e2256ac0fbd3cb5c7b10c5cd3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy