Algorithms | Analysis of Algorithms | Question 2 - GeeksforGeeks (2024)

Table of Contents
C Please Login to comment...

Last Updated : 16 May, 2019

What is the time complexity of fun()?

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

Algorithms | Analysis of Algorithms | Question 2 - GeeksforGeeks (2024)
Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6430

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.