Knowee
Questions
Features
Study Tools

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.int F(int n)if (n <= 2)return 1elsereturn F(n − 2) * F(n − 2)a.O(2^(n/2))b.O(2^n)c.O(n^2)d.O( n )

Question

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.int F(int n)if (n <= 2)return 1elsereturn F(n − 2) * F(n − 2)a.O(2^(n/2))b.O(2^n)c.O(n^2)d.O( n )

🧐 Not the exact question you are looking for?Go ask a question

Solution

Đoạn mã giả trên có độ phức tạp là O(2^n).

Giải thích: Hàm F(n) gọi đệ quy tới hàm F(n-2) hai lần. Do đó, số lượng phép tính cần thực hiện tăng lên theo cấp số nhân, tức là 2^n.

Vì vậy, đáp án chính xác là b. O(2^n).

Similar Questions

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.int func(int n)if (n <= 1)return 0elsereturn func(n/2) + 1a.O(n^2)b.O(nlogn)c.O( n )d.O(logn)Clear my choice

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.int fun(int n)if (n <= 1)return nreturn fun(n − 1) + fun(n − 1)a.O(2^n)b.O(2^(n/2))c.O(n^2)d.O( n )Clear my choice◄ Lab2 - Divide and Conquer

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.s = 0for (i = 1; i <= n; i *= 3)s = s + a[i]a.O( n )b.O(n^2)c.O(logn)d.O(nlogn)Clear my choice

Cho biết độ phức tạp của đoạn mã giả sau dùng ký hiệu big-O.x = 0for i <- 1 to n dox++a.O(n^2)b.O(logn)c.O(nlogn)d.O( n )Clear my choice◄ Lab2 - Divide and Conquer

Suppose, for now, that n is a power of 2. An easy way of doing so is theexpansion method, which simply expands f (n) all the way down:f (n) ≤ c2 + f (n/2)≤ c2 + c2 + f (n/22)≤ c2 + c2 + c2 + f (n/23)≤ c2 + ... + c2| {z }log2 n of them+f (1)= c2 · log2 n + c1 = O(log n).Yufei Tao Recursion

1/2

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.