subject

Consider an array of distinct positive integers where the elements are sorted in ascending order. We want to find all the subsequences of the array consisting of exactly m elements. For example, given array a = [1, 2, 3, 4), the subsequences consisting of m = 3 elements are [1, 2, 3). [1, 2, 4), (1, 3, 4), and [2, 3, 4). Once we have all of the m-element subsequences, we find the value of globalMaximum using the following pseudocode: globalMaximum = 0 for each subsequence, s, consisting of m elements { currentMinimum 1018 for each (x, y) pair of elements in subsequence si absoluteDifference = abs(x - y) if absoluteDifference < currentMinimum currentMinimum = absoluteDifference } } if currentMinimum > globalMaximum { globalMaximum = currentMinimum } } For example, given the array a = [2,3,5,9) and a length m = 3, first find all subsequences of length m. [2,3,5) [2,3,9) [2,5,9] [3,5,9] Debugging output from the pseudocode is: globalMaximum: 0 Subsequence: [2, 3, 5] currentMinimum: 1000000000000000000 x: 3 y: 2 abs(x-y): 1 currentMinimum: 1 x: 5 y: 2 abs(x-y): 3 currentMinimum: 1 x: 5 y: 3 abs(x-y): 2 currentMinimum: 1 globalMaximum: max(globalMaximum, currentMinimum) max(1, 0) = 1 Subsequence: [2, 3, 9] currentMinimum: 1000000000000000000 X: 3 y: 2 abs(x-y): 1 currentMinimum: 1 X: 9 y: 2 abs(x-y): 7 currentMinimum: 1 X: 9 y: 3 abs(x-y): 6 currentMinimum: 1 globalMaximum: max(1, 1) = 1 Subsequence: [2, 5, 9] currentMinimum: 1000000000000000000 X: 5 y: 2 abs(x-y): 3 currentMinimum: 3 X: 9 y: 2 abs(x-y): 7 currentMinimum: 3 2. After the iteration on subsequence {1, 2, 4), the minimum difference between adjacent elements is 1. The value of globalMaximum is 1. 3. After the iteration on subsequence (1, 3, 4), the minimum difference between adjacent elements is 1. The value of globalMaximum is 1. 4. After the iteration on subsequence (2, 3, 4), the minimum difference between adjacent elements is 1. The value of globalMaximum is 1. Thus, the function returns 1 as the answer. Sample Case 1 Sample Input 1 STDIN Function 4 → arr[] size n = 4 [1, 2, 3, 4] 1 arr = 2 3 4 2 m = 2 Sample Output 1 3 Explanation 1 The subsequences of array arr = [1, 2, 3, 4] consisting of m = 2 elements are {1, 2}, {1,3}, {1, 4), (2, 3), (2, 4), and {3,4}. 1. After the iteration on the subsequence {1, 2}, the value of globalMaximum is 1. Explanation 1 The subsequences of array arr = [1, 2, 3, 4) consisting of m = 2 elements are {1, 2}, {1,3}, {1,4} {2, 3), (2, 4), and (3, 4). 1. After the iteration on the subsequence {1, 2}, the value of globalMaximum is 1. 2. After the iteration on the subsequence {1, 3}, the value of globalMaximum is 2. 3. After the iteration on the subsequence {1,4}, the value of globalMaximum is 3. 4. After the iteration on the subsequence (2, 3), the value of globalMaximum is 3. 5. After the iteration on the subsequence (2,4}, the value of globalMaximum is 3. 6. After the iteration on the subsequence (3, 4), the value of globalMaximum is 3. Thus, the function returns 3 as the answer. Sample Case 2 Sample Input 2 STDIN Function 5 1 arr[] size n = 5 arr = [1, 2, 4, 5, 8] 4 5 8 3 > m = 3 Sample Output 2 3 Explanation 2 The subsequences of array arr = [1, 2, 4, 5, 8] consisting of m = 3 elements are {1, 2, 4}, {1, 2, 5}, {1, 2,8}, {1, 4, 5}, {1, 4, 8}, {1, 5, 8}, {2, 4, 5), {2, 4, 8), (2, 5, 8), and {4, 5, 8). Language Java 8 Autocomplete Ready O 15 1 > import java. io.*; ** 14 class Result { 16 17 /* 18 * Complete the 'findMaximum' function below. 19 20 * The function is expected to return an INTEGER. 21 * The function accepts following parameters: 22 1. INTEGER_ARRAY arr 23 2. INTEGER m 24 */ * * * 25 26 27 public static int findMaximum(List arr, int m) { // write your code here 28 29 } 30 31 } 32 33 > public class Solution { ***

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 13:30, gamingisfun
Me ! evelyn is a manager in a retail unit. she wants to prepare a report on the projected profit for the next year. which function can she use? a. pmt b. round c. division d. what-if analysis
Answers: 2
image
Computers and Technology, 23.06.2019 14:00, uday50
Select the correct answer. a company is currently focusing on creating specific management goals for itself. which level of maturity is the company demonstrating under the sse_ccm framework? a. performed informally b. planned and tracked c. quantitatively controlled d. well-defined e. continuously improving
Answers: 2
image
Computers and Technology, 23.06.2019 18:30, bsept1018
Report all segments of identity by descent longer than 20 polymorphisms between pairs of individuals in the following cohort of 15 individuals across 49 polymorphisms: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 numeric input 2 points possible (graded) you have 2 attempts to complete the assignment below. for example if the sequence is "bcd", which occurs in "abcdef" , the starting point would be 2 (b), and the finishing point would be 4(d). individuals 7,10 between positions
Answers: 1
image
Computers and Technology, 23.06.2019 21:30, quintonps12
Which of the following includes the three primary network access technologies? dsl, cable modem, broadband lan, wan, man voip, uc, iptv tcp/ip, ftp, dhcp
Answers: 2
You know the right answer?
Consider an array of distinct positive integers where the elements are sorted in ascending order. We...

Questions in other subjects:

Konu
Mathematics, 05.12.2020 21:40
Konu
Mathematics, 05.12.2020 21:40