Write a standalone function outside of the DynamicArray class that receives a dynamic array already in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a standalone function outside of the DynamicArray class that receives a dynamic array already in sorted order, either non-descending or non-ascending. The function will return a tuple containing (in this order) a dynamic array comprising the mode (most-occurring) value/s of the array, and an integer that represents the highest frequency (how many times they appear). If there is more than one value that has the highest frequency, all values at that frequency should be included in the array being returned in the order in which they appear in the input array. If there is only one mode, only that value should be included. You may assume that the input array will contain one or more homogeneous elements(either all numbers, or strings, or custom objects, but never a mix of these). You do not need to write checks for these conditions. For full credit, the function must be implemented with O(N) complexity with no additional data structures (beyond the array you return) being created. (Note: You can replace the return array as needed) Example #1: test cases ( > [1, 1, 2, 3, 3, 4], [1, 2, 3, 4, 51, ["Apple", "Banana", "Banana", "Carrot", "Carrot", "Date", "Date", "Date", "Eggplant", "Eggplant", "Eggplant", "Fig", "Fig", "Grape"] for case in test cases: da DynamicArray (case) mode, frequency find_mode (da) print (f" (da) Mode: (mode), Frequency: (frequency} ") case 14, 3, 3, 2, 2, 2, 1, 1, 1, 11 da DynamicArray() for x in range (len (case)): da.append(case [x]) mode, frequency = find_mode (da) print (f" (da) Mode: (mode), Frequency: (frequency} "); Output: DYN ARR Size/Cap: 6/8 [1, 1, 2, 3, 3, 41 Mode: DYN ARR Size/Cap: 2/4 [1, 31, Frequency: 2 DYN ARR Size/Cap: 5/8 [1, 2, 3, 4, 51 Mode: DYN ARR Size/Cap: 5/8 [1, 2, 3, 4, 51, Frequency: 1 Write a standalone function outside of the DynamicArray class that receives a dynamic array already in sorted order, either non-descending or non-ascending. The function will return a tuple containing (in this order) a dynamic array comprising the mode (most-occurring) value/s of the array, and an integer that represents the highest frequency (how many times they appear). If there is more than one value that has the highest frequency, all values at that frequency should be included in the array being returned in the order in which they appear in the input array. If there is only one mode, only that value should be included. You may assume that the input array will contain one or more homogeneous elements(either all numbers, or strings, or custom objects, but never a mix of these). You do not need to write checks for these conditions. For full credit, the function must be implemented with O(N) complexity with no additional data structures (beyond the array you return) being created. (Note: You can replace the return array as needed) Example #1: test cases ( > [1, 1, 2, 3, 3, 4], [1, 2, 3, 4, 51, ["Apple", "Banana", "Banana", "Carrot", "Carrot", "Date", "Date", "Date", "Eggplant", "Eggplant", "Eggplant", "Fig", "Fig", "Grape"] for case in test cases: da DynamicArray (case) mode, frequency find_mode (da) print (f" (da) Mode: (mode), Frequency: (frequency} ") case 14, 3, 3, 2, 2, 2, 1, 1, 1, 11 da DynamicArray() for x in range (len (case)): da.append(case [x]) mode, frequency = find_mode (da) print (f" (da) Mode: (mode), Frequency: (frequency} "); Output: DYN ARR Size/Cap: 6/8 [1, 1, 2, 3, 3, 41 Mode: DYN ARR Size/Cap: 2/4 [1, 31, Frequency: 2 DYN ARR Size/Cap: 5/8 [1, 2, 3, 4, 51 Mode: DYN ARR Size/Cap: 5/8 [1, 2, 3, 4, 51, Frequency: 1
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
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...
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
The Sales Discounts account is a contra account to which of the following accounts? Cost of Goods Sold Sales Returns and Allowances Purchases Discounts Sales Revenue
-
Outline a synthesis for each of the following compounds in stereochemically pure form from enantiomerically pure (2R,3R)-2,3-dimethyloxirane: (a) (b) CH,O O (3S)-CH CHC CH ., , , OCH (2S,3R)-CH CH...
-
It is known that 25% of workers in a factory own a personal computer. Find the probability that at least 26% of a random sample of 80 workers will own a personal computer. In this example, we have...
-
Green, or sustainable finance, is an important part of ethical investment. In many jurisdictions, including Australia and New Zealand, green bonds are becoming an important source of funding....
-
(a) How might Victor and Maria more fully protect themselves through their homeowners and automobile insurance policies? (b) What additional benefits would they receive in buying an umbrella...
-
6. If the tangent to the curve y = x at the point P(t, t) meets the curve again at Q, then the ordinate of the point which divides PQ internally in the ratio 1:2 is: (a) 0 7. (b)-t The system of...
-
Tonya works in a small office with a staff of seven (7) people. The staff includes a physician, a nurse, four (4) administrative employees, and one (1) technician. The office has recently changed its...
-
What is the annual report, and what two types of information does it provide?
-
Common uses of analytical procedures include: a. risk identification during the risk assessment phase. b. estimation of account balances during the risk response phase. c. overall assessment of the...
-
Explain why environmental damage costs are an externality. Use some concrete exam ple(s) to support your answer.
-
"The price of anything is the amount of life you exchange for it." What does this quote from Henry David Thoreau say about valuing nature? Speculate.
-
Discuss at least two differences among the strategic, tactical, and operational decisions in a supply chain. Give two examples of each type of decision.
-
For the following A 132kV/66kV, three-phase 100MVA transformer has impedance of (0+j0.05) pu, based on its own ratings. Determine the positive sequence equivalent circuit, if the system bases are:...
-
The first law of thermodynamics is sometimes whimsically stated as, You cant get something for nothing, and the second law as, You cant even break even. Explain how these statements could be...
-
Based on the historical record of surprises in inflation and productivity, the historical equity risk premium for the US equity market, if it is used as an estimate of the forward- looking equity...
-
Based upon Exhibit 1, the expected three-year holding period return for Novo-Gemini Inc. at the time of purchase was closest to: A. 39.76%. B. 42.76%. C. 44.82%. Judy Chen is the primary portfolio...
-
Based upon Exhibit 1, the realized three-year holding period return for Novo-Gemini Inc. was closest to: A. 39.76%. B. 42.76%. C. 44.82%. Judy Chen is the primary portfolio manager of the global...
Study smarter with the SolutionInn App