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.
-
What are the two parts of a registration statement? What does each part contain?
-
Given the following activities required for staging a community play on Independence Day, (a) Construct an AON diagram. (b) Determine the earliest completion time for the play and the critical path....
-
Consider two alternatives, each of which will accomplish the same EPA-mandated pollution control. Using an incremental IRR analysis, determine the preferred alternative assuming MARR is 20...
-
1. What are the costs to other stakeholders in society beyond those that Reuters included? How would these costs be estimated? 2. Has the cost of lost reputation been included by Reuters? If no, how...
-
Explain the effect of inflation on UK, Canada, US, Switzerland, China, South Africa, Australia Comparison should be based on house prices, food price, gasoline, energy and so on. I need proper...
-
Ricky Bobby is divorced with two dependent children, ages 9 and 11. During 2022, Ricky had the following gross receipts: Salary income Passive loss from Alpha Partnership (Ricky is a limited partner...
-
A recent article in the Lawyers Weekly began, The law of fiduciary duty is the hottest legal issue these days! Which of the following is false about the meaning of "fiduciary duty?" Select one: a....
-
What are the functions of directors, officers, and shareholders?
-
Review the pros and cons of managing marketing communications in-house rather than using the services of external agencies.
-
What are the federal exemptions debtors can exclude from the bankruptcy process?
-
Classify each of the following items as excludable, nonexcludable, rival, or nonrival. Explain your answer. A public beach in Greece An IKEA chair A movie at the local cinema A view of Mount Fuji
-
Imagine you are working as a salesperson for a household goods retailer selling items such as fridge freezers, furniture and bedding, and televisions, for example. Pick one product category and write...
-
Required Prepare Schedule of Cost of Goods Manufactured and Sold At December 31,2016 , the end of its fiscal year. At December 31,2016, the end of its fiscal year, Lederman Manufacturing Corporation...
-
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...
-
Management is considering three alternatives to satisfy an urgent need. Each of the alternatives will completely satisfy the need, so no combinations have to be considered. The first costs, operating...
-
Consider the following cash flow profile and assume MARR is 10 percent/year and the finance rate is 4 percent/year. a. Determine the MIRR for this project. b. Is this project economically attractive?...
-
Consider the following cash flow profile and assume MARR is 10 percent/year and the finance rate is 4 percent/ year. a. Determine the MIRR for this project. b. Is this project economically...
Study smarter with the SolutionInn App