our second implementation for computing prefix averagesprefix average is presented in code fragment def prefix average ( ) """return list such thatfor all ja[jequals average of [ ] [ "" len(screate new list of zeros [ for in range( ) [jsum( [ : + ]( + record the average return code fragment algorithm prefix average this approach is essentially the same high-level algorithm as in prefix average but we have replaced the inner loop by using the single expression sum( [ : + ]to compute the partial sums[ sjwhile the use of that function greatly simplifies the presentation of the algorithmit is worth asking how it affects the efficiency asymptoticallythis implementation is no better even though the expressionsum( [ : + ])seems like single commandit is function call and an evaluation of that function takes oj time in this context technicallythe computation of the slices[ : + ]also uses oj timeas it constructs new list instance for storage so the running time of prefix average is still dominated by series of steps that take time proportional to nand thus ( linear-time algorithm our final algorithmprefix averages is given in code fragment just as with our first two algorithmswe are interested in computingfor each jthe prefix sum [ [ sj]denoted as total in our codeso that we can then compute the prefix average [ =total ( howeverthere is key difference that results in much greater efficiency def prefix average ( ) """return list such thatfor all ja[jequals average of [ ] [ "" len(screate new list of zeros [ total compute prefix sum as [ [ for in range( ) total + [jupdate prefix sum to include [ [jtotal ( + compute average based on current sum return code fragment algorithm prefix average