Algorithm Visualizations
Hash table quadratic probing: Insert keys, delete a key, insert another key, then search. Resolve collisions by quadratic probing; tombstones preserve search…
javascript
function algorithm(a, n, deleteKey, insertKey, target, output) {
let present = Array(256).fill(0);
let table = Array(256).fill(0); let probe = 0; let slot = 0; let tomb = 0;
let value = 0; let deleting = 0; let found = 0; let length = 0; let comparisons = 0;
for (let i = 0; i < 17; i++) { table[i] = -1; }
for (let operation = 0; operation < n + 2; operation++) {
deleting = 0; value = insertKey;
if (operation < n) { value = a[operation]; } else if (operation == n) { value = deleteKey; deleting = 1; }
tomb = -1; found = 0;
for (probe = 0; probe < 17; probe++) {
slot = (value % 17 + ((probe * (probe + 1)) >> 1)) % 17;
if (table[slot] == value) { found = 1; break; }
Nov 16, 2026
javascript
Algorithm Visualizations
Hash table linear probing: Insert keys, delete a key, insert another key, then search. Resolve collisions by linear probing; tombstones preserve search paths.…
javascript
function algorithm(a, n, deleteKey, insertKey, target, output) {
let present = Array(256).fill(0);
let table = Array(256).fill(0); let probe = 0; let slot = 0; let tomb = 0;
let value = 0; let deleting = 0; let found = 0; let length = 0; let comparisons = 0;
for (let i = 0; i < 17; i++) { table[i] = -1; }
for (let operation = 0; operation < n + 2; operation++) {
deleting = 0; value = insertKey;
if (operation < n) { value = a[operation]; } else if (operation == n) { value = deleteKey; deleting = 1; }
tomb = -1; found = 0;
for (probe = 0; probe < 17; probe++) {
slot = (value % 17 + probe) % 17;
if (table[slot] == value) { found = 1; break; }
Nov 16, 2026
javascript
Algorithm Visualizations
Hash table separate chaining: Insert keys, delete a key, insert another key, then search. Resolve collisions with bucket chains. Explore a worked example,…
javascript
function algorithm(a, n, deleteKey, insertKey, target, output) {
let present = Array(256).fill(0);
let head = Array(256).fill(0); let key = Array(256).fill(0); let next = Array(256).fill(0); let used = 0; let u = 0; let previous = 0; let bucket = 0;
let value = 0; let deleting = 0; let found = 0; let length = 0; let comparisons = 0;
for (let operation = 0; operation < n + 2; operation++) {
deleting = 0; value = insertKey;
if (operation < n) { value = a[operation]; } else if (operation == n) { value = deleteKey; deleting = 1; }
bucket = value % 17; u = head[bucket]; previous = 0;
while (u != 0 && key[u] != value) { previous = u; u = next[u]; }
if (deleting != 0 && u != 0) {
if (previous == 0) { head[bucket] = next[u]; } else { next[previous] = next[u]; } present[value] = 0;
Nov 16, 2026
javascript
Algorithm Visualizations
Held-Karp traveling salesperson: Store the cheapest path for each visited subset and final vertex, then close the tour back to vertex 0. Reconstruct an exact…
javascript
function algorithm(costs, n, output) {
let dist = Array(256).fill(0); let parent = Array(256).fill(0); let states = 1 << n; let next = 0; let candidate = 0; let best = 1000000; let end = -1; let mask = 0; let u = 0; let previous = 0;
for (let i = 0; i < states * n; i++) { dist[i] = 1000000; parent[i] = -1; }
dist[n] = 0;
for (mask = 1; mask < states; mask++) {
if ((mask & 1) == 0) { continue; }
for (u = 0; u < n; u++) {
if (dist[mask * n + u] == 1000000) { continue; }
for (let v = 1; v < n; v++) {
if ((mask & (1 << v)) == 0 && costs[u * n + v] >= 0) {
next = (mask | (1 << v)) * n + v; candidate = dist[mask * n + u] + costs[u * n + v];
if (candidate < dist[next]) { dist[next] = candidate; parent[next] = u; }
Nov 16, 2026
javascript
Algorithm Visualizations
Optimal binary search tree: Minimize weighted search cost over ordered keys, including frequencies for unsuccessful searches in every gap. Try each root for…
javascript
function algorithm(p, q, n, output) {
let cost = Array(256).fill(0); let weight = Array(256).fill(0); let s = n + 1; let j = 0; let candidate = 0;
for (let i = 0; i < s * s; i++) { output[i] = -1; }
for (let i = 0; i <= n; i++) { cost[i * s + i] = q[i]; weight[i * s + i] = q[i]; }
for (let length = 1; length <= n; length++) {
for (let i = 0; i + length <= n; i++) {
j = i + length; weight[i * s + j] = weight[i * s + j - 1] + p[j - 1] + q[j]; cost[i * s + j] = 1000000;
for (let r = i; r < j; r++) {
candidate = cost[i * s + r] + cost[(r + 1) * s + j] + weight[i * s + j];
if (candidate < cost[i * s + j]) { cost[i * s + j] = candidate; output[i * s + j] = r; }
}
}
Nov 16, 2026
javascript