Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following pieces of code, choose the Big O complexity. (If there is more than one option, circle the tightest asymptotic bound.) Give a

Given the following pieces of code, choose the Big O complexity. (If there is more than one option, circle the tightest asymptotic bound.)

Give a 1-2 sentence explanation of your reasoning.

a)

p = 1;

for (int j=0; j < n; j++) {

if (a[j] != 0) {

p = p * a[j];

}

} return p;

where n is a positive integer and array a[] has all float values. i) O(1) ii) O(n) iii) O(n2)

iv) O(log n) b)

bool isUndirected (int n, float **a) {

bool result = true;

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

for (int j = 0; j < n ; j++) {

if ( (i != j) && (a[i][j] != a[j][i])) {

result = false;

}

}

} return result;

}

where n is a positive integer and the 2D matrix a[ ][ ] has all float values. i) O(1) ii) O(n) iii) O(n2)

iv) O(log n) c) float p1 = 1;

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

if (a[i] < 0) {

p1 = p1 * a[i];

}

}

float p2 = 1;

for (int j=0; j < n; j++) {

if (a[j] > 0) {

p = p * a[j];

}

} float pp = (abs(p1) > p2)? abs(p1) : p2;

return pp;

i) O(1) ii) O(n) iii) O(n2)

iv) O(log n)

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

LO 14-8 How to plan for a successful career.

Answered: 1 week ago

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago