Once upon a time, in a picturesque town, a highly competitive examination was held, with substantial...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Once upon a time, in a picturesque town, a highly competitive examination was held, with substantial rewards to the victors. It attracted huge numbers of people to join from all over the world. As one of the participants in the competition, Bob was eager to find out his result. However, the only information Bob has is his rank and a list of the (anonymous) student scores that are stored in an array S. He designed the algorithms below to find his score from his ranking. Algorithm 1 findMyScore 1: Input: S = [81,82,81]: a list of student scores; l: the length of the list; re {ala € N*,ze [1,1]}: the rank. 2: Initialization: i← 1. 3: if 1 = 1 then score 5: else if l = 2 then 6: 7: 8: 9: 10: else 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: if S[1] > S[2] then 7: 8: 9: 10: S[1], S[2] = S(2], S[1] // sort array end if score S[r] // find the score as the r-th element in the sorted array S[r] // base case, if there is only one element in the array, the score is that element. while i ≤l do pivot = S[i] rank, Sget Rank (S, 1, pivot) if rank 1/3 and rank <21/3 then if rank = r then score + pivot else if rank <r then score = find MyScore(S[rank :], 1-rank +1,r-rank + 1) // find score with rank r- rank in the last 1-rank + 1 elements. else end if end if 25: 26: i+i+1 27: end while 28: end if 29: Return score. else score = find MyScore(S[: rank],i,r) // find the score with rank r in the first i elements. break Algorithm 2 get Rank = 1: Input: S [81, 82, 2: Initialization: S' 3: while i ≤l do ← 4: if S[i] < n then 5: 6: S'[left] = S[i] left = left + 1 end if i+i+1 S'[right] = S[i] right right-1 = 81]: a list of numbers; 1: the length of the list; n: a number. [0,0,...,0]: a list of zeros with length l; left+1; right+l; i+ 1. 11: 12: end while 13: Return left, S'. (a) To check if his algorithm works, Bob tried a toy example: the scores S = [66, 95, 13, 7, 14], and the rank = 3. Briefly explain how Algorithm 1 processes the input to obtain Bob's score. (b) Assuming that the class is huge, with thousands of students, Bob wanted to have a rough idea about how long the algorithm would take as a function of the problem size 1. (i) Derive the average-case time complexity of Algorithm 1 in terms of (Big Theta). (ii) Derive the worst-case time complexity of Algorithm 1 in terms of (Big Theta). When doing the calculations, you may assume: (1) No two scores are the same. (2) The rank of a score is the number of scores smaller or equal to it. (3) The list index starts from 1, i.e., S[1] denotes the first element in the list S. (4) It is ok to ignore the ceiling and floor operation in , O and calculation. (5) The scores are randomly and independently distributed, i.e., any given score S[i] is ranked j th with probability of 1/1, where 1 ≤ i ≤l and 1 ≤ i ≤l, where l is the number of scores. Once upon a time, in a picturesque town, a highly competitive examination was held, with substantial rewards to the victors. It attracted huge numbers of people to join from all over the world. As one of the participants in the competition, Bob was eager to find out his result. However, the only information Bob has is his rank and a list of the (anonymous) student scores that are stored in an array S. He designed the algorithms below to find his score from his ranking. Algorithm 1 findMyScore 1: Input: S = [81,82,81]: a list of student scores; l: the length of the list; re {ala € N*,ze [1,1]}: the rank. 2: Initialization: i← 1. 3: if 1 = 1 then score 5: else if l = 2 then 6: 7: 8: 9: 10: else 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: if S[1] > S[2] then 7: 8: 9: 10: S[1], S[2] = S(2], S[1] // sort array end if score S[r] // find the score as the r-th element in the sorted array S[r] // base case, if there is only one element in the array, the score is that element. while i ≤l do pivot = S[i] rank, Sget Rank (S, 1, pivot) if rank 1/3 and rank <21/3 then if rank = r then score + pivot else if rank <r then score = find MyScore(S[rank :], 1-rank +1,r-rank + 1) // find score with rank r- rank in the last 1-rank + 1 elements. else end if end if 25: 26: i+i+1 27: end while 28: end if 29: Return score. else score = find MyScore(S[: rank],i,r) // find the score with rank r in the first i elements. break Algorithm 2 get Rank = 1: Input: S [81, 82, 2: Initialization: S' 3: while i ≤l do ← 4: if S[i] < n then 5: 6: S'[left] = S[i] left = left + 1 end if i+i+1 S'[right] = S[i] right right-1 = 81]: a list of numbers; 1: the length of the list; n: a number. [0,0,...,0]: a list of zeros with length l; left+1; right+l; i+ 1. 11: 12: end while 13: Return left, S'. (a) To check if his algorithm works, Bob tried a toy example: the scores S = [66, 95, 13, 7, 14], and the rank = 3. Briefly explain how Algorithm 1 processes the input to obtain Bob's score. (b) Assuming that the class is huge, with thousands of students, Bob wanted to have a rough idea about how long the algorithm would take as a function of the problem size 1. (i) Derive the average-case time complexity of Algorithm 1 in terms of (Big Theta). (ii) Derive the worst-case time complexity of Algorithm 1 in terms of (Big Theta). When doing the calculations, you may assume: (1) No two scores are the same. (2) The rank of a score is the number of scores smaller or equal to it. (3) The list index starts from 1, i.e., S[1] denotes the first element in the list S. (4) It is ok to ignore the ceiling and floor operation in , O and calculation. (5) The scores are randomly and independently distributed, i.e., any given score S[i] is ranked j th with probability of 1/1, where 1 ≤ i ≤l and 1 ≤ i ≤l, where l is the number of scores.
Expert Answer:
Answer rating: 100% (QA)
a In order to get Bobs score Algorithm 1 processes the input as follows Nondecreasing orderly sortin... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
3. Let r R be some fixed real number. Use induction to prove the following proposition. Proof (by induction) Base Case Inductive Step Proposition. VnEN, Wi
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Water is pumped out of a holding tank at a rate of 5 5e 0.12t liters/minute, where t is in minutes since the pump is started. If the holding tank contains 1000 liters of water when the pump is...
-
A computer consists of a CPU and an I/O device D connected to main memory Mvia a shared bus with a data bus width of one word. The CPU can execute a maximum of 106 instructions per second. An average...
-
Calcium oxalate (CaC2O4), the main component of kidney stones, is insoluble in water. For this reason it can be used to determine the amount of Ca2+ ions in fluids such as blood. The calcium oxalate...
-
Vibration spectra can have many frequency peaks. What is key to simplifying the analysis of the number of peaks of interest?
-
The Comparative statements of cash flows for Executive style corporation, a manufacturer of high-quality suits for men, appear on the next page. To expand its markets and familiarity with its brand,...
-
1) your essay answers the question being posed in detail; 2) your responses must be at least 250 words per question; 3) APA formatting is mandatory, so please be sure your formatting is correct...
-
A major pharmaceutical wholesaler buys brand drugs from a manufacturer at wholesale prices and sells them to pharmacies at retail prices. It estimates that the wholesale (W) price, the retail (R)...
-
esc The weights of a certain dog breed are approximately normally distributed with a mean of and a standard deviation of = 5 pounds. A dog of this breed weighs 55 pounds. What is the dog's z-score?...
-
How might definitions of well-being differ across and within cultures? Why is this important to consider in a clinical psychology or health psychology context?
-
What theories have been used in peer-reviewed research when investigating emotion-based persuasive messages? What has peer-reviewed research revealed about the implications of emotion-based...
-
Explain what is meant by the taxable income limitation as it relates to the dividends received deduction. In what situation would this limitation not apply? 2. If a corporation has gross income from...
-
What is the difference between the fair market value of employer securities at distribution and their cost or other basis to the plan?
-
What statement regarding tuition fees is correct? The tuition tax credit includes the cost of books for students who receive in-class instruction. Full-time students at recognized post-secondary...
-
2. Benzinger Trailer Rental owns thirty small trailers that are rented by the day for local moving jobs. The adjusted trial balance for Benzinger Trailer Rental for the year ended December 31, 19x4,...
-
Why is it necessary to study the diffusion of molecules in biological systems?
-
Identify the types of duress and discuss the legal effect of each.
-
Scott, manufacturer of a carbonated beverage, entered into a contract with Otis, owner of a baseball park, whereby Otis rented to Scott a large signboard on top of the center field wall. The contract...
-
Discuss the concept and importance of negotiability.
-
In 2022, Mark purchased two separate activities. Information regarding these activities for 2022 and 2023 is as follows: The 2022 losses were suspended losses for that year. During 2023, Mark also...
-
In 2023, Julie, a single individual, reported the following items of income and deduction: Julie owns 100% and is an active participant in the rental real estate activity. What is her taxable income...
-
Jerry sprayed all of the landscaping around his business with a pesticide in June 2023. Shortly thereafter, all of the trees and shrubs unaccountably died. The FMV and the adjusted basis of the...
Study smarter with the SolutionInn App