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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:00
Why should characters such as / \ " ' * ; - ? [ ] ( ) ~ ! $ { } < > # @ & | space, tab, and newline be avoided in file names?
Answers: 2
question
Computers and Technology, 22.06.2019 22:30
I'll mark brainliest if answered right! with which feature or menu option of a word processing program can you make an image like this? you can get this image using the option of a word processing program.
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
Which of the following is not an enhancement to the standard wiki to make it more attractive for corporations? encryptionwork spacespermission toolspredictive text
Answers: 2
question
Computers and Technology, 24.06.2019 17:30
Match the following. 1. formatting that is applied when cell data meets certain criteria 2. borders with formats not found on the border tool 3. a shortcut bar that contains tools for commonly used formats 4. formats that can be applied to numbers conditional formatting custom borders format bar number formats
Answers: 3
You know the right answer?
Consider an array of distinct positive integers where the elements are sorted in ascending order. We...
Questions
question
Mathematics, 01.12.2020 01:00
question
Mathematics, 01.12.2020 01:00
question
Mathematics, 01.12.2020 01:00
question
Mathematics, 01.12.2020 01:00
Questions on the website: 13722362