Knowee
Questions
Features
Study Tools

1. Consider the algorithm:procedure giaithuat(a1, a2, …, an : integers)count:= 0for i:= i to n doif ai > 0 then count: = count + 1print(count)Give the best big-O complexity for the algorithm above

Question

  1. Consider the algorithm:procedure giaithuat(a1, a2, …, an : integers)count:= 0for i:= i to n doif ai > 0 then count: = count + 1print(count)Give the best big-O complexity for the algorithm above
🧐 Not the exact question you are looking for?Go ask a question

Solution

Độ phức tạp tốt nhất của thuật toán trên là O(n).

Similar Questions

Consider the algorithm:procedure GT(n : positive integer)F:=1for i:= 1 to n doF: = F * iPrint(F)Give the best big-O complexity for the algorithm above.

The following algorithm:for i in range(n): # from 0 to n-1 for j in range(i) # from 0 to i-1 s += i * log(j)has a complexity inSelect one:a. O( n log(n) )b. O(n)c. O(n^2)d. O(1)e. O(n/2)

If the efficiency of the algorithm doIt can be expressed as O(n) = n2 , cal-culate the efficiency of the following program segment:for (i = 1; i <= n;; i++)for (j = 1; j < n, j++)doIt (...)

Which of the following sorting algorithm has best case time complexity of O(n2)?ans.

What is the time complexity of this function / algorithm?void f(int n){ int i; for (i = 0; i < n; i++) { printf("[%d]\n", i); }}O(n)O(1)O(log(n))O(nlog(n))O(2^n)O(n!)O(n^2)

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.