Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For Questions 1 6 1 9 refer to the insertionSort method and the private instance variable a , both in a Sorter class. private Integer
For Questions refer to the insertionSort method and the private instance variable a both in a Sorter class.
private Integer a;
Precondition: aaaalength is an unsorted array
of Integer objects.
Postcondition: Array a is sorted in descending order.
public void insertionSort
for int i ; i alength; i
Integer temp ai;
int j i ;
while j && temp.compareToaj
aj aj;
j;
aj temp;
An array of Integer is to be sorted biggest to smallest using the insertionSort
method. If the array originally contains
what will it look like after the third pass of the for loop?
A
B
C
D
E
When sorted biggest to smallest with insertionSort, which list will need the
fewest changes of position for individual elements?
A
B
C
D
E
When sorted biggest to smallest with insertionSort, which list will need the
greatest number of changes in position?
A
B
C
D
E
While typing the insertionSort method, a programmer by mistake enters
while tempcompareTo aj
instead of
while j && temp.compareTo aj
Despite this mistake, the method works as intended the first time the programmer enters an array to be sorted in descending order. Which of the following
could explain this?
I The first element in the array was the largest element in the array.
II The array was already sorted in descending order.
III The first element was less than or equal to all the other elements in the array.
A I only
B II only
C III only
D I and II only
E II and III only
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started