Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[5 pts]: What is the worst-case big-O asymptotic running time of the following method mthd , assuming that the parameter n is a positive integer?

  1. [5 pts]: What is the worst-case big-O asymptotic running time of the following method mthd, assuming that the parameter n is a positive integer? Assume that the time complexity of addition is logarithmic in the magnitude of the number. Justify your answer.

void mthd ( int n ) {

int answer = 0;

for ( int i = 1; i <= n; i++ ) {

for ( int k = 1; k <= n; k++ ) {

answer += i + k;

}

}

for ( int m = 1; m < n; m++ ) {

answer += m;

}

}

Solution:

  1. [5 pts]: Consider that f(n) = n + n lg n is Q(n lg n) by applying the definition of Q-complexity from Chapter 3 of Cormen (reproduced below).

Definition: (g(n)) = { f(n) : there exists positive constants c1, c2, n0 such that 0 c1g(n) f(n) c2g(n) , for n n0}. Find a (c1, c2, n0) triple that meets the criteria. Show some work.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions