MakarovSuites
English
EnglishDeutschРусскийУкраїнськаFrançaisEspañolItalianoPolski
Contact & licences

Math

Knapsack: greedy against the table

Choose numbered cargo under a mass limit. Compare your selection with greed and the exact solution, open a table cell and trace the optimal set backwards.

Knapsack: greedy against the table — Actual application image
Actual application image

What happens

Choose numbered cargo under a mass limit. Compare your selection with greed and the exact solution, open a table cell and trace the optimal set backwards. T(i,c): best value using only the first i items and capacity c. Click a cell; blue skips, green takes. Arrows page through a large table. w = weight, v = value. Cargo size is decorative; only total weight limits the bag. Fractional is an upper bound for a different task where items may be cut. It is not another feasible 0/1 selection.

Equations used in the module
Equations
0/1: sum(w_i x_i) <= W; max sum(v_i x_i), x_i in {0,1}
T(0,c) = 0
w_i > c: T(i,c) = T(i-1,c)
w_i <= c: T(i,c) = max(T(i-1,c), v_i + T(i-1,c-w_i))
v_i/w_i ↓; i ↑
F_greedy <= F_0/1 <= F_fractional
V_single = max({0} ∪ {v_i : w_i <= W})
max(F_greedy, V_single) >= F_0/1 / 2
N_DP = n*W; N_subsets = 2^n

Related experiments

Back to catalogue
Simplex on the plane — Actual application image

Math

Simplex on the plane

The feasible region lies on the table and a plate hangs over it at the height of the objective. The objective is linear, so the plate is flat and tilted, and the best point is literally its highest corner. The simplex climbs the edges to it.

The Turing machine and the busy beavers — Actual application image

Math

The Turing machine and the busy beavers

A paper tape between two reels, a metal head with a state lamp, and a table of rules. Every step plays as read, write, move, next state; the journal below holds the whole run, and an edited rule keeps the old run as a ghost. The records are found by enumerating every machine, not quoted.

Fourier, a period, and a factor — Actual application image

Math

Fourier, a period, and a factor

Compare a peak with its neighbour. Then measure: a peak suggests a denominator, not a guaranteed factor. Ideal CPU simulation, 12 qubits; no noise or physical device. N=21 uses Q=128 < N²: reduced precision. Coprime bases only; otherwise gcd(a,N) already finds a factor.