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
djverab [1.8K]
3 years ago
5

For each of the following six program fragments: a) Give an analysis of the running time (Big-Oh will do). b) Implement the code

in the language of your choice, and give the running time for several values of N. c) Compare your analysis with the actual running times. (1) sum
Computers and Technology
1 answer:
lions [1.4K]3 years ago
8 0

Answer:

1) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++sum(n times)

++i (n times)

Total = 3n+2

O(n) is the big O notation

2) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++sum(n^2 times)

++i (n times)

j=0 ( n times)

j<n (n^2 times)

++j (n^2 times)

Total = 3n^2 + 3n+2

O(n^2) is the big O notation as we considered the maximum possible computation

3) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++sum(n^3 times)

++i (n times)

j=0 ( n times)

j<n (n^3 times)

++j (n^3 times)

Total = 3n^3 + 3n+2

O(n^3) is the big O notation as we considered the maximum possible computation

4) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++i (n times)

In the "j" th loop

j=0 ( n times)

j<i (this executes for max of n^2 times when i=n-1)

Similarly ++j (n^2 times when i=n-1)

Hence ++sum(n^2 times)

Total = 3n^2+ 3n+2

O(n^2) is the big O notation as we considered the maximum possible computation

6) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++i (n times)

In the "j" th loop

j=0 ( n times)

j<i*i(this executes for max of n^3 times when i=n-1)

Similarly ++j (n^3 times when i=n-1)

In the "k" th loop

k=0 ( max of n^3 times when j=n^3)

k<j(max of n^4 times when j=n^3)

Similarly ++k(max of n^4 times when j=n^3)

Finally ++sum ( n^4 times when j=n^3)

Total = 3n^4+ 3n^3+3n+2

O(n^4) is the big O notation as we considered the maximum possible computation

5) no of computations are :

sum =0 - (1 time )

i=0 ( 1 times)

i<n ( n times )

++i (n times)

In the "j" th loop

j=0 ( n times)

j<i*i(this executes for max of n^3 times when i=n-1)

Similarly ++j (n^3 times when i=n-1)

In the "k" th loop

k=0 ( max of n^3 times when j=n^3)

k<j(max of n^4 times when j=n^3)

Similarly ++k(max of n^4 times when j=n^3)

Finally ++sum ( n^4 times when j=n^3)

Total = 3n^4+ 3n^3+3n+2

O(n^4) is the big O notation as we considered the maximum possible computation

You might be interested in
Jeff is a financial assistant. He needs to create a document for his client that tracks her stocks and calculates the loss or ga
seropon [69]
Spreadsheet. Brainliest answer plz??
4 0
3 years ago
Read 2 more answers
What steps can be used to password-protect a worksheet?
muminat

Answer:

Review

Changes

Protect sheet

Explanation:

I did it

8 0
3 years ago
Global visibility is: Group of answer choices A visibility type where an object A has a semi-permanent reference to another obje
polet [3.4K]

Answer:

the visibility persists as long as both A and B exist.

Explanation:

Global visibility basically means that the visibility persists as long as both A and B exist. In programming global visibility signifies that the variable/data in question is visible from any context of the code. Meaning that it can be accessed and manipulated from any part of the code, even from within a function or another document. This makes it very easy to use and structure accordingly.

5 0
2 years ago
HELPPP ME PLEASEEE!!
natita [175]
It’s the last one! The key to an effective persuasion is to know what you want and be clear about your response.
4 0
3 years ago
To gain one pound of fat, how many extra calories would you need to consume?
mamaluj [8]
You'll need $3,500 extra calories to gain one pound of fat.

6 0
3 years ago
Other questions:
  • What are the example of dedicated computers?
    5·1 answer
  • Select all that apply.
    15·2 answers
  • How do emotions affect purchasing decisions?
    6·1 answer
  • Which of the following is the core of an operating system that maintains the computer’s clock, starts applications, and assigns
    5·1 answer
  • Wide area network (WAN) connects multiple networks that are in the same geographical locations.
    6·1 answer
  • When security issues are a special concern, companies want to take extra steps to make sure that transmissions can’t be intercep
    7·1 answer
  • Which of the following is NOT a data type in Python?<br> integer<br> decimal<br> string<br> float
    15·1 answer
  • A mobile application delivers market predictions based on stock data from the stock market data platform. Knowing that the data
    12·1 answer
  • Jjhb ft fv tuning Denise l Debbie
    9·1 answer
  • Sara wants to set up her lights to turn on when she arrives home. She has heard that she might be able to do this using IoT. Wha
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!