Search Header Logo

Sorting Questions

Authored by SAMUEL KEENER

Computers

11th Grade

Used 3+ times

Sorting Questions
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

9 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume that insertionSort has been called with an ArrayList parameter that has been initialized with the following Integer objects.

[5, 2, 4, 1, 3, 6]

What will the contents of data be after three passes of the outside loop (i.e., when j == 3 at the point indicated by /* End of outer loop */) ?

[1, 2, 3, 4, 5, 6]

[1, 2, 3, 5, 4, 6]

[1, 2, 4, 5, 3, 6]

[2, 4, 5, 1, 3, 6]

[5, 2, 1, 3, 4, 6]

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume that array arr has been defined and initialized with the values {5, 4, 3, 2, 1}. What are the values in array arr after two passes of the for loop (i.e., when j = 2 at the point indicated by / end of for loop / ) ?

{2, 3, 4, 5, 1}

{3, 2, 1, 4, 5}

{3, 4, 5, 2, 1}

{3, 5, 2, 3, 1}

{5, 3, 4, 2, 1}

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

The following declaration and method call appear in a method in the same class as insertionSort.

int[] arr = {4, 12, 4, 7, 19, 6};

insertionSort(arr);

How many times is the statement possibleIndex--; in line 10 of the method executed as a result of the call to insertionSort ?

2

3

4

5

6

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

The following declaration and method call appear in the same class as selectionSort.

int[] vals = {5, 10, 2, 1, 12};

selectionSort(vals);

How many times is the statement minIndex = k; in line 11 of the method executed as a result of the call to selectionSort ?

0

1

2

3

4

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Which of the following changes should be made so that selectSort will work as intended?

Line 1 should be changed to

  for (int j = 0; j < numbers.length - 2; j++)

Line 2 should be changed to

  int pos = j;

Line 3 should be changed to

  for (int k = 0; k < numbers.length; k++)

Line 4 should be changed to

  if (numbers[k] > numbers[pos])

Line 5 should be changed to

  k = pos;

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume arr is the following array.

{"Ann","Mike","Walt","Lisa","Shari","Jose","Mary",“Bill”}

What is the intermediate value of arr after two iterations of the outer for loop in the call sort(arr)?

"Ann""Mike""Walt""Lisa""Shari""Jose""Mary"“Bill”

"Ann""Mike""Lisa""Shari""Jose""Mary"“Bill”"Walt"

"Ann"“Bill”"Jose""Lisa""Mary""Mike""Shari""Walt"

"Ann""Mike"“Bill”"Lisa""Mary""Jose""Shari""Walt"

"Walt""Shari""Ann""Lisa""Mike""Jose""Mary"“Bill”

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume that sort is called with the array {6, 3, 2, 5, 4, 1}. What will the value of data be after three passes of the outer loop (i.e., when j = 2 at the point indicated by / End of outer loop /) ?

{1, 2, 3, 4, 5, 6}

{1, 2, 3, 5, 4, 6}

{1, 2, 3, 6, 5, 4}

{1, 3, 2, 4, 5, 6}

{1, 3, 2, 5, 4, 6}

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?