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
What is computer ????
LekaFEV [45]

Answer:

Explanation:

A computer is a device that manipulates information, or data accrding to the instructions given to it and give us an output. It has the ability to store, retrieve, and process data.

6 0
4 years ago
write an expression taht evaluated to true if and only if the variable s does not contain the string 'end'
natima [27]

Answer:

//check which string is greater

if(strcmp(name1,name2)>0)

//assign name1 to first, if the

    //name1 is greater than name2

    first=name1;

else

    //assign name2 to first, if the

    //name2 is greater than name1

    first=name2;

5)

//compare name1 and name2

    if(strcmp(name1,name2)>0)

   

         //compare name1 and name3

         if(strcmp(name1,name3)>0)

       

             //assign name1 to max, becuase

             //name1 is greater than name2 and name3

             max=name1;

       

Explanation:

7 0
3 years ago
he Correct Coding Initiative (CCI) edits contain a listing of codes under two columns titled, "comprehensive codes" and "compone
iragen [17]

Answer:

The answer is "Option C"

Explanation:

The content management system promotes the accurate coding technique, which is used to monitor incorrect encoding, in which the comprehensive code is used, that compiles the code to defining or covering two or more CPT part code, packaged as one package, that's why "option c" is correct and other were wrong which can be defined as follows:

  • In option A, It is wrong because code can't be a component code.
  • Option B and Option D is wrong because it uses a comprehensive code only.

7 0
3 years ago
Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5.
Minchanka [31]

Answer:

M2 is the answer for the above question.

Explanation:

  • The above question states the scenario, where firstly main function calls the M1 function.
  • Then M1 function calls the function M2.
  • Then M2 function calls the function M3.
  • Then M3 function calls the function M5.
  • Then Again M2 function will resume and calls the function M4.
  • Then Again M2 function will resume because when the M4 will ends it return to the statement of the M2 function from which the M4 function has been called.
  • It is because when any function ends its execution it returns to that line of a statement from which it has been called. This is the property of programming language to call the function.
  • So when the M4 will terminate its execution then the M2 function will resume again.
4 0
3 years ago
What was the first general purpose, programmable, electronic computer?.
ryzh [129]

Answer:

ENIAC: first general-purpose electronic computer.

Explanation:

6 0
3 years ago
Other questions:
  • Look at the following array definition:
    11·1 answer
  • Presentation aids should include short phrases or images to convey your message.
    6·1 answer
  • What is computer hacking? describe some examples
    6·1 answer
  • What can be designed to create annoying glitches or destroy data
    15·2 answers
  • The power we use at home has a frequency of 60 HZ. What is the time period of such a power?
    10·1 answer
  • What does it mean when a computer can't break the rules
    10·2 answers
  • When your grounded and the only thing you can get on is a computer........................oh welllllllllllllllllllllllllllllllll
    7·1 answer
  • This isn't school related but if I get a 2 month free plan and it is expired and I don't have a card attached to my account will
    14·1 answer
  • Please help me with computing!
    12·1 answer
  • The best team in nba like right now
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!