Computers and Technology

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 { ***

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 20:30, oofoofoof1
Write a program that reads the file, then displays the average number of steps taken for each month. (the data is from a year that was not a leap year, so february has 28 days.) your program needs to use at least 3 functions not counting main and display the information in a neat well formatted fashion.
Answers: 3
image
Computers and Technology, 23.06.2019 06:30, eddsworldfrantic
You have a small company and want to keep your costs low, but it is important your employees share data. which network would provide you with the most economical solution?
Answers: 1
image
Computers and Technology, 23.06.2019 10:50, Leffew
The volume v and paper surface area a of a conical paper cup are given by where r is the radius of the base of the cone and h is the height of the cone. a. by eliminating h, obtain the expression for a as a function of r and v. b. create a user-de ned function that accepts r as the only argument and computes a for a given value of v. declare v to be global within the function. c. for v ! 10 in.3 , use the function with the fminbnd function to compute the value of r that minimizes the area a. what is the corresponding value of the height h? investigate the sensitivity of the solution by plotting v versus r. how much can r vary about its optimal value before the area increases 10 percent above its minimum value?
Answers: 1
image
Computers and Technology, 23.06.2019 23:30, jamalchris9353
Worth 50 points answer them bc i am not sure if i am wrong
Answers: 1
Do you know the correct answer?
Consider an array of distinct positive integers where the elements are sorted in ascending order. We...

Questions in other subjects: