Master Methode MATHLAB ?
조회 수: 7 (최근 30일)
이전 댓글 표시
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
Ganesh
2024년 6월 20일
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
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!