Master Methode MATHLAB ?

7 views (last 30 days)
alkadjfkl
alkadjfkl on 20 Jun 2024
Commented: Ganesh on 20 Jun 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 Comment
Ganesh
Ganesh on 20 Jun 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

Sign in to comment.

Answers (0)

Categories

Find more on Elementary Math in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!