Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(10 points) We compare the running time of two similar programs, given here in pseudo-code. Suppose we have an array A of 10,000 random integers,
(10 points) We compare the running time of two similar programs, given here in pseudo-code. Suppose we have an array A of 10,000 random integers, each between 0 and 99 , and we'll add the array elements that satisfy A[i]50. To make the time required more noticeable, we'll repeat that 100,000 times. for j in 0..9999 A[j]= a random number from 0 to 99 sum =0 for i in 0..99999 for j in 0..9999 if A[j]>=50 sum +=A[j] The second program is identical to the first, except we sort the array in place after the initialization. for i in 0..9999 A[i]= a random number from 0 to 99 sort_in_place (A) sum =0 for i in 0.99999 for j in 09999 if A[j]>=50 sum +=A[j] We measure the execution time of both programs, and find to our surprise that the second program runs noticeably faster than the first program! Explain where this miraculous performance increase came from. (You do not need to implement and run these functions yet. That comes in Assignment 1.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started