Question

Given the following algorithm, matching each statement to the correct sequence for complexity analysis. procedure Alg3(A):...

Given the following algorithm, matching each statement to the correct sequence for complexity analysis.

procedure Alg3(A): A is a list of n integers

1 for i = 1 to n-1 do

2   x=aix=ai

3 j = i − 1

4 while (j ≥≥ 0) do

5 if x≥ajx≥aj then

6 break

7 end if

8   aj+1=ajaj+1=aj

9 j = j − 1

a end while

b   aj+1=xaj+1=x

c end for

d return A

The complexity of this algorithm is O(n2)O(n2)

Respuesta 1Elegir...1572634

The inner loop is a while loop for variable jj and the number of iterations is i−1i−1 in the worst case.

Respuesta 2Elegir...1572634

The outer loop is a for loop for variable ii and the number of iterations is n−1n−1.

Respuesta 3Elegir...1572634

In each iteration in the inner loop, there are 2 operations.

Respuesta 4Elegir...1572634

We consider comparison as the operation to be analyzed

Respuesta 5Elegir...1572634

There are at most 2×(1+2+⋯+(n−1)+2(n−1)+12×(1+2+⋯+(n−1)+2(n−1)+1 operation.

Respuesta 6Elegir...1572634

The pseudocode contains a nested loop.

Respuesta 7Elegir...1572634

Homework Answers

Answer #1

If you like th solution please give it a thumbs up.

Solution :- Clearly, text in the question in gambled, but i can understand the steps. below i've ordered the time complexity analysis according to the given code.

- The pseudocode contains a nested loop.

- The outer loop is a for loop for variable i and the number of iterations is n−1.

- The inner loop is a while loop for variable j and the number of iterations is i−1 in the worst case.

- In each iteration in the inner loop, there are 2 operations.

- We consider comparison as the operation to be analyzed

-  There are at most 2×(1+2+⋯+(n−1)+2(n−1)+1 operation.

- The complexity of this algorithm is O(n2).

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
Determine the order of complexity for the following algorithm: function(int n) { int l, u, m;...
Determine the order of complexity for the following algorithm: function(int n) { int l, u, m;    l=0; u= n-1;    while (l<u) {        m= (l+u)/2;        if (a[m] < x) l= m+1;        else if (a[m] >x) u=m-1;            else return “found”    }    return (“not found”); }
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT