Answer:
The answer is (C)
Let’s run the algorithm on a small input to see the working process.
Let say we have an array {3, 4, 1, 5, 2, 7, 6}. MAX = 7
- Now for i=0, i < 7/2, here we exchange the value at ith index with value at (MAX-i-1)th index.
- So the array becomes {6, 4, 1, 5, 2, 7, 3}. //value at 0th index =3 and value at (7-0-1)th index is 6.
- Then for i=1, i < 7/2, the value at index 1 and (7-1-1)=5 are swapped.
- So the array becomes {6, 7, 1, 5, 2, 4, 3}.
- Then for i=2, i < 7/2, the value at index 2 and (7-2-1)=4 are swapped.
- So the array becomes {6, 7, 2, 5, 1, 4, 3}.
- Then for i=3, i not < 7/2, so stop here.
- Now the current array is {6, 7, 2, 5, 1, 4, 3} and the previous array was{3, 4, 1, 5, 2, 7, 6}.
Explanation:
So from the above execution, we got that the program reverses the numbers stored in the array.
Answers:
1. D
2. A
3. B
4. C
Explanation: I just did it and got a 100%
Any image that helps you, the reader, understand the text that the visual aid is accompanied with is referred to as a visual graphic or graphic aid.
Too frequently, readers lazily scan or entirely ignore graphs, diagrams, charts, and tables. Grid graphs, tables, bar charts, flow charts, maps, pie diagrams, and drawings and sketches are the most popular. Relationships are displayed using grid graphs. A visual aid should always be used in conjunction with preparation to interest the audience, improve their comprehension of your message, elicit an emotional response, and assist you in communicating it effectively. Charts, diagrams, graphs, maps, flashcards, posters, images, photos, booklets, folders, pamphlets, cartoons, and comics are examples of graphic aids.
Learn more about graphic here-
brainly.com/question/1169945
#SPJ4
Since both arrays are already sorted, that means that the first int of one of the arrays will be smaller than all the ints that come after it in the same array. We also know that if the first int of arr1 is smaller than the first int of arr2, then by the same logic, the first int of arr1 is smaller than all the ints in arr2 since arr2 is also sorted.
public static int[] merge(int[] arr1, int[] arr2) {
int i = 0; //current index of arr1
int j = 0; //current index of arr2
int[] result = new int[arr1.length+arr2.length]
while(i < arr1.length && j < arr2.length) {
result[i+j] = Math.min(arr1[i], arr2[j]);
if(arr1[i] < arr2[j]) {
i++;
} else {
j++;
}
}
boolean isArr1 = i+1 < arr1.length;
for(int index = isArr1 ? i : j; index < isArr1 ? arr1.length : arr2.length; index++) {
result[i+j+index] = isArr1 ? arr1[index] : arr2[index]
}
return result;
}
So this implementation is kind of confusing, but it's the first way I thought to do it so I ran with it. There is probably an easier way, but that's the beauty of programming.
A quick explanation:
We first loop through the arrays comparing the first elements of each array, adding whichever is the smallest to the result array. Each time we do so, we increment the index value (i or j) for the array that had the smaller number. Now the next time we are comparing the NEXT element in that array to the PREVIOUS element of the other array. We do this until we reach the end of either arr1 or arr2 so that we don't get an out of bounds exception.
The second step in our method is to tack on the remaining integers to the resulting array. We need to do this because when we reach the end of one array, there will still be at least one more integer in the other array. The boolean isArr1 is telling us whether arr1 is the array with leftovers. If so, we loop through the remaining indices of arr1 and add them to the result. Otherwise, we do the same for arr2. All of this is done using ternary operations to determine which array to use, but if we wanted to we could split the code into two for loops using an if statement.
Answer is Xero. All the other Languages are Popular and Widely Used.
Thank You!