0%
0 / 15 answered
Implementing Selection and Iteration Algorithms Practice Test
•15 QuestionsQuestion
1 / 15
Q1
Given the task requirements, which of the following correctly implements the required loop structure?
Implement insertion sort to sort an integer array in ascending order. Use iteration to shift larger elements to the right, and selection to decide when shifting stops.
Input: $n$, then $n$ integers.
Output: the sorted array.
Constraints: $1 \le n \le 100$; values in -1000, 1000.
Example input:
4
5 2 9 1
Example output:
1 2 5 9
Choose the correct inner loop for insertion sort (assume key = a<u>i</u> and j = i - 1):
Given the task requirements, which of the following correctly implements the required loop structure?
Implement insertion sort to sort an integer array in ascending order. Use iteration to shift larger elements to the right, and selection to decide when shifting stops.
Input: $n$, then $n$ integers.
Output: the sorted array.
Constraints: $1 \le n \le 100$; values in -1000, 1000.
Example input:
4
5 2 9 1
Example output:
1 2 5 9
Choose the correct inner loop for insertion sort (assume key = a<u>i</u> and j = i - 1):