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

Question

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
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

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

Giải thích: Trong vòng lặp, biến i được nhân lên 3 lần sau mỗi lần lặp. Điều này có nghĩa là số lần lặp sẽ tăng lên theo hàm logarit cơ số 3 của n. Do đó, độ phức tạp thời gian của đoạn mã giả này là O(logn). Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem. Knowee AI StudyGPT is a powerful AI-p

ed study tool designed to help you to solve study problem. Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem. Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem. Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem. Knowee AI StudyGPT is a p

This problem has been solved

Similar Questions

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.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 )

What is the time complexity of searching for an element in a circular linked list?Select one:a.O(n)b.O(nlogn)c.O(1)d.O(n2)

What is the space complexity for deleting a linked list?Select one:a.O(1).b.O(n).c.Either o(1) or o(n).d.O(logn).

What is the best and worst case complexity of ordered linear search?O(nlogn), o(logn)O(logn), O(nlogn)O(n), O(1)O(1), O(n)

1/3