Question

Consider the following loop nest: int sum = 0; for(int j = 0; j < N...

Consider the following loop nest:

int sum = 0;
for(int j = 0; j < N * N; j += 2)
   for(int i = 2*N; i > 0; i--)
      sum++;

What is the Big-O behavior?

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

2.Consider the following loop nest:

int sum = 0;
for(int j = 1; j < N; j *= 2)
   for(int i = 0; i < N; i += 2)
      sum++;

What is the Big-O behavior?

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

3.Consider the following loop nest:

int sum = 0;
for(int j = 0; j < N; j++)
   for(int i = 2*N; i > 0; i--)
      sum++;

What is the Big-O behavior?

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

4.Which of the following step commands in Eclipse's debugger causes the code inside a method that is called to be skipped when examining the execution of a program?

Group of answer choices

step into

step over

step return

Fill in the blank: SimplePriorityQueue ___________ PriorityQueue.

Group of answer choices

is a

has a

is not related to

What should the Big-O behavior of the findMin method be?

public E findMin() throws NoSuchElementException;

/**
   * Retrieves, but does not remove, the minimum element in this priority
   * queue.
   *
   * @return the minimum element
   * @throws NoSuchElementException if the priority queue is empty
   */

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

What should the Big-O behavior of the deleteMin method be?

public E deleteMin() throws NoSuchElementException;

/**
   * Retrieves and removes the minimum element in this priority queue.
   *
   * @return the minimum element
   * @throws NoSuchElementException if the priority queue is empty
   */

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

Flag this Question

Recall that the insert method must maintain the descending, sorted order of the priority queue's backing array. Therefore, the method must first search for the correct location in which to place the new item, using a binary search. Then, the method must shift all array items at and beyond this location in order to make space for the new item.

What should the Big-O behavior of the binary search part of the insert method be?

   public void insert(E item);

   /**
   * Inserts the specified element into this priority queue.
   *
   * @param item - the element to insert
   */

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

What should the Big-O behavior of the array element shifting part of the insert method be?

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

Flag this Question

Question 101 pts

Combining the binary search and array shifting parts appropriately, what should the Big-O behavior of the entire insert method be?

Group of answer choices

O(1)

O(log N)

O(N)

O(N log N)

O(N2)

O(N3)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans: Answering first 4, if you need all the answers, post them in a set of 4

1) Let's find the complexity step by step

int sum = 0;

This loop has O(N2) as it goes from 0 to N*N and in each iteration j increases by 2 compared to its previous value

for(int j = 0; j < N * N; j += 2)     

 This is nested inside previous and has O(N), 2*N to 0 as in each iteration i decreases by 1
   for(int i = 2*N; i > 0; i--)    
      sum++;

Now the first loop is O(N2) and there is another nested loop with O(N),

So, overall Time Complexity = O(N2*N) = O(N3)

2) Let's go step by step

int sum = 0;
This loop has O(log2N) Complexity, as in each iteration j becomes 2 times of it's previous value
for(int j = 1; j < N; j *= 2) 

This loop is nested and has O(N) Complexity, as in each iteration i increases by 2 of it's previous value
   for(int i = 0; i < N; i += 2)
      sum++;

So, Overall Complexity = O(N*Log2(N) )

3) Step-By-Step

int sum = 0;
This loop has O(N) Complexity, as in each iteration j increases by 1 of it's previous value
for(int j = 0; j < N; j++)

This is nested inside previous and has O(N), 2*N to 0 as in each iteration i decreases by 1
   for(int i = 2*N; i > 0; i--)
      sum++;

So, Overall Complexity = O(N2)

4) step into - It enters to the particular method and executes it

step over - It avoids the next method call and doesn't run any code inside it.

step return - It stops the execution wherever it's being called inside a method.

So, answer is step-return

Add a comment
Know the answer?
Add Answer to:
Consider the following loop nest: int sum = 0; for(int j = 0; j < N...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for...

    Java's LinkedList class represents a doubly-linked list. What is the Big-O behavior of its addFirstmethod for a list of size N? Group of answer choices O(1) O(log N) O(N) O(N log N) Flag this Question Question 21 pts Java's ArrayList class represents a basic array. As a convenience for the user, when the capacity of the backing array is exceeded, the class handles creating a new larger array and copying over the existing items. Its add(int index, E element) method...

  • (c) int sum(int n) un { int sum=0; for (int i=0; i<n; i++) for(int j=0; j<i/2;...

    (c) int sum(int n) un { int sum=0; for (int i=0; i<n; i++) for(int j=0; j<i/2; j++) for(int k=0; k<min(j,5); k++) { sum=sum+1; } return sum; }

  • Consider the following code: Void F1 (int n) { int a; for(int i = 0; i...

    Consider the following code: Void F1 (int n) { int a; for(int i = 0; i < n; i += 2) a = i; } Which of the following characterization, in terms of n, of the running time of the above code (F1) is correct? Θ(n3/2)                   · O(1/n)                 · O(n)                     · Ω(n2) Consider the following code: Void F1 (int n) { int a; for(int i = 0; i < n; i += 2) a = i; }...

  • Big-O notation. Consider the following function. int func1(int n) { int sum = 0, i; for(i...

    Big-O notation. Consider the following function. int func1(int n) { int sum = 0, i; for(i = 0; i<n; i++;) { sum += i; return sum; } Express the running time of func1 as a function of n using big-O notation. Write a function that has the same functionality as func1, but runs in O(1) time.

  • Please answer ASAP Thank You 1Consider an algorithm that requires the following number of operations (time...

    Please answer ASAP Thank You 1Consider an algorithm that requires the following number of operations (time units) for these input sizes (n). The algorithm is ___________ . Input size Operations 100 100,000 400 100,000 1600 100,000 Group of answer choices 1.O(n2) 2.O(n) 3.O(log n) 4.O(n3) 5.O(1) 2The below algorithm contains nested loops. for (int total = 1; total <= n; total++) { for (int samples = 0; samples < n; samples++) { for (int location = 1; location < 10;...

  • #9 What is time complexity of fun()? int fun(int n) {   int count = 0;   for...

    #9 What is time complexity of fun()? int fun(int n) {   int count = 0;   for (int i = n; i > 0; i /= 2)      for (int j = 0; j < i; j++)         count += 1;   return count; } Group of answer choices O(n^2) O(nLogn) O(n) O(nLognLogn)

  • Show the Big O Complexity of the following functions and loop constructions: (Please show work and...

    Show the Big O Complexity of the following functions and loop constructions: (Please show work and explain) a. f(n) = 2n + (blog(n+1)) b. f(n) = n * (log(n-1))/2 c. int sum = 0; for (int i=0; i<n; i++) sum++; for (int j=n; j>0; j /= 2) sum++; d. int sum = 0; for (int i=n; i>0; i--) for (int j=i; j<n; j *= 2) sum++;

  • Array manipulation (a) Write Java code for a method exchange (int [] a, int i, int...

    Array manipulation (a) Write Java code for a method exchange (int [] a, int i, int j) that exchanges the values stored at indices i and j in the array a. You do not need to worry about cases where either i or j is an invalid index. Give the best estimate you can for its time complexity (b) In an ordered array of n items, how can we determine whether or not an item belongs to the list using...

  • 4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode...

    4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. howing your work is not required (although showing work may allow some partial t in the case your answer is wrong-don't spend a lot of time showing your work.). You MUST choose your answer from the following (not given in any particular order), each of which could be re-used (could be the answer for...

  • Which big-O expression best characterizes the worst case time complexity of the following code? public static...

    Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT