Question

In: Computer Science

Two versions of a strategy to solve the “10 largest trades on a given day in...

Two versions of a strategy to solve the “10 largest trades on a given day in the NYSE” problem are given below:

Strategy a: Updating an unsorted output array:

         a.1. Let B be an array of size 10.

         a.2. Copy the first 10 trade values from A into B.

         a.3. Scan B to locate the smallest trade value L in it.

         a.4. Repeat steps a.4.1-a.4.3for each of the remaining (10 million ─ten) trade values in A:

                   a.4.1 Get the next trade value from A and compare it with L.

                   a.4.2 If L is larger or equal, do nothing

                   a.4.3 Otherwise

                            a.4.3.1 Replace L in B with this next trade value from A.

                            a.4.3 2 Scan B to locate the smallest trade value L in it.

         a.5 Output the trade values in B.

The second version maintains B in a sorted state so that the largest trade value in it could be directly located:

Strategy a’: Updating a sorted output array:

         a’.1. Let B be an array of size 10.

         a’.2. Copy the first 10 trade values from A into B.

         a’.3. sort B in ascending or descending order

         a’.4. Repeat steps 3b.4.1-3b.4.2for each of the remaining (10 million ─ten) trade values in A:

                   a’.4.1 Get the next trade value from A and compare it with the smallest value in B

                   a’.4.2 If the smallest value in B is larger or equal, do nothing

                   a’.4.3 Otherwise

                            a’.4.3.1 Replace the smallest value in B with this next trade value from A.

                            a’.4.3 2 sort B in the same order

         a’.4. Output the trade values in B.

Which version is more efficient? Circle one:         

Strategy a        Strategy a’      both are equally efficient

Provide a technical justification or argument (short and precise) to support your claim:

Solutions

Expert Solution

For strategy a.

As the size of the B array is 10,so step 3 will take O(10) complexity.which is constant.

In step 4,In worst case ,let's assume ,each time we have to replace the L with the current number from A array.

The size of Array A is 10 million,so we'll have to replace L each time in worst case and searching the number in array B take O(10) time.so total time complexity is O(10*(10 million)).

For strategy a'.

As the size of the B array is 10.If we assume sorting takes O(n(logn)) then step 3 will take O(10*log10) complexity.which is constant.

In step 4,In worst case ,let's assume ,each time we have to replace the L with the current number from A array.

The size of Array A is 10 million,so we'll have to replace L each time in worst case and searching the number in array B take O(1) time because in sorted array in increasing order always presents at first index then sorting takes O(10log10).so total time complexity is O(10log(10)*(10 million)).

So it's obvious that 10 < (10log10) so strategy a is more efficiently.


Related Solutions

1. Based upon the pseudocode given in “Background”, solve the three versions of add up to...
1. Based upon the pseudocode given in “Background”, solve the three versions of add up to K problems: ◦ all pairs of numbers that add up to K ◦ all triples (set of three) that add up to K ◦ all possible subsets of numbers that add up to K: recursive version is given, you are asked to solve it iteratively. 2. Test the three functions using given test cases. 3. Measure the running time of algorithms under various input...
Children in elementary schools in a US city were given two versions of the same test,...
Children in elementary schools in a US city were given two versions of the same test, but with the order of questions arranged from easier to more difficult in version A and in reverse order in version B. A randomly selected group of 44 students were given version A; their mean grade was 83 with standard deviation 5.6. Another randomly selected group of 38 students were given version B; their mean grade was 81 with standard deviation 5.3. A hypothesis...
Question 3: Pricing Multiple Product Versions (show all work) Casey’s company produces two versions of a...
Question 3: Pricing Multiple Product Versions (show all work) Casey’s company produces two versions of a software program, “Advanced” and “Basic”. There are 3 segments of customers, the Managers, Executives and Students, and the respective segment sizes are 2000, 1000 and 5000. The per-unit cost of producing the Advanced version is $20, while the per-unit cost of producing the Basic version is $10. The willingness to pay (WTP) for each version, by segment, is given as follows: WTP (Managers) =...
What is hedonism? What are the two different versions of this position?
What is hedonism? What are the two different versions of this position?What is atomism?What are the two types of pleasures on Epicurus’ view?What does Epicurus mean when he says that “death is nothing to us?” How does he explain or justify this position?
17. Largest Dams : The data shows the heights (in feet) of the 10 largest dams...
17. Largest Dams : The data shows the heights (in feet) of the 10 largest dams in the United States. Identify the five-number summary, the interquartile range, and draw a boxplot. 770 730 717 710 645 606 602 585 578 564 Source: U.S. Army Corps of Engineers
1. What do we mean when we say to solve a two-player strategy game in a...
1. What do we mean when we say to solve a two-player strategy game in a a. ultra weak sense b. weak sense c. strong sense 2. Compare Depth-First Iterative Deepening method with Depth-First Search and Breadth- First Search. What are the pros and cons for each of these methods
What is the largest size n of a problem that can solve in 1 second, assuming...
What is the largest size n of a problem that can solve in 1 second, assuming that the algorithm to solve the problem takes sqrt(n) microseconds? (sqrt stands for square root) 1 10^(6) 10^(12) 10^(3) How does the array arr = [8, 5, 3, 6, 10] look like after the second iteration (when j = 3) of the j loop on line 1 of the give pseudocode below? insertion_sort.PNG 1 for j 2 do 3 // Insert A[j] into the...
You are given the following information concerning the trades made on a particular stock. Calculate the...
You are given the following information concerning the trades made on a particular stock. Calculate the money flow for the stock based on these trades. (Leave no cells blank - be certain to enter "0" wherever required. A negative value should be indicated by a minus sign. Do not round intermediate calculations. Round your answers to the nearest whole dollar.) Price Volume $ 70.01 70.04 3,000 70.02 2,500 70.01 2,900 69.02 3,050 70.40 3,800 70.31 4,100 Price Up/Down Price Times...
You are given the following information concerning the trades made on a particular stock. Calculate the...
You are given the following information concerning the trades made on a particular stock. Calculate the money flow for the stock based on these trades. (Leave no cells blank - be certain to enter "0" wherever required. A negative value should be indicated by a minus sign. Do not round intermediate calculations. Round your answers to the nearest whole dollar.) Price Volume $ 30.31 30.34 3,800 30.32 3,300 30.31 3,700 29.32 3,850 30.39 4,600 30.30 4,90
You are given the following information concerning the trades made on a particular stock. Calculate the...
You are given the following information concerning the trades made on a particular stock. Calculate the money flow for the stock based on these trades. (Leave no cells blank - be certain to enter "0" wherever required. Negative amounts should be indicated by a minus sign. Do not round intermediate calculations. Round your answers to the nearest whole dollar. Omit the "$" sign in your response.)    Price Volume     $ 59.97 59.99 3,400 59.97 2,900 59.96 3,300 58.97 3,450 60.20...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT