Master Methode MATHLAB ?

7 vues (au cours des 30 derniers jours)
alkadjfkl
alkadjfkl le 20 Juin 2024
Commenté : Ganesh le 20 Juin 2024
function T = master_method(a, b, k)
% Master Method to solve recurrence T(n) = a * T(n/b) + n^k
% Check input values
if a <= 0 || b <= 1 || k < 0
error('Invalid input values: a must be positive, b must be greater than 1, and k must be non-negative.');
end
% Base cases of the Master Method
if k > log(b) / log(a)
% Case 1: T(n) = Θ(n^k)
T = 'Θ(n^k)';
elseif k == log(b) / log(a)
% Case 2: T(n) = Θ(n^k * log(n))
T = 'Θ(n^k * log(n))';
else
% Case 3: T(n) = Θ(n^(log_b(a)))
T = 'Θ(n^(log_b(a)))';
end
% Display the asymptotic time complexity
disp(['The asymptotic time complexity T(n) is: ', T]);
end
% Beispielaufrufe
master_method(6, 6, 1);
master_method(3, 2, 2);
master_method(2, 3, 1);
  1 commentaire
Ganesh
Ganesh le 20 Juin 2024
Define the function at the end.
master_method(6, 6, 1);
master_method(3, 2, 2);
master_method(2, 3, 1);
function T = master_method(a, b, k)
.....
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by