Knowee
Questions
Features
Study Tools

Which of the following returns the correct minimum of an array of num integers called values? There can be multiple answers. Question 9Answer a. int Min( int *values, int num){ int i; int min=0; for (i=0; i<num; i++) if (values[i] < min) min = values[i]; return min; } b. int Min( int *values, int num){ int i; int mini=num-1; for (i=0; i<num-1; i++) if (values[i] < values[mini]) mini = i; return values[mini]; } c. int Min( int *values, int num){ int i; int mini=0; for (i=1; i<num; i++) if (values[i] < values[mini]) mini = i; return values[mini]; } d. int Min( int *values, int num){ int i; int min= values[0]; for (i=1; i<num; i++) if (values[i] < min) min = values[i]; return min; } e. int Min( int *values, int num){ int i; int mini=0; for (i=0; i<num; i++) if (values[i] < values[mini]) mini = values[i]; return values[mini]; } f. int Min( int *values, int num){ int i; int mini=num; for (i=0; i<num; i++) if (values[i] < values[mini]) mini = i; return values[mini]; }

Question

Which of the following returns the correct minimum of an array of num integers called values? There can be multiple answers.

Question 9Answer

a. int Min( int *values, int num){ int i; int min=0; for (i=0; i<num; i++) if (values[i] < min) min = values[i]; return min; }

b. int Min( int *values, int num){ int i; int mini=num-1; for (i=0; i<num-1; i++) if (values[i] < values[mini]) mini = i; return values[mini]; }

c. int Min( int *values, int num){ int i; int mini=0; for (i=1; i<num; i++) if (values[i] < values[mini]) mini = i; return values[mini];

}

d. int Min( int *values, int num){ int i; int min= values[0]; for (i=1; i<num; i++) if (values[i] < min) min = values[i]; return min; }

e. int Min( int *values, int num){ int i; int mini=0; for (i=0; i<num; i++) if (values[i] < values[mini]) mini = values[i]; return values[mini]; }

f. int Min( int *values, int num){ int i; int mini=num; for (i=0; i<num; i++) if (values[i] < values[mini]) mini = i; return values[mini]; }

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answers are options b, c, and d.

Here's why:

a. This option is incorrect because it initializes min as 0. If all the numbers in the array are greater than 0, it will return 0 even if 0 is not in the array.

b. This option is correct. It initializes mini as the index of the last element in the array and then checks each element to see if it's less than the current minimum. If it is, it updates mini to the current index. It then returns the smallest value found.

c. This option is correct. It initializes mini as the index of the first element in the array and then checks each subsequent element to see if it's less than the current minimum. If it is, it updates mini to the current index. It then returns the smallest value found.

d. This option is correct. It initializes min as the first element in the array

This problem has been solved

Similar Questions

01.Find the minimum element and its index in an array 3.5 marks Problem Statement You are given a function, void MinInArray(int arr[], int length); The function accepts an integer array 'arr' of size 'length' as its argument. Implement the function to find the minimum element of the array and print the minimum element and its index to the standard output (STDOUT). The minimum element and its index should be printed in separate lines. Note: Array index starts with 0 Minimum element and its index should be separated by a line in the output Assume there is only 1 minimum element in the array Print exactly what is asked, do not print any additional greeting messages Example: Input: 23 45 82 27 66 12 78 13 71 86 Output: 12 5 Explanation: 12 is the minimum element of array at index 5. The custom input format for the above case: 10 23 45 82 27 66 12 78 13 71 86 (The first line represents the size of the array, the second line represents the elements of the array) Sample input 1 9 11 144 6 7 112 95 Sample Output 1 0 The custom input format for the above case: 8 1 9 11 144 6 7 112 95 (The first line represents the size of the array, the second line represents the elements of the array) Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcome/greeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time. give me the code

Find the incorrect statement in the following code of minimum cost path?int min_cost(int** input, int si, int sj, int ei, int ej) {if (si == ei && sj == ej) { return input[ei][ej];}if (si > ei || sj > ej) { return INT_MAX;}int option1 = min_cost(input, si + 1, sj, ei, ej);// Statement 1int option2 = min_cost(input, si - 1 , sj - 1 , ei, ej);// Statement 2int option3 = min_cost(input, si, sj + 1, ei, ej);// Statement 3return input[si][sj] + min(option1, min(option2, option3));}

Given an array of integers, your task is to find the smallest and second smallest element in the array. If smallest and second smallest do not exist, print -1.

Find below the shuffled code to find the minimum number in the array. Arrange it in correct order.Scanner sc=new Scanner(System.in);System.out.println("Enter the elements of the array");for(int i=0;i<n;i++)  {minimum=arr[i];}}for(int i=0;i<n;i++){      if(arr[i]<minimum) {System.out.println("Enter the number of elements in the array");int n = sc.nextInt();arr[i]=sc.nextInt();}int arr[]=new int[n];import java.util.Scanner;System.out.println("Minimum element is "+minimum);}}public class Test {public static void main(String[] args) {int minimum=arr[0];

You are given two integer arrays nums1 and nums2.From nums1 two elements have been removed, and all other elements have been increased (or decreased in the case of negative) by an integer, represented by the variable x.As a result, nums1 becomes equal to nums2. Two arrays are considered equal when they contain the same integers with the same frequencies.Return the minimum possible integer x that achieves this equivalence. Example 1:Input: nums1 = [4,20,16,12,8], nums2 = [14,18,10]Output: -2Explanation:After removing elements at indices [0,4] and adding -2, nums1 becomes [18,14,10].Example 2:Input: nums1 = [3,5,5,3], nums2 = [7,7]Output: 2Explanation:After removing elements at indices [0,3] and adding 2, nums1 becomes [7,7]. Constraints:3 <= nums1.length <= 200nums2.length == nums1.length - 20 <= nums1[i], nums2[i] <= 1000The test cases are generated in a way that there is an integer x such that nums1 can become equal to nums2 by removing two elements and adding x to each element of nums1.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.