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
-
18-43. TRANSFERRED-IN COSTS, WEIGHTED-AVERAGE METHOD. Spelling Sports produces basketballs in two departments: cutting and stitching. Each department has one direct-cost category (direct materials)...
-
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...
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
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
-
Predict the absolute configuration of the major diol product formed by treatment of (S)-2 ethyl- 2-methyloxirane with water in the presence of an acid catalyst.
-
Suppose the Waterford Crystal company can produce up to 100 iced-tea pitchers per day. Now suppose that the plant is open 250 days per year and that the annual demand is for 20,000 pitchers. The cost...
-
May Enterprises issued \(\$ 200,000\) of six percent, five-year bonds with interest payable semiannually. Determine the issue price if the bonds are priced to yield (a) six percent,
-
Refer to TMCs project selection problem presented in this chapter. In the solution shown in Figure, The probability of success for project 4 is only 0.3488. Thus, project 4 is almost twice as likely...
-
Question 3 (Marks: 25) Q.3.1 Mobile commerce (m-commerce) predominantly relies on voice recognition and text-to-speech technologies. Argue in support or against the above statement. (5) Q.3.2 Using a...
-
SUMMARIZ AND PARAPHRASE THE WRITTEN BELOW Facilities Facilities are the actual physical locations in the supply chain network where product is stored, assembled, or manufactured. The two major types...
-
1) Daily Enterprises is purchasing a $9.7 million machine. It will cost $50,000 to transport and install the machine. The machine has a depreciable life of five years and will have no salvage value....
-
1) Calculate the future value of $130,000 in 40 weeks at a 5% annual interest rate. 2) Suppose you win a $300 million jackpot in a lottery, which promises to pay you $20 million per year for the next...
-
See photo attached for question Homework: MT217 M5 Competency Assessment Score: 0 of 5 pts Problem 7.LO4.16 15 of 20 (17 complete) Save HW Score: 80%, 80 of 100 pts Question Help AU.S. Government...
-
From a company's budget for next year, the operating profit before depreciation is estimated at NOK 100,000. Depreciation is estimated at NOK 20,000, while interest is estimated at NOK 10,000 and...
-
You plan on retiring in 15 years. You need $4,000 per month to live after you retire. You have average life expentency of 15 years after your retirement. How much you need to be saving every month...
-
Spread the balance sheets of Lake of Egypt Marina, Inc., for 2021 and 2020. (Input all amounts as positive values. Round your answers to 2 decimal places.) Use the following financial statements for...
-
Prove that if Σ an is absolutely convergent, then a. an
-
Certain operating information is shown below for Harris Department Store: The managers are disappointed with the operating results of department R. They do not believe that competition will permit...
-
A firms cost of acquiring the funds for capital investment projects is known as the a. Payback period. b. Rate of return. c. Cost of capital. d. Time value of money.
-
Blaine Company is considering four investment proposals, each requiring the same amount of initial cash investment. The excess present value index for each proposal is listed below. Using the index...
Study smarter with the SolutionInn App