Last Updated : 16 May, 2019
What is the time complexity of fun()?
C
int
fun(
int
n)
{
int
count = 0;
for
(
int
i = 0; i < n; i++)
for
(
int
j = i; j > 0; j--)
count = count + 1;
return
count;
}
(A)
Theta (n)
(B)
Theta (n2)
(C)
Theta (n*log(n))
(D)
Theta (n*(log(n*log(n))))
Answer: (B)
Explanation:
The time complexity can be calculated by counting the number of times the expression “count = count + 1;” is executed. The expression is executed 0 + 1 + 2 + 3 + 4 + …. + (n-1) times.
Time complexity = Theta(0 + 1 + 2 + 3 + .. + n-1) = Theta (n*(n-1)/2) = Theta(n2)
Quiz of this Question
Please comment below if you find anything wrong in the above post
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...
FAQs
Dynamic programming algorithms: These algorithms are used to solve problems by breaking them down into smaller, simpler subproblems and solving them iteratively. Recursive algorithms: These algorithms are designed to solve problems by breaking them down into smaller, similar problems.
What is an algorithm 2? ›
An algorithm is a set of commands that must be followed for a computer to perform calculations or other problem-solving operations.According to its formal definition, an algorithm is a finite set of instructions carried out in a specific order to perform a particular task.
What are the fundamentals of the analysis of algorithm? ›
Fundamentals of the Analysis of Algorithm Efficiency — The Analysis Framework. There are three notations: O (“big oh”), (“big omega”), and (“big theta”). There are two kinds of efficiency: Time efficiency, also called time complexity, indicates how quickly an algorithm runs.
What is an algorithm in data analysis? ›
An algorithm in data mining (or machine learning) is a set of heuristics and calculations that creates a model from data. To create a model, the algorithm first analyzes the data you provide, looking for specific types of patterns or trends.
What are 2 main types of machine learning algorithm? ›
But for now, humans and data will continue to play a critical role in shaping machine-driven predictions. There are two main methods to guide your machine learning model—supervised and unsupervised learning.
What is the divide by 2 algorithm? ›
The Divide by 2 algorithm assumes that we start with an integer greater than 0. A simple iteration then continually divides the decimal number by 2 and keeps track of the remainder. The first division by 2 gives information as to whether the value is even or odd. An even value will have a remainder of 0.
What are the three principles of algorithms? ›
An algorithm is made up of three basic building blocks: sequencing, selection, and iteration. Sequencing: An algorithm is a step-by-step process, and the order of those steps are crucial to ensuring the correctness of an algorithm.
How to test an algorithm? ›
Algorithm testing involves unit and integration testing to verify individual components and their interactions. Techniques like boundary value analysis, equivalence partitioning, and performance testing ensure the algorithm's correctness, robustness, and efficiency.
What are the 3 algorithm analysis techniques? ›
In Sections 1.3 through 1.6, we explore three important techniques of algorithm design—divide-and-conquer, dynamic programming, and greedy heuristics.
What is algorithm in simple words? ›
An algorithm is a procedure used for solving a problem or performing a computation. Algorithms act as an exact list of instructions that conduct specified actions step by step in either hardware- or software-based routines. Algorithms are widely used throughout all areas of IT.
Search algorithms are strategies or methods used to find specific data within a data structure. They can either be sequential (linear search) or interval-based (binary search).
What are the 2 methods of representing algorithms? ›
Algorithms are step-by-step plans for solving problems. They can be designed using pseudo-code and flowcharts.
What are the 2 kinds of algorithm efficiency? ›
The correct answer is Space efficiency and Time efficiency.