alculate the time complexity for the following function in terms of Big O notation. Explain your answer. [Note: Line numbers are only for reference purpose] int fun(int n) { 1 int count = 0; 2 for (int i = n; i >= 0; i /= 2) 3 count += i; 4 for (int j = 0; j < n; j++) 5 count +=j; 6 return count; }
alculate the time complexity for the following function in terms of Big O notation. Explain your answer. [Note: Line numbers are only for reference purpose] int fun(int n) { 1 int count = 0; 2 for (int i = n; i >= 0; i /= 2) 3 count += i; 4 for (int j = 0; j < n; j++) 5 count +=j; 6 return count; }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Calculate the time complexity for the following function in terms of Big O notation. Explain your answer.
[Note: Line numbers are only for reference purpose]
int fun(int n)
{
1 int count = 0;
2 for (int i = n; i >= 0; i /= 2)
3 count += i;
4 for (int j = 0; j < n; j++)
5 count +=j;
6 return count;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps