Problem 1. (10 points: 2+2+2+4) Given an unsorted array of n unique integers, you need to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem 1. (10 points: 2+2+2+4) Given an unsorted array of n unique integers, you need to return the k smallest of them in sorted order, where k is between 1 and n. You come up with three algorithms to solve this problem: They are: A1: Sort the array in increasing order, then list the first k integers after sorting. A2: Build a min-heap from these n integers, and then call EXTRACT-MIN k times. A3: Use the linear time selection algorithm to find the kth smallest integer, then partition the array about that number, and finally sort these k smallest numbers. Assume that you are using the sorting algorithm with the best worst-case time complexity (e.g. merge-sort) in both A1 and A3. Answer the following questions. (a) Let Ti(n, k) denote the worst-case running time of Algorithm A1. Analyze Ti(n, k) using the O() notation, in terms of n and k. Justify your answer. (b) Let T₂(n, k) denote the worst-case running time of Algorithm A2. Analyze T₂(n, k) using the O() notation, in terms of n and k. Justify your answer. (c) Let T3(n, k) denote the worst-case running time of Algorithm A3. Analyze T3(n, k) using the O() notation, in terms of n and k. Justify your answer. (d) Among the three algorithms, which algorithm would you choose to find the k smallest integers in sorted order, and why? Problem 1. (10 points: 2+2+2+4) Given an unsorted array of n unique integers, you need to return the k smallest of them in sorted order, where k is between 1 and n. You come up with three algorithms to solve this problem: They are: A1: Sort the array in increasing order, then list the first k integers after sorting. A2: Build a min-heap from these n integers, and then call EXTRACT-MIN k times. A3: Use the linear time selection algorithm to find the kth smallest integer, then partition the array about that number, and finally sort these k smallest numbers. Assume that you are using the sorting algorithm with the best worst-case time complexity (e.g. merge-sort) in both A1 and A3. Answer the following questions. (a) Let Ti(n, k) denote the worst-case running time of Algorithm A1. Analyze Ti(n, k) using the O() notation, in terms of n and k. Justify your answer. (b) Let T₂(n, k) denote the worst-case running time of Algorithm A2. Analyze T₂(n, k) using the O() notation, in terms of n and k. Justify your answer. (c) Let T3(n, k) denote the worst-case running time of Algorithm A3. Analyze T3(n, k) using the O() notation, in terms of n and k. Justify your answer. (d) Among the three algorithms, which algorithm would you choose to find the k smallest integers in sorted order, and why?
Expert Answer:
Answer rating: 100% (QA)
a The worstcase running time of Algorithm A1 Tin k is Onlogn This is because the algorithm first sor... View the full answer
Related Book For
Thermodynamics An Engineering Approach
ISBN: 978-0073398174
8th edition
Authors: Yunus A. Cengel, Michael A. Boles
Posted Date:
Students also viewed these programming questions
-
A state law enforcement agency has come up with three different methods for publicizing burglary-prevention measures during vacation periods. Recognizing that there are more burglaries in larger...
-
Three different inventors come up with three wind turbine designs with these claimed efficiencies: Turbine A: 41 percent, Turbine B: 59 percent, Turbine C: 67 percent. How do you evaluate these...
-
Given an unsorted array of n elements, find if the element k is present in the array or not. Complete the find-Number function. It has 2 parameters: 1. An array of integers, arr, denoting the...
-
A tank of water of length 2 0 m , 1 0 m , and height 5 m is filled with water of density 1 . 2 g / cm 3 . Find the pressure ( in Pa ) of water on one of the walls at a point 5 9 cm above the bottom.
-
Bateson Corp. is considering entering into two contractsone with a joint stock company that distributes home products east of the Mississippi River and the other with a business trust formed by a...
-
1. Does it appear that the marketing strategy that Avon used in China from 1998 to 2006 worked well? Might some other strategy have been more effective? 2. Discuss the usefulness of the preferred...
-
Repeat the solution of Problem 12 for the case when the flow is unsteady and the problem is solved using the fully implicit time discretization (the simple implicit scheme).
-
Evaluating a cost center including flexible budgeting concepts Smiley Medical Equipment Company makes a blood pressure measuring kit. Elbert Jackson is the production manager. The production...
-
Y6 . Problem 3 - Chapter 6 Journal Entries. Record the following transactions in general journal form related to the debt activities of the City of Layton described below. Journal entries should be...
-
1. Using the spreadsheet model from Case 2.1 as a starting point, use Solver to find the optimal set of projects to approve. The solution should maximize the total NPV from the approved projects, and...
-
Carpenter Company uses standard costing. The company has a manufacturing plant in Georgia. Standard labour hours per unit are 0.50, and the variable overhead rate for the Georgia plant is $3.50 per...
-
Spring Break Corporation earned $10 million for the fiscal year ending yesterday. The firm also paid out 20% of its earnings as dividends yesterday and it will continue to pay out 20% of its earnings...
-
Yokam Company is considering two alternative projects. Project 1 requires an initial investment of $520,000 and has a present value os all its cash flows of $1,550,000. Project 2 requires an initial...
-
to prepare for Mimi's increasing expenditure, Simon considers investing in a fixed-income security at the start of the year. The security will pay out $100 at the end of each year for the next 10...
-
If annual total disposable income is $60,000 and your annual credit card interest is $1,500, using common-size analysis, what is the percentage of your annual credit card interest to total disposable...
-
1. This is a question about binary min-heaps. 1. Given the binary min-heap A = [1, 60, 18, 83, 97, 68, 47, 99] do the following: (a) Draw the tree representation. [3 marks] (b) Show the steps...
-
A company achieves a competitive advantage when: A. it is able to maximize shareholder wealth B. it is consistently able to achieve both its strategic and financial objectives C. its strategy and its...
-
The value of a share of common stock depends on the cash flows it is expected to provide, and those flows consist of the dividends the investor receives each year while holding the stock and the...
-
Chickens with an average mass of 2.2 kg and average specific heat of 3.54 kJ/kgC are to be cooled by chilled water that enters a continuous-flow-type immersion chiller at 0.5C and leaves at 2.5C....
-
Consider an electric refrigerator located in a room. Determine the direction of the work and heat interactions (in or out) when the following are taken as the system: Room FIGURE P2-19C
-
A household refrigerator that has a power input of 450 W and a COP of 1.5 is to cool 5 large watermelons, 10 kg each, to 8C. If the watermelons are initially at 28C, determine how long it will take...
-
7. Roger Schlafly applied for a patent for two prime numbers. (A prime number cannot be evenly divided by any number other than itself and 1. For example: 1, 2, 3, 5, 7, 11, 13.) Schlafly's numbers...
-
10. Babe Ruth was one of the greatest baseball players of all time. After Ruth's death, his daughters registered the words "Babe Ruth" as a trademark. MacMillan, Inc., published a baseball calendar...
-
9. Question: Aman asked a question of the advice columnist at his local newspaper. His wife had thought of a clever name for an automobile. He wanted to know if there was any way they could own or...
Study smarter with the SolutionInn App