CSC 345 Section 4.8

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". a = b + c; d = a + e; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(1)

Determine \ThetaΘ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; for (i = 1; i ≤ n; i *= 2) for (j = 1; j ≤ n; j++) sum++; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n log n)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; for (i = 1; i ≤ n; i++) for (j = 1; j ≤ n; j *= 2) sum++; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n log n)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; for (i = 0; i < 3; i++) for (j = 0; j < n; j++) sum++; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; if (EVEN(n)) for (i = 0; i < n; i++) sum++; else sum = sum + n; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". Assume that array A contains nn values, "random" takes constant time, and "sort" takes n log n time. sum = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) A[j] = random(n); sort(A); } Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n^2 log n)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) { tmp = AA[i][j]; AA[i][j] = AA[j][i]; AA[j][i] = tmp; } Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n^2)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". sum = 0; for (i = 0; i < n * n; i++) sum++; Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n^2)

Determine Θ for the following code fragment in the average case. Assume that all variables are of type "int". Assume array A contains a random permutation of the values from 0 to n−1. sum = 0; for (i = 0; i < n; i++) { for (j = 0; A[j] != i; j++) sum++; } Θ(n^3) Θ(n^2) Θ(log n) Θ(2^n) Θ(1) Θ(n^2 log n) Θ(n) Θ(n log n)

Θ(n^2)


Kaugnay na mga set ng pag-aaral

Module One: American Political Culture and the Characteristics of the Constitution

View Set

Different EXAM FX chapter test questions pt.1

View Set

Business Finance Exam 3 Conceptual Stuff (HW & Practice Exam)

View Set

Chapter 2 (Part 2) | Mid-Term 1301

View Set

Security+ Chapter 4 Review Questions

View Set

CH 66 Management of Patients With Neurologic Dysfunction

View Set