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.
-
1. Will interactive television catch on with consumers? What might be slowing the adoption of this innovative advertising technique? 2. Discuss the types of products or services that would benefit...
-
Why do controls need to be timely and economical?
-
What is shareholder value? Given that there is a range of stakeholders interested in corporate environmental impacts, what arguments can be advanced for emphasising shareholders and value...
-
Is Service Marketing Different from Product Marketing? Some service marketers maintain that service marketing is fundamentally different from product marketing and relies on different skills. Some...
-
The differential gear used in an automobile is shown in Fig.15.13. The pinion A on the propeller shaft has 12 teeth and the crown gear B has 60 teeth. The shafts P and Q form the rear axles to which...
-
Nautilus Resources is investing in a new heavy oil upgrader in northern Alberta. Nautilus has hired Rite Build Contractors to construct the facilities. The contract price is $3,600 million to be...
-
The steel truss shown in Figure 1.C is anchored at A and supported on rollers at B. If the truss is so designed that, under the given loading, all tension members are stressed to 100 N/mm and all...
-
How will culminating projects assess learning objectives tied to Common Core State Standards for Kindergarten? What three learning objectives align with state standards for students' culminating...
-
Expand in taylor series, up to the lowest possible order, The following functions. Around x = -1 and x=0 b). f(x) = x+4 d). f (x)= In (x-4) f). ex-3 a) f (x) = = = = / 1 1 x-1 2 c). g(x) = +1 e). ex
-
11 LW 12. ADDI DOR 14 DW 15 SUB 11: DW 43 13. OR 14: LW IS: SUB Question & MIPS &-Stage Pipetine For this qontin 11: B, Kha) 12,811, 2 ht. B, 34-4(2) 22 mb , Fi, 844 kyland architecture Show...
-
Paying points for bond rates. Your grandmother wants to buy you a 1-year US Savings Bond. It costs $1,000. It earns interest at a continuous rate of r% for a year, then you get to redeem it for its...
-
You are to write a program in either c or c++. Your program should prompt the user for a string of symbols, including: brackets ']', '[', curly brackets '{', '}', and parentheses '(',')'. After...
-
Berkeley College offers students a number of different majors and disciplines. These majors and disciplines have department chairpersons who are responsible for the department budget preparation....
-
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...
-
Distinguish among the following tests and indicate the assertions to which each test pertains: a. Vouch recorded payables to supporting documentation. b. Examine subsequent payments. c. Determine...
-
a. Discuss materiality from the perspective of the production cycle. b. Discuss inherent risk from the perspective of the production cycle. c. Why might the auditor use different audit strategies for...
-
What circumstances pertaining to property, plant, and equipment may warrant the following assessments of inherent risk (IR)? a. Low for the existence or occurrence assertion. b. Moderate or high for...
Study smarter with the SolutionInn App