Skip to main content
fade2black's user avatar
fade2black's user avatar
fade2black's user avatar
fade2black
  • Member for 7 years, 6 months
  • Last seen more than a week ago
  • Berlin, Germany
comment
Algorithm complexity of this program is O(n) or O(n^3)?
Statement; j++ is invoked $n$ times (total!), and the second for-loop increments $i$ $n$ times (total!), and the outer for-loop increments $i$ only once after which it quits since $i$ reaches $n$ (by the second for-loop). This gives $n+n +1= 2n+1$ which is $O(n)$.
comment
Algorithm complexity of this program is O(n) or O(n^3)?
The inner for-loop starts from $i=0$ and runs until $i=n$.Statement; j++ is executed $n$ times for only $i=0$ and never executed for $i>0$. The outer for-loop runs only once for $i=0$. You could observe it by running this code.
comment
Algorithm complexity of this program is O(n) or O(n^3)?
In fact $O(n^3)$ is not a wrong answer, but $O(n)$ is tighter bound. Three loops does not necessary imply cubic time. Please pay attention to variables used in the for-loops. In particular, is it true that the outermost for-loop always runs $n$ times? How many times is j++ invoked?
revised
Loading…
comment
Algorithm complexity of this program is O(n) or O(n^3)?
First of all please replace the image with text (source code). Second, what is your version? Why do you think it should be $O(n^3)$ and not $O(n^)$? Please include it in your post.
comment
Loading…
comment
Regular expression for the language containing neither aa nor bb
or $b, ba, bab, baba, \dots$. Kleene closure of something.
comment
Are time complexity of followng codes equivalent?
Programming questions are off topic here.
comment
Comparison of Depth First Search Trees
How do you define "similarity" between two trees?
revised
Is it possible to prove Turing irreducibility
added 150 characters in body
Loading…
answered
Loading…
reviewed
Approve
reviewed
Approve
reviewed
Approve
comment
Complexity of computing the antiderivative of a given function
What do you mean by "the computational complexity of a function"? Is it complexity of an algorithm that computes the function $f(x)$?
1
3 4
5
6 7
105