Suppose you want to find the k-th smallest element from a collection of n given elements...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose you want to find the k-th smallest element from a collection of n given elements for a given k. (If k=1, then we want the smallest; if k=n; we want the largest, etc.). The elements are given in arbitrary order. Consider these two algorithms: // Algorithm 1 Build a min-heap on all n elements. Perform k delete-mins and return the result of the last delete min. // Algorithm 2 (idea: keep the k-smallest elements seen so far in 11 a heap; when done return max of them. Build a max-heap on the first k elements in the given sequence For each of the remaining n-k elements x{ if x is smaller than the largest element in the heap { do a delete-max insert x into the heap } //else heap unchanged return the max element in the heap after this process. Give a tight runtime analysis of each algorithm in terms of both n and k.. Algorithm 1: Algorithm 2: Suppose you want to find the k-th smallest element from a collection of n given elements for a given k. (If k=1, then we want the smallest; if k=n; we want the largest, etc.). The elements are given in arbitrary order. Consider these two algorithms: // Algorithm 1 Build a min-heap on all n elements. Perform k delete-mins and return the result of the last delete min. // Algorithm 2 (idea: keep the k-smallest elements seen so far in 11 a heap; when done return max of them. Build a max-heap on the first k elements in the given sequence For each of the remaining n-k elements x{ if x is smaller than the largest element in the heap { do a delete-max insert x into the heap } //else heap unchanged return the max element in the heap after this process. Give a tight runtime analysis of each algorithm in terms of both n and k.. Algorithm 1: Algorithm 2:
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
On June 15, 2020, Smithson Foods purchased $1,000,000 of 2.5 percent corporate bonds at par and designated them as availableforsale investments. On December 31, 2020, Smithsons yearend, the bonds are...
-
In Problem 8.69, determine the couple that must be applied to shaft AB in order to rotate the large gear clockwise. PROBLEM 8.69 The square-threaded worm gear shown has a mean radius of 2 in. and a...
-
Is the following function a valid discrete- time autocorrelation function? Justify your answer. 1, k=1, 4 0, otherwise
-
A project has been selected for implementation. The net cash flow (NCF) profile associated with the project is shown below. MARR is 10 percent/year. a. What is the annual worth of this investment? b....
-
Sid Patel bid for and won a concession to rent bicycles in the local park during the summer. During the month of April, Patel completed the following transactions for his bicycle rental business:...
-
Consider the following Closed-loop block diagram of a system: R(s) K s + 5 15 Y(s) s+ p Consider the following parameter values: p = 2 and K-10. a. Obtain the closed-loop transfer function for the...
-
Andi purchases a rental property (27.5-year property) in August 2021 for $140,000. She allocates $20,000 to the land and $120,000 to the house. a. What is Andis 2021 depreciation deduction if she...
-
Professor Anderson needs a sample of students from his university with 13,200 students. He uses a table of random numbers to select 130 numbers between 1 and 13.200. His sample is a. (a) Simple...
-
Suppose you want to estimate the proportion of a population of voters. A random sample reveals that the sample proportion is .42; N = 2,500 and n = 500. Find a 99 % confidence interval for the...
-
A limousine chauffeur is going to take a guest from the hotel to the airport. To catch the flight, the chauffeur has to arrive at the airport in 30 min. There are two routes to the airport: a local...
-
Suppose you estimate a regression and compute SSE = 17.57 and SSR = 102.76. Calculate SST, R 2 , and r by using this information.
-
Compare the width of a 90%confidence interval with that of a 99%confidence interval. Which is wider? Why?
-
28. You are considering two projects with the following cash flows: Project Y $7.000 7,500 8,000 8,500 Year I Year 2 Year 3 Year 4 Project X $8.500 8,000 7,500 7,000 Which one of the following...
-
Perform the operation by first converting the numerator and denominator to scientific notation. Write the answer in scientific notation. 7,200,00/0.000009
-
Consider the FayHerriot model in (14.5). Suppose that Ïd , Ï2 v , and β are known. a. Let With a [0, 1]. Show that, under the model in (14.5), EM [Ëθd (a)...
-
In Example 6.11, we calculated the with-replacement variance for ṫHT. In this example, the sampling fraction n/N is 1/3, so the with-replacement variance is likely to overestimate...
-
The distribution of N in (13.1) is often not approximately normal. The distribution of = m/n2, however, is often close to normality, and CIs for p are easily constructed. For the data in Example...
-
Let \(\left(N_{t} ight)_{t \geqslant 0}\) be a Poisson process with intensity \(\lambda=1\) (see Problem 10.1 for the definition). Show that for \(\mathscr{F}_{t}^{N}:=\sigma\left(N_{r}: r \leqslant...
-
Let \(X_{t}\) be as in Problem 19.5 and set \(\widehat{\tau}_{b}:=\inf \left\{t \geqslant 0: X_{t}=b ight\}\). a) Use Problem 19.5 to find the probability density of \(\widehat{\tau}_{b}\) if...
-
Let \(\left(B_{t} ight)_{t \geqslant 0}\) be a \(\mathrm{BM}^{1}\), denote by \(\mathcal{H}_{T}^{2}\) the space used in Lemma 19.10 and pick \(\xi_{1}, \ldots, \xi_{n} \in \mathbb{R}\) and \(0=t_{0}...
Study smarter with the SolutionInn App