How to use the algorithm-visualizer.Layout.setRoot 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 / algorithm-visualizer / src / files / skeletons / code.js View on Github external
(function main() {
  // visualize {
  Layout.setRoot(new VerticalLayout([array2dTracer, logTracer]));
  array2dTracer.set(messages);
  Tracer.delay();
  // }
  highlight(0);
})();
github algorithm-visualizer / algorithms / Greedy / Job Scheduling Problem / code.js View on Github external
}
  }
}

const slot = new Array(N);
const result = new Array(N);
for (let i = N - 1; i >= 0; i--) {
  result[i] = '-';
}

// define tracer variables {
const tracer3 = new Array1DTracer('Schedule');
const tracer = new Array1DTracer('Job Ids');
const tracer1 = new Array1DTracer('Deadlines');
const tracer2 = new Array1DTracer('Profit');
Layout.setRoot(new VerticalLayout([tracer3, tracer, tracer1, tracer2]));
tracer.set(jobId);
tracer1.set(deadline);
tracer2.set(profit);
tracer3.set(result);
Tracer.delay();
// }

// Initialise all slots to free
for (let i = 0; i < N; i++) {
  slot[i] = 0;
}

// Iterate through all the given jobs
for (let i = 0; i < N; i++) {
  /*
     Start from the last possible slot.
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 {
  tracer.patch(i, A[i]);
github algorithm-visualizer / algorithms / Brute Force / Depth-First Search / graph.js View on Github external
// import visualization libraries {
const { Tracer, Array1DTracer, GraphTracer, LogTracer, Randomize, Layout, VerticalLayout } = require('algorithm-visualizer');
// }

// define tracer variables {
const graphTracer = new GraphTracer().directed(false);
const visitedTracer = new Array1DTracer('visited');
const logger = new LogTracer();
Layout.setRoot(new VerticalLayout([graphTracer, visitedTracer, logger]));
graphTracer.log(logger);
const G = Randomize.Graph({ N: 8, ratio: .3, directed: false });
graphTracer.set(G);
Tracer.delay();
// }

function DFSExplore(graph, source) {
  const stack = [[source, null]];
  const visited = [];
  let node;
  let prev;
  let i;
  let temp;
  for (i = 0; i < graph.length; i++) {
    visited.push(false);
  }

algorithm-visualizer

Visualization Library for JavaScript

MIT
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis