0
$\begingroup$

would the code below be considered O(N^3)?

while (...) {
   while (...) {
   }
   while (...) {
   }
}
$\endgroup$
  • 2
    $\begingroup$ Are you asking what do various $O(n^3)$ algorithms look like? There are plenty of reasons to have cubic upper bound on the number of operations, which may or may not manifest themselves in the structure of while/for loops. $\endgroup$ – Dmitri Urbanowicz Mar 26 '20 at 7:16
  • $\begingroup$ It also depends on what $n$ is. If each loop is executed $n$ times at worst case then your algorithm is $O(n^2) $. But you can't tell just by looking ag the structure of the program $\endgroup$ – melfnt Mar 26 '20 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.