1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
torisob [31]
4 years ago
10

Give a big-O estimate the number of operations, where an operation is a comparison or a multiplication, used in this segment of

an algorithm (ignoring comparisons used to test the conditions in the for loops, where a1, a2, . . . , an are positive real numbers)
Computers and Technology
1 answer:
ki77a [65]4 years ago
6 0

Answer and Explanation:

For the first iteration of i for loop 1 to n, the j for loop will run from 2 to n times. i.e. n-1 times.

For the second iteration of i for loop, the j for loop will run from 3 to n times. i.e. n-2 times.

From the third to the last iteration of i for loop, the j for loop will run n-1 to n times. i.e. 2 times.

From the second to the last iteration of i for loop, the j for loop will run from n to n times. i.e. 1 time.

For the last iteration of i for loop, the j for loop will run 0 times because i+1 >n.

Hence the equation looks like below:

1 + 2 + 3 + ...... + (n-2) + (n-1) = n(n-1)/2

So the number of total iterations is n(n-1)/2.

There are two operations per loop, i.e. Comparison and Multiplication, so the iteration is 2 * n(n-1)/2 = n ^2 - n

So f(n) = n ^ 2 - n

f(n) <= n ^ 2 for n > 1

Hence, The algorithm is O(n^2) with C = 1 and k = 1.

4) Suppose n = 1, then i = 2

n = 2, then i = 4

n = 3, then i = 6

n = 4, then i = 8

So the value of i is doubled for each iteration of while loop.

So i = 2 ^ n

i is growing at the rate of a power of 2, so the number of operations is log(2n)

Hence the algorithm is O(log(n)).

You might be interested in
What term best describes the way the dns name space is organized?
Andreyy89
The answer would be hierarchical
 <span />
6 0
3 years ago
Forwarded events can only be recorded when systems ADMINISTRATORS have de-established an event subscription. TRUE or FALSE
weeeeeb [17]

Answer:

True

Explanation:

Forwarded events can only be recorded when systems administrators have de-established an event subscription.

8 0
3 years ago
Write two statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a slash, and
Montano1993 [528]

Answer:

1/2000

Explanation:

import java.util.Scanner;

public class InputExample {

public static void main(String [] args) {

Scanner scnr = new Scanner(System.in);

System.out.print("Enter birth month and date:");//comment this line if not needed

int birthMonth=scnr.nextInt();

int birthYear=scnr.nextInt();

String output= birthMonth+"/"+birthYear+"\n";

System.out.println(output);

}

}

if using this code the out put should be 1/2000

5 0
3 years ago
Media messages are communicated through which of the following:
LenaWriter [7]
All of the above is the answer
3 0
4 years ago
Read 2 more answers
Difference between RAM and CPU
frozen [14]

The main difference between the RAM and the CPU is the roles they play in a computer. The CPU is the actual part that does the computing while the RAM only holds the data.

4 0
4 years ago
Other questions:
  • An important piece of a project is past due date.
    9·2 answers
  • Enter a nested lookup function in cell E4 that uses the cells E2 and E3 to return a specific sales record. For example, using th
    14·1 answer
  • What could be one possible reason where the recipient is not guaranteed that the data being streamed will not get interrupted?
    15·1 answer
  • Mrs. Patel uses a computer program to balance her checkbook. Which of the following best explains how the
    13·1 answer
  • Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin
    13·1 answer
  • UML is a graphical language that is used for designing and documenting software created within the _____________ framework. (a)
    9·1 answer
  • Which of the following trims would be used at the beginning of a scene?
    12·1 answer
  • You are hired by a game design company and one of their most popular games is The Journey. The game has a ton of quests, and for
    12·2 answers
  • Im a beginner programmer. what languages should i learn and how do i get better
    13·1 answer
  • "Use onblur and onfocus to add red borders to the input elements when the user leaves without any input, and a green border if a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!