0
$\begingroup$

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

while (...) {
   while (...) {
   }
   while (...) {
   }
}
New contributor
CSSSSS is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\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 2 days ago
  • $\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 2 days ago

Your Answer

CSSSSS is a new contributor. Be nice, and check out our Code of Conduct.

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.