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 07:30
Events and conditions that happen within an organization that are somewhat easier to deal with when responding to change are called
Answers: 1
question
Computers and Technology, 22.06.2019 19:00
Which parts of a presentation should be the most general? a. introduction and conclusion b. introduction and outline c. outline and conclusion d. outline and body
Answers: 1
question
Computers and Technology, 23.06.2019 01:50
Free points just awnser this. what should i watch on netflix
Answers: 2
question
Computers and Technology, 23.06.2019 03:10
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
You know the right answer?
Consider an array of distinct positive integers where the elements are sorted in ascending order. We...
Questions
question
Business, 26.09.2019 04:30
question
Mathematics, 26.09.2019 04:30
Questions on the website: 13722367