Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 4, Problem 60P

Explanation of Solution

Experimental analysis for prefixAverage1:

With the reference to the textbook, the prefixAverage1 algorithm computes the prefix averages in quadratic time O(n2). Now let us take the given algorithm from the textbook for analysis to draw the visualization representation as follows:

Algorithm: prefixAverage1(X,n)

Input: array x on n integers

Output: Array A of prefix averages of X

//Line1

A<- new array of n integers

//Line2

for i<-0 to n-1 do

//Line3

S<-X[0]

//Line4

for j<-1 to i do

//Line5

S<-S+X[j]

// Line6

A[i]<-s/(i+1)

//Line7

return A

Explanation:

In the above algorithm,

  • The Line1 is to initialize the array of "n" integers and it takes O(n) time.
  • Next the Line2 is the outer for loop which act as counter and executed "n" number of times and it takes O(n) times to complete the loop.
  • The Line3 is assigning the initial element of array to variable "s" and this executes in O(n) time.
  • Line4 is the inner body of for loop executes based on the outer for loop and it follows sum up operation such as 1+2+3+...(n-1). So, this line executes in O(n2) time.
  • Similar to Line4 and Line 5 follows same running time O(n2) because it performs sum up operation inside the for loop.
  • On Line6, it calculates the averages for the sum of elements and this is executed in O(n) time because the operation is directly proportional.
  • On Line7, the value is returned and it is executed in constant time O(1).

Visualization representation of algorithm prefixAverage1 in log-log graph:

As the running time of prefixAverage1 is O(1+2+...+n) and the sum of first "n" integers is n(n+1)2

Blurred answer
Students have asked these similar questions
You are tasked with developing a portable system that can be worn to collect health and fitness data. The challenge is to integrate all functions into the smaller form of an ear clip. The device should include heart rate, movement and temperature sensor and wireless communication with a mobile app. Draw a diagram- hardware architecture of the system- including the selection of suitable sensors, communication modules, and an energy-efficient microcontroller. (visualize the components and their connections)
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.

Chapter 4 Solutions

Data Structures and Algorithms in Java

Chapter 4, Problem 11R Chapter 4, Problem 12R Chapter 4, Problem 13R Chapter 4, Problem 14R Chapter 4, Problem 15R Chapter 4, Problem 16R Chapter 4, Problem 17R Chapter 4, Problem 18R Chapter 4, Problem 19R Chapter 4, Problem 20R Chapter 4, Problem 21R Chapter 4, Problem 22R Chapter 4, Problem 23R Chapter 4, Problem 24R Chapter 4, Problem 25R Chapter 4, Problem 26R Chapter 4, Problem 27R Chapter 4, Problem 28R Chapter 4, Problem 29R Chapter 4, Problem 30R Chapter 4, Problem 31R Chapter 4, Problem 32R Chapter 4, Problem 33R Chapter 4, Problem 34R Chapter 4, Problem 35C Chapter 4, Problem 36C Chapter 4, Problem 37C Chapter 4, Problem 38C Chapter 4, Problem 39C Chapter 4, Problem 40C Chapter 4, Problem 41C Chapter 4, Problem 42C Chapter 4, Problem 43C Chapter 4, Problem 44C Chapter 4, Problem 45C Chapter 4, Problem 46C Chapter 4, Problem 47C Chapter 4, Problem 48C Chapter 4, Problem 49C Chapter 4, Problem 50C Chapter 4, Problem 51C Chapter 4, Problem 52C Chapter 4, Problem 53C Chapter 4, Problem 54C Chapter 4, Problem 55C Chapter 4, Problem 56C Chapter 4, Problem 57C Chapter 4, Problem 58C Chapter 4, Problem 59C Chapter 4, Problem 60P Chapter 4, Problem 61P Chapter 4, Problem 62P Chapter 4, Problem 63P
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Text book image
    Operations Research : Applications and Algorithms
    Computer Science
    ISBN:9780534380588
    Author:Wayne L. Winston
    Publisher:Brooks Cole
    Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT