Question

JAVA - algorithm analysis and sorting Question 1 Which of the following features grows fastest? 1....

JAVA - algorithm analysis and sorting

Question 1

Which of the following features grows fastest?

1. N2

2. log N

3. N log N

4. N

5. 10

Question 2

Given the following code segment:
for( int i = 1; i < n; i++ )
  for( int j = 1; j < i; j++ ) 
    k = k + i + j; 
What is the runtime of the code segment?
1. None of the above 

2. O(i*N)

3. O(N2)

4. O(N4)

5. O(N)

Question 3

The runtime for the following code is:

for (i = 1; i <= n; i++) { 
    for (j = 1; j <= n-1; j++) { 
    k = k + i + j; 
  } 
}  
for (i = 1; i <= n; i++) { 
   m = m + i; 
}

1. O(N2 + N)

2. O(N3)

3. O(N)

4. O(N2)

Question 4

Analyzing algorithm efficiency is

1. To estimate execution time

2. To measure exact execution time

3. To find the average driving time

4. To estimate the degree of growth in the form of a function

Question 5

Which of the following complexities is nlogn

1. 23nlogn + 50

2. 23n + 68logn

3. 45n + 45nlogn + 503

4. 300n + 400n*n

5. n*n*n + nlogn

Question 6

The approach searches incrementally for a candidate. As soon as one finds out that this will not provide a solution, look for a new candidate.

The approach is called. ( several answers possible)

1. Backtracking

2. Recursion

3. Divide-and-conquer

4. Brute-force

5. Dynamic programming

Homework Answers

Answer #1
Question 1
N2 features grows fastest
Answer:
1. N2

Question 2
Runtime of the code segment is O(N2)
Answer:
3. O(N2)

Question 3
Runtime of the code segment is O(N2)
Answer:
4. O(N2)

Question 4
Analyzing algorithm efficiency is To estimate the degree of growth in the form of a function
Answer:
4. To estimate the degree of growth in the form of a function

Question 5
23nlogn + 50, 45n + 45nlogn + 503 are of complexities nlogn
Answer:
1. 23nlogn + 50
3. 45n + 45nlogn + 503

Question 6
The approach searches incrementally for a candidate. As soon as one finds out that this will not provide a solution, look for a new candidate.
The approach is called Backtracking
Answer:
1. Backtracking

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Java) For the following code segment, match the different values of the empty line with the...
(Java) For the following code segment, match the different values of the empty line with the resulting Big O complexity of the algorithm. int n = int k = 0; for (int i=0; i <= n; i++){ int j = i; while (j > 0) { // ___MISSING CODE___ k++; } } j = 0; j--; j /= 2; j = j * 2; Options for each are: O(n^3)            O(n * log n)            an...
Answer the following questions: 1. Given the code segments below with n as the problem size,...
Answer the following questions: 1. Given the code segments below with n as the problem size, answer the following questions: //Code Segment 1 (Consider n as a power of 3) int sum = 0; for(int i = 1; i <= n; i = i*3) sum++;​​​​​​​// statement1 //Code Segment 2: (Consider both possibilities for x) if(x < 5){ for(int i = 1; i <= n; i++)    for(int k = 1; k <= i; k++)    sum++;​​​​​// statement2 } else{ for(int...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm...
How to measure the time complexity of an algorithm? Identify an important operation in the algorithm that is executed most frequently. Express the number of times it is executed as a function of N. Convert this expression into the Big-O notation. A. For each of the three fragments of code, what is its worst-case time complexity, in the form "O(…)". (Use the given solution to the first problem as a model)                 //----------------- This is a sample problem – solved ------...
This is python questions 1.An algorithm to solve this computation problem must be written using a...
This is python questions 1.An algorithm to solve this computation problem must be written using a programming language. a.True b.False 2.O(N) is called __________ complexity. a.Constant b.Linear c.Quadraic d.Exponential 3. A fast sorting algorithm is a sorting algorithm that has an average runtime complexity of __________ or better. a.O(N2) b.O(N1.5) c.O(NlogN) d.None of these 4.A(n)_________ describes a sequence of steps to solve a computational problem or perform a calculation. a.permutation b.statement c,algorithm d.formula
I found a scrap of paper with this Java implementation of a sorting algorithm on it:...
I found a scrap of paper with this Java implementation of a sorting algorithm on it: // This will get me the Turing Award for sure!! public static void sort (int[] A) { sort(A, 0, A.length); } // Sorts the subarray A[lo .. hi-1] into ascending order private static void sort (int[] A, int lo, int hi) { int size = hi - lo; if (size == 2) { if (A[lo] > A[lo+1]) { int temp = A[lo]; A[lo] =...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!! QUESTION 1 What is the output after the code executes? Assume there are no syntax errors and the code will compile. int x = 10; do { System.out.println ( x ); x -= 3; } while (x > 0); A. 10 7 4 1...
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n...
2. Design a deterministic algorithm to solve the following problem. input: An array A[1...n] of n integers. output: Two different indices i and j such that A[i] = A[j], if such indices exist. Otherwise, return NONE. Your algorithm must take O(n log(n)) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(n log(n)).
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum = 0; for (int i = 0; i < 100; i++) { sum += array[i]; } return sum; } 2. int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { sum++; sum++; } } for (int i = 0; i < n; i += 2) { sum++; } 3. nt...
1.) Answer the following questions based on the following pseudocode for the function “foo”: Algorithm 1:...
1.) Answer the following questions based on the following pseudocode for the function “foo”: Algorithm 1: foo mystery() foreach i ←1 to n do mystery() foreach j ←1 to i do (A) Determine the exact number of times mystery() is called in terms of n. (B) Assume the mystery function is in O(log(n) ∗ n ^2 ). Determine the complexity of “foo” in O-notation. if i ≤ j then mystery()
Consider the following function: 01: void cpUniq (const int* source, int N, vector<int>& dest) 02: {...
Consider the following function: 01: void cpUniq (const int* source, int N, vector<int>& dest) 02: { 03: list<int> L; 04: for (int i = 0; i < N; ++i) 05: { 06: copy (source, source + i, front_inserter<int>(L)); 07: } 08: for (int j: L) 09: { 10: if (find(dest.begin(), dest.end(), j) != dest.end()) 11: dest.push_back(j); 12: } 13: } and the following list of complexity values: A: O(1), B: O(log N), C: O(N), D: O(N log N), E: O(N2),...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT