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 19:30
Singing in the rain: this first part of the film shows the early history of motion picture. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theater productions? explain.
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
What is the primary difference between the header section of a document and the body? a. the body is displayed on the webpage and the header is not. b. the header is displayed on the webpage and the body is not. c. the tag for the body is self-closing, but the tags for the headers must be closed. d. the tag for the header is self closing, but the tag for the body must be closed.
Answers: 3
question
Computers and Technology, 23.06.2019 23:30
What are "open-loop" and "closed-loop" systems
Answers: 1
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
Consider an array of distinct positive integers where the elements are sorted in ascending order. We...
Questions
question
Spanish, 25.04.2020 00:00
question
History, 25.04.2020 00:00
question
Mathematics, 25.04.2020 00:00
question
English, 25.04.2020 00:00
Questions on the website: 13722363