P-th percentile (0 < P 100) of a list of K ordered values (sorted from...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
P-th percentile (0 < P ≤ 100) of a list of K ordered values (sorted from least to greatest) is the smallest value in the list such that no more than P percent of the data is strictly less than the value and at least P percent of the data is less than or equal to that value. It can be obtained by first calculating the ordinal rank and then taking the value from the ordered list that corresponds to that rank. The original rank k is calculated using this formula k = 100 × K Given two sorted arraysa and b size of n and m. Implement a function find_percentile(a, b, p) that finds p-th percentile of an array c, where c is the result of merge arrays a and b. Time limit: 0.1 seconds per test. Note that solutions working for linear time from O(n + m) will not satisfy the time limit. To get full score the solution should work faster. Input data: The function takes two arraysa and b and quantile parameters q and k. 0 ≤n, m≤ 10⁰,0 <p≤100 You can assume that at least one of the arrays is not empty. Output data: One int-p-th percentile of merged arrays. Examples: # 1 2 3 4 a [1, 2, 7, 8, 10] [1, 2, 7, 8] [15, 20, 35, 40, 50] [15, 20] b [6, 12] [6, 12] 0 [25, 40, 50] Р 50 50 30 40 output 7 6 20 20 Test sets: Part 1. 50-th percentile is called the median. For all tests from this test set p = 50 and you should find the median of two sorted arrays. For this test set n, m < 100 and solution working for linear time from n and m will satisfy the time limit. Part 2. For all tests p = 50,0 ≤n, m≤ 106. Solution working for O(n + m) will satisfy the time limit. Part 3. Small tests 0 ≤n, m≤ 100,0 < p ≤ 100. Part 4. Large tests 0 ≤n, m≤ 10⁰,0 < p ≤ 100. Hints: Hint 1. Remember what algorithms with log in time complexity do you know? Hint 2. After you come up with some solution try to prove it's correctness and estimate time and space complexity. It can help you to find mistakes (if any) in this stage and you will be asked to do this anyway in the next task. Hint 3. Try unit test and stress test to find mistakes (if any), you will be asked to implement unit tests and stress test anyway in the next task. For example: Test a = [] b = [3] P = 50 print( find_percentile(a, b, p)) a = [10, 20, 30] b = [1, 2] P = 50 print( find_percentile(a, b, p)) Result 3 10 Upload your solution file find_percentile.py and add to your code unit test, stress test and max test. Use python method time.time() to calculate how long your solution (not reference!) works on the max test. This method returns the time in seconds from the beginning of the epoch, you can calculate time before and after your function run. def find percentile(a, b, p): # do something return result def test_find_percentile(a, b, p, correct_answer): # run the soluton and compare to the correct answer def run_unit_tests(): #run several test_find_percentile for different tests def run_stress_test(): #run several random tests #don't forget to find the right answer with refrence solution # find_percentile works 10 seconds on the max test def run_max_test() # generate arrays a and b of maximum possible sizes #len(a), len(b) <= 150000 for theproblem # calculate working time for your solution, not reference! #run test_find_ercentile for max_test P-th percentile (0 < P ≤ 100) of a list of K ordered values (sorted from least to greatest) is the smallest value in the list such that no more than P percent of the data is strictly less than the value and at least P percent of the data is less than or equal to that value. It can be obtained by first calculating the ordinal rank and then taking the value from the ordered list that corresponds to that rank. The original rank k is calculated using this formula k = 100 × K Given two sorted arraysa and b size of n and m. Implement a function find_percentile(a, b, p) that finds p-th percentile of an array c, where c is the result of merge arrays a and b. Time limit: 0.1 seconds per test. Note that solutions working for linear time from O(n + m) will not satisfy the time limit. To get full score the solution should work faster. Input data: The function takes two arraysa and b and quantile parameters q and k. 0 ≤n, m≤ 10⁰,0 <p≤100 You can assume that at least one of the arrays is not empty. Output data: One int-p-th percentile of merged arrays. Examples: # 1 2 3 4 a [1, 2, 7,8, 10] [1, 2, 7, 8] [15, 20, 35, 40, 50] [15, 20] b [6, 12] [6, 12] 0 [25, 40, 50] Р 50 50 30 40 output 7 6 20 20 Test sets: Part 1. 50-th percentile is called the median. For all tests from this test set p = 50 and you should find the median of two sorted arrays. For this test set n, m < 100 and solution working for linear time from n and m will satisfy the time limit. Part 2. For all tests p = 50,0 ≤n, m≤ 106. Solution working for O(n + m) will satisfy the time limit. Part 3. Small tests 0 ≤n, m≤ 100,0 < p ≤ 100. Part 4. Large tests 0 ≤n, m≤ 10⁰,0 < p ≤ 100. Hints: Hint 1. Remember what algorithms with log in time complexity do you know? Hint 2. After you come up with some solution try to prove it's correctness and estimate time and space complexity. It can help you to find mistakes (if any) in this stage and you will be asked to do this anyway in the next task. Hint 3. Try unit test and stress test to find mistakes (if any), you will be asked to implement unit tests and stress test anyway in the next task. For example: Test a = [] b = [3] P = 50 print( find_percentile(a, b, p)) a = [10, 20, 30] b = [1, 2] P = 50 print( find_percentile(a, b, p)) Result 3 10 Upload your solution file find_percentile.py and add to your code unit test, stress test and max test. Use python method time.time() to calculate how long your solution (not reference!) works on the max test. This method returns the time in seconds from the beginning of the epoch, you can calculate time before and after your function run. def find_percentile(a, b, p): # do something return result def test_find_percentile(a, b, p, correct_answer): # run the soluton and compare to the correct answer def run_unit_tests(): #run several test_find_percentile for different tests def run_stress_test(): #run several random tests # don't forget to find the right answer with refrence solution # find_percentile works 10 seconds on the max test def run_max_test() # generate arrays a and b of maximum possible sizes #len(a), len(b) <= 150000 for theproblem # calculate working time for your solution, not reference! #run test_find_ercentile for max_test P-th percentile (0 < P ≤ 100) of a list of K ordered values (sorted from least to greatest) is the smallest value in the list such that no more than P percent of the data is strictly less than the value and at least P percent of the data is less than or equal to that value. It can be obtained by first calculating the ordinal rank and then taking the value from the ordered list that corresponds to that rank. The original rank k is calculated using this formula k = 100 × K Given two sorted arraysa and b size of n and m. Implement a function find_percentile(a, b, p) that finds p-th percentile of an array c, where c is the result of merge arrays a and b. Time limit: 0.1 seconds per test. Note that solutions working for linear time from O(n + m) will not satisfy the time limit. To get full score the solution should work faster. Input data: The function takes two arraysa and b and quantile parameters q and k. 0 ≤n, m≤ 10⁰,0 <p≤100 You can assume that at least one of the arrays is not empty. Output data: One int-p-th percentile of merged arrays. Examples: # 1 2 3 4 a [1, 2, 7, 8, 10] [1, 2, 7, 8] [15, 20, 35, 40, 50] [15, 20] b [6, 12] [6, 12] 0 [25, 40, 50] Р 50 50 30 40 output 7 6 20 20 Test sets: Part 1. 50-th percentile is called the median. For all tests from this test set p = 50 and you should find the median of two sorted arrays. For this test set n, m < 100 and solution working for linear time from n and m will satisfy the time limit. Part 2. For all tests p = 50,0 ≤n, m≤ 106. Solution working for O(n + m) will satisfy the time limit. Part 3. Small tests 0 ≤n, m≤ 100,0 < p ≤ 100. Part 4. Large tests 0 ≤n, m≤ 10⁰,0 < p ≤ 100. Hints: Hint 1. Remember what algorithms with log in time complexity do you know? Hint 2. After you come up with some solution try to prove it's correctness and estimate time and space complexity. It can help you to find mistakes (if any) in this stage and you will be asked to do this anyway in the next task. Hint 3. Try unit test and stress test to find mistakes (if any), you will be asked to implement unit tests and stress test anyway in the next task. For example: Test a = [] b = [3] P = 50 print( find_percentile(a, b, p)) a = [10, 20, 30] b = [1, 2] P = 50 print( find_percentile(a, b, p)) Result 3 10 Upload your solution file find_percentile.py and add to your code unit test, stress test and max test. Use python method time.time() to calculate how long your solution (not reference!) works on the max test. This method returns the time in seconds from the beginning of the epoch, you can calculate time before and after your function run. def find percentile(a, b, p): # do something return result def test_find_percentile(a, b, p, correct_answer): # run the soluton and compare to the correct answer def run_unit_tests(): #run several test_find_percentile for different tests def run_stress_test(): #run several random tests #don't forget to find the right answer with refrence solution # find_percentile works 10 seconds on the max test def run_max_test() # generate arrays a and b of maximum possible sizes #len(a), len(b) <= 150000 for theproblem # calculate working time for your solution, not reference! #run test_find_ercentile for max_test P-th percentile (0 < P ≤ 100) of a list of K ordered values (sorted from least to greatest) is the smallest value in the list such that no more than P percent of the data is strictly less than the value and at least P percent of the data is less than or equal to that value. It can be obtained by first calculating the ordinal rank and then taking the value from the ordered list that corresponds to that rank. The original rank k is calculated using this formula k = 100 × K Given two sorted arraysa and b size of n and m. Implement a function find_percentile(a, b, p) that finds p-th percentile of an array c, where c is the result of merge arrays a and b. Time limit: 0.1 seconds per test. Note that solutions working for linear time from O(n + m) will not satisfy the time limit. To get full score the solution should work faster. Input data: The function takes two arraysa and b and quantile parameters q and k. 0 ≤n, m≤ 10⁰,0 <p≤100 You can assume that at least one of the arrays is not empty. Output data: One int-p-th percentile of merged arrays. Examples: # 1 2 3 4 a [1, 2, 7,8, 10] [1, 2, 7, 8] [15, 20, 35, 40, 50] [15, 20] b [6, 12] [6, 12] 0 [25, 40, 50] Р 50 50 30 40 output 7 6 20 20 Test sets: Part 1. 50-th percentile is called the median. For all tests from this test set p = 50 and you should find the median of two sorted arrays. For this test set n, m < 100 and solution working for linear time from n and m will satisfy the time limit. Part 2. For all tests p = 50,0 ≤n, m≤ 106. Solution working for O(n + m) will satisfy the time limit. Part 3. Small tests 0 ≤n, m≤ 100,0 < p ≤ 100. Part 4. Large tests 0 ≤n, m≤ 10⁰,0 < p ≤ 100. Hints: Hint 1. Remember what algorithms with log in time complexity do you know? Hint 2. After you come up with some solution try to prove it's correctness and estimate time and space complexity. It can help you to find mistakes (if any) in this stage and you will be asked to do this anyway in the next task. Hint 3. Try unit test and stress test to find mistakes (if any), you will be asked to implement unit tests and stress test anyway in the next task. For example: Test a = [] b = [3] P = 50 print( find_percentile(a, b, p)) a = [10, 20, 30] b = [1, 2] P = 50 print( find_percentile(a, b, p)) Result 3 10 Upload your solution file find_percentile.py and add to your code unit test, stress test and max test. Use python method time.time() to calculate how long your solution (not reference!) works on the max test. This method returns the time in seconds from the beginning of the epoch, you can calculate time before and after your function run. def find_percentile(a, b, p): # do something return result def test_find_percentile(a, b, p, correct_answer): # run the soluton and compare to the correct answer def run_unit_tests(): #run several test_find_percentile for different tests def run_stress_test(): #run several random tests # don't forget to find the right answer with refrence solution # find_percentile works 10 seconds on the max test def run_max_test() # generate arrays a and b of maximum possible sizes #len(a), len(b) <= 150000 for theproblem # calculate working time for your solution, not reference! #run test_find_ercentile for max_test
Expert Answer:
Answer rating: 100% (QA)
The problem describes a task of finding the Pth percentile of the merged array resulting from two so... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
On December 15th of the current year, George and Jane Murray determine they have an estimated gross income of $100,000. In addition they report the following expenditures: State Taxes Qualified...
-
The United States Golf Association requires that the weight of a golf ball must not exceed 1.62 oz. The association periodically checks golf balls sold in the United States by sampling specific...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
For the given year, find the standard quotas for the New York City boroughs given in Table 17.5 in Problems 23-28. Assume there are eight council seats. Table 17. 5 1990 Year Total 1790 49 1800 81...
-
A toroid having a rectangular cross section (a = 2.00 cm by b = 3.00 cm) and inner radius R = 4.00 cm consists of 500 turns of wire that carries a sinusoidal current I = I max sin wt, with I max =...
-
Assuming the validity of the De Priester charts, make the following VLE calculations far the ethane (1)/propane(2)/isobutane(3)/isopentane(4) system: (a) BVBL P, given x1 = 0.10, x2 = 0.20. x3 =...
-
Warmup Ltd produces outdoor gas fires for domestic use. The following information has been gathered so that a production budget, a direct materials budget and a direct labour budget for part of 2025...
-
The Slattery Company was formed on January 1, 2010 to build a single product. The company issued no-par common stock on that date for $300,000 cash. The product costs $20 to make, all of which is...
-
Review the first 2 case studies: https://www.countyhealthrankings.org/ Synthesize each in a brief summary (use each of these as a subheading) of key concepts a. Characterizing a Community b....
-
Orie and Jane, husband and wife, operate a sole proprietorship. They expect their taxable income next year to be $450,000, of which $250,000 is attributed to the sole proprietorship. Orie and Jane...
-
Write a Java program to generate 10 random numbers between 0 and 99, figure out the prime numbers in them, and count the number of prime numbers (hint: consult Section 5.11 in the Textbook on finding...
-
Kellogg Company is considering launching a new flavour of its Eggo frozen waffle called the Eggo 11 in order to monetize some of the free publicity around their product from the first seasons of the...
-
A vending machine that sells Pepsi for 200 Halalas(alls) and accept coins of 50(H) and 100(R) Halalas. You are to design the control circuitry of this machine which satisfies the following...
-
Geneva's parents saved for her education by depositing $1 000 at the end of each year in a Registered Education Savings Plan that earns 5% per year compounded annually. a. What is the amount of the...
-
We start with some review problems A crate of mass 4 4 . 0 kg rests on a level surface, with a coefficient of kinetic friction 0 . 1 6 8 . You push on the crate with an applied force of 2 0 1 N ....
-
Electrons have a charge of q = - 1 . 6 0 2 \ times 1 0 - 1 9 C . A student observes that a Styrofoam cup has a total charge of Q = - 0 . 2 5 \ mu C . a . Write an expression for the number of excess...
-
A. Plot historical prices for the six assets on the same line chart. B. Compute returns on all the assets (Asset A-F) in the 'Returns' tab. C. A portfolio allocates 20% to Asset A, 20% to ETF Asset...
-
A 6-lb shell moving with a velocity ?? v0k explodes at point D into three fragments which hit the vertical wall at the points indicated. Fragments A, B, and C hit the wall 0.010 s, 0.018 s, and 0.012...
-
Cedar Corporation has an S corporation election in effect. During the 2012 calendar tax year, the corporation had ordinary taxable income of $200,000, and on January 15, 2012, the corporation paid...
-
Frank Willingham has the following transactions during the year: Sale of office equipment on March 15 that cost $20,000 when purchased on July 1, 2010. Frank has claimed $5,000 in depreciation and...
-
Cypress Corporation has regular taxable income of $170,000 (assume annual gross receipts are greater than $5 million) and regular tax liability of $49,550 for 2012. The corporation also has tax...
-
You have an intrinsic semiconductor, a \(p\)-type semiconductor, and an \(n\)-type semiconductor. The doped samples each contain the same number density of dopant atoms. Which of the three...
-
You have ordered a \(10.00 \mathrm{~mm} \times 10. 00 \mathrm{~mm} \times 2. 000 \mathrm{~mm}\) sheet of pure silicon from a laboratory supply company, but the sheet the company sends has a mass of...
-
The circuit diagram for a rectifier is sometimes drawn with a resistor in the center. Would the rectifier function if this resistor were replaced by a capacitor?
Study smarter with the SolutionInn App