How to use the algorithm-visualizer.LogTracer 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 / Dynamic Programming / Maximum Subarray / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

const D = [-2, -3, 4, -1, -2, 1, 5, -3];

// define tracer variables {
const tracer = new Array1DTracer();
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([tracer, logger]));
tracer.set(D);
Tracer.delay();
// }

const maxSubarraySum = (function maxSubarray(array) {
  let maxSoFar = 0;
  let maxEndingHere = 0;

  // logger {
  logger.println('Initializing maxSoFar = 0 & maxEndingHere = 0');
  // }

  for (let i = 0; i < array.length; i++) {
    // visualize {
    tracer.select(i);
github algorithm-visualizer / algorithms / Dynamic Programming / Ugly Numbers / code.js View on Github external
const N = 15;
const A = new Array(N);
for (let i = N - 1; i >= 0; i--) {
  A[i] = 0;
}
A[0] = 1; // By convention 1 is an ugly number

const M = [2, 3, 5]; // multiples of 2, 3, 5 respectively
const I = [0, 0, 0]; // iterators of 2, 3, 5 respectively

// define tracer variables {
const tracer = new Array1DTracer('Ugly Numbers');
const tracer2 = new Array1DTracer('Multiples of 2, 3, 5');
const tracer3 = new Array1DTracer(' Iterators I0, I1, I2 ');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([tracer, tracer2, tracer3, logger]));
tracer.set(A);
tracer2.set(M);
tracer3.set(I);
Tracer.delay();
// }

for (let i = 1; i < N; i++) {
  // next is minimum of m2, m3 and m5
  const next = (M[0] <= M[1]) ? (M[0] <= M[2]) ? M[0] : M[2] : (M[1] <= M[2]) ? M[1] : M[2];
  // logger {
  logger.println(` Minimum of ${M[0]}, ${M[1]}, ${M[2]} : ${next}`);
  // }
  A[i] = next;

  // visualize {
github algorithm-visualizer / algorithms / Brute Force / Shellsort / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, ChartTracer, LogTracer, Randomize, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

// define tracer variables {
const chart = new ChartTracer();
const tracer = new Array1DTracer();
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([chart, tracer, logger]));
const D = Randomize.Array1D({ N: 15 });
tracer.set(D);
tracer.chart(chart);
Tracer.delay();
// }

// logger {
logger.println(`Original array = [${D.join(', ')}]`);
// }
const N = D.length;

for (let gap = N; gap = parseInt(gap / 2);) {
  // logger {
  logger.println('');
  logger.println(`Gap of ${gap}`);
github algorithm-visualizer / algorithms / Dynamic Programming / Catalan Number / code.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, LogTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

const N = 10;
const A = new Array(N + 1);
for (let i = N; i >= 0; i--) {
  A[i] = 0;
}

// define tracer variables {
const tracer = new Array1DTracer(' Catalan Numbers ');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([tracer, logger]));
tracer.set(A);
Tracer.delay();
// }

A[0] = 1;
// visualize {
tracer.patch(0, A[0]);
Tracer.delay();
tracer.depatch(0);
// }
A[1] = 1;
// visualize {
tracer.patch(1, A[1]);
Tracer.delay();
tracer.depatch(1);
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 };
const N = 26;

algorithm-visualizer

Visualization Library for JavaScript

MIT
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis