I know that this loop is O(n^2) but what is Big-Omega and Big-Theta? How do you go about calculating them in situations like these?
for(i = 0; i < array.length; i++)
for (j = 0; j < array.length; j++)
//bla bla
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.
For starters, see larsmans’ comment. The loop logic is not necessarily trivial enough to exclude. Let’s say for argument’s sake that you’re confident that the loop logic will be not break out, that the logic is trivial (i.e. no conditional paths affecting the work performed), and that you are defining your unit of work to be the total logic performed in one pass through the loop.
In this case, your upper and lower bounds are the same. You are guaranteed to execute at least, and at most, on the order of N^2 units of work. You have a
Ω(N^2), and aO(N^2). Your lower and upper bounds are identical; you can characterizeΘ(N^2).It bears mentioning again that this is pointless if the loop logic is non-trivial and is especially dependent on what you are actually defining as a unit of work. The point of these notations is to characterize an expected amount of work to be incurred by an algorithm. You can iterate through a loop millions of times, but that doesn’t affect this notation if the work you really care about is how many times
SomeExpensiveFunction()is called within that loop, and the logic dictates that it is only called once.