I know that complexity of two serial loops with the same number of iterations is O(n), as stated here, but what if the loops are based on different inputs? for example:
for(i;i<m;i++){
//code
}
for(y;y<n;y++){
//code
}
It would be O(m+n)?
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.
Yes, absolutely 🙂
The first loop, if it’s not empty, has a multiple of
moperations.The second loop has a multiple of
noperations.Using both one after the other gives you
O(m+n).