5. Sorting out complaints. A group of In students, all of whom have distinct heights, line...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
5. Sorting out complaints. A group of In students, all of whom have distinct heights, line up in a single-file line for a group photo. Any student who stands somewhere in front of a shorter student will conceal the shorter student, who will not appear in the picture. (The taller student need not be directly in front of the shorter one.) For this reason, each student makes one complaint to the photographer for each taller student in front of them. In this problem we are concerned with algorithms that determine the number of complaints that will be made. The input is an array A[1,..., n] of the students' heights, from the front of the line to the back. (So, A[1] is the height of the student in the very front, and A[n] is the height of the student in the very back.) The desired output is the total number of complaints. (Throughout this question, assume that two heights can be compared in constant time, independent of n.) (a) Describe briefly, clearly, and precisely (in English) a simple brute-force algorithm for this problem; do not give pseudocode. State, with brief justification, a O(.) bound on its (worst-case) running time as a function of n. You do not need to give a formal proof. Solution: (b) Suppose that both the front half and back half of the line (i.e., the two halves of the array A) happen to be sorted in ascending order, though the line as a whole may not be. Describe clearly and precisely (in English or in pseudocode, as you prefer) an O(n)-time algorithm that outputs the number of complaints in this scenario, and briefly justify its correctness and running time. Solution: (c) Give a O(n log n)-time divide-and-conquer algorithm for this complaint-counting prob- lem. Briefly and clearly describe (in English) how the algorithm works, then give clear pseudocode. Hint: Enhance the MERGESORT algorithm to both sort and count. Think about how sorting the two halves of the array affects, or doesn't affect, whether a specific student will be concealed by a particular other student. Solution: 5. Sorting out complaints. A group of In students, all of whom have distinct heights, line up in a single-file line for a group photo. Any student who stands somewhere in front of a shorter student will conceal the shorter student, who will not appear in the picture. (The taller student need not be directly in front of the shorter one.) For this reason, each student makes one complaint to the photographer for each taller student in front of them. In this problem we are concerned with algorithms that determine the number of complaints that will be made. The input is an array A[1,..., n] of the students' heights, from the front of the line to the back. (So, A[1] is the height of the student in the very front, and A[n] is the height of the student in the very back.) The desired output is the total number of complaints. (Throughout this question, assume that two heights can be compared in constant time, independent of n.) (a) Describe briefly, clearly, and precisely (in English) a simple brute-force algorithm for this problem; do not give pseudocode. State, with brief justification, a O(.) bound on its (worst-case) running time as a function of n. You do not need to give a formal proof. Solution: (b) Suppose that both the front half and back half of the line (i.e., the two halves of the array A) happen to be sorted in ascending order, though the line as a whole may not be. Describe clearly and precisely (in English or in pseudocode, as you prefer) an O(n)-time algorithm that outputs the number of complaints in this scenario, and briefly justify its correctness and running time. Solution: (c) Give a O(n log n)-time divide-and-conquer algorithm for this complaint-counting prob- lem. Briefly and clearly describe (in English) how the algorithm works, then give clear pseudocode. Hint: Enhance the MERGESORT algorithm to both sort and count. Think about how sorting the two halves of the array affects, or doesn't affect, whether a specific student will be concealed by a particular other student. Solution:
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Python and most Python libraries are free to download or use, though many users use Python through a paid service. Paid services help IT organizations manage the risks associated with the use of...
-
Suppose that in response to a negative supply shock, the Federal Reserve raises interest rates. Their reason for doing this might be to Keep the economy from overheating Shift SRAS to the right Move...
-
E-mail systems differ in the manner in which multiple recipients are handled. In some systems, the originating user agent or mail sender makes all the necessary copies and these are sent out...
-
Derive (15-44) and use it to solve the following problem. Sulfate ion is to be removed from 60 L of water by exchanging it with chloride ion on 1 L of a strong-base resin with relative molar...
-
An engine indicator is used to determine (a) speed (b) temperature (c) pressure (d) m.e.p.
-
Clark sold securities for a $50,000 short-term capital loss during the current year, but he has no personal capital gains to recognize. The C&L General Partnership, in which Clark has a 50% capital,...
-
Case: Dodson v. Shrader https://law.justia.com/cases/tennessee/supreme-court/1992/824-s-w-2d-545-2.html Your Role Attorney for Defendant (Shrader) Questions Closing Statement Exhibit Table Answer in...
-
The addition rule in probability states that, for two events E1 and E2, the probability that one or the other of the events (possibly both) occurs is given by: P(E1 or E2) = P(E1) + P(E2) - P(E1 and...
-
Hanna Company s current asset and current liability account balances at the beginning and end of the year were as follows: December 3 1 End of Year Beginning of Year Current assets: Cash and cash...
-
Considering the evolving nature of workforce dynamics and the imperative to attract, retain, and develop top talent in competitive labor markets, how do organizations craft holistic talent management...
-
In order to determine if an increase in GDP is caused by an increase in quantities produced or by an increase in price (inflation), what aspect the economists could use ?
-
Considering the multifaceted interplay of regulatory complexities and evolving compliance standards across international jurisdictions, how do organizations navigate regulatory landscapes...
-
What is a perfectly inelastic demand? Explain with examples.
-
What is the internal rate of return for the following project: An initial outlay of $9,000 resulting in a single cash inflow of $16,452 in 7 years.
-
Find the velocity, acceleration, and speed of a particle with the given position function. r(t) = (t 2 , sin t - t cos t, cos t + t sin t), t > 0
-
What is the pro forma statement, and how important is it for a business?
-
Briefly compare replacement value to liquidation value of an asset.
-
What do we mean by budgeting, and how would this process serve the firm?
Study smarter with the SolutionInn App