How to use the algorithm-visualizer.Array1DTracer function in algorithm-visualizer

To help you get started, we’ve selected a few algorithm-visualizer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github algorithm-visualizer / algorithms / Uncategorized / Affine Cipher / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

const plainText = 'secret';

// define tracer variables {
const ptTracer = new Array1DTracer('Encryption');
const ctTracer = new Array1DTracer('Decryption');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([ptTracer, ctTracer, logger]));

ptTracer.set(plainText);
Tracer.delay();
// }

/*
 code assumes that plainText contains ONLY LOWER CASE ALPHABETS
 */

Number.prototype.mod = function (n) {
  return ((this % n) + n) % n;
};
github algorithm-visualizer / algorithms / Uncategorized / Affine Cipher / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

const plainText = 'secret';

// define tracer variables {
const ptTracer = new Array1DTracer('Encryption');
const ctTracer = new Array1DTracer('Decryption');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([ptTracer, ctTracer, logger]));

ptTracer.set(plainText);
Tracer.delay();
// }

/*
 code assumes that plainText contains ONLY LOWER CASE ALPHABETS
 */

Number.prototype.mod = function (n) {
  return ((this % n) + n) % n;
};

const keys = { a: 5, b: 7 };
github algorithm-visualizer / algorithms / Dynamic Programming / Z String Search / code.js View on Github external
// }

// let pattern = "aab";
// let text = "aabxaabxcaabxaabxay";
const pattern = 'abc';
const text = 'xabcabzabc';

const len = pattern.length + text.length + 1;

const z = new Array(len);
z[0] = 0;

// define tracer variables {
const textTracer = new Array1DTracer('text');
const pattTracer = new Array1DTracer('pattern');
const concatTracer = new Array1DTracer('concatenated string');
const tracer = new Array1DTracer('zArray');
pattTracer.set(pattern);
textTracer.set(text);
tracer.set(z);
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([textTracer, pattTracer, concatTracer, tracer, logger]));
Tracer.delay();
// }

function createZarr(concat) {
  let left;
  let right;
  let N;
  N = concat.length;
  left = 0;
  right = 0;
github algorithm-visualizer / algorithms / Brute Force / PageRank / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, Array2DTracer, GraphTracer, LogTracer, Randomize, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

function filledArray(length, value) {
  return Array(...Array(length)).map(Number.prototype.valueOf, value);
}

// define tracer variables {
const G = Randomize.Graph({ N: 5, ratio: .4 });
let ranks;
const outgoingEdgeCounts = filledArray(G.length, 0);
let incomingNodes;
const graphTracer = new GraphTracer('Web Page inter-connections');
const rankTracer = new Array1DTracer('Web Page Ranks');
const oecTracer = new Array1DTracer('Outgoing Edge Counts');
const inTracer = new Array2DTracer('Incoming Nodes');

const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([graphTracer, rankTracer, oecTracer, inTracer, logger]));

graphTracer.set(G);
oecTracer.set(outgoingEdgeCounts);

for (incomingNodes = []; incomingNodes.length < G.length; incomingNodes.push(filledArray(G.length, -1))) ;
inTracer.set(incomingNodes);
Tracer.delay();
// }

/*
  PageRank Algorithm Version 2
  Equation:
github algorithm-visualizer / algorithms / Graph Search / PageRank Algorithm (V2) / code.js View on Github external
import { Array1DTracer, Array2DTracer, GraphTracer, LogTracer, Randomize } from 'algorithm-visualizer';

function filledArray(length, value) {
  return Array(...Array(length)).map(Number.prototype.valueOf, value);
}

const G = Randomize.graph(5, { ratio: 0.4 });
let ranks;
const outgoingEdgeCounts = filledArray(G.length, 0);
let incomingNodes;
const graphTracer = new GraphTracer('Web Page inter-connections');
const rankTracer = new Array1DTracer('Web Page Ranks');
const oecTracer = new Array1DTracer('Outgoing Edge Counts');
const inTracer = new Array2DTracer('Incoming Nodes');

const logger = new LogTracer();

graphTracer.set(G);
oecTracer.set(outgoingEdgeCounts);

for (incomingNodes = []; incomingNodes.length < G.length; incomingNodes.push(filledArray(G.length, -1)));
inTracer.set(incomingNodes).delay();

/*
  PageRank Algorithm Version 2
  Equation:
    PR (X) = ( (1 - D)/N ) + D (Summation i->X (PR (I) / Out (i)))
  NOTE: Algorithm uses the recommended damping factor (D). Number of iterations is small because only a small Web of 5 Pages is simulated
*/

algorithm-visualizer

Visualization Library for JavaScript

MIT
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis