How would you find a T(n) run-time (not the big O run time) for a function that has two inputs? Do you just consider the a input your ‘n’?
int h(int a, int b) {
if (a > 0) {
return h(a-1, a+b);
}
else {
return 0;
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this case we just need to consider
asince the length of this algorithm isn’t dependent on b.In other words since we can pass in 20000 or -2 for b and not impact our time in the slightest (ignoring the actual time of adding
a+b) we shouldn’t have to consider b in our calculations.In a more general case, if the input did depend on
aandbwe would simply account for this in our time complexity function. In other words it would beT(a, b)not justT(a).