Sorting Questions

Sorting Questions

11th Grade

9 Qs

quiz-placeholder

Similar activities

AP Computer Science A Unit 6 Lesson 1 (Introduction)

AP Computer Science A Unit 6 Lesson 1 (Introduction)

10th - 12th Grade

5 Qs

Sorting Algorithms

Sorting Algorithms

9th - 12th Grade

10 Qs

Berfikir Komputesional

Berfikir Komputesional

9th - 12th Grade

10 Qs

CodeHS Arraylist

CodeHS Arraylist

10th - 12th Grade

5 Qs

AP CS A Unit 6 Quiz PRACTICE

AP CS A Unit 6 Quiz PRACTICE

9th - 12th Grade

10 Qs

Unit 6 Arrays

Unit 6 Arrays

10th - 12th Grade

14 Qs

Xб_сор

Xб_сор

9th - 12th Grade

10 Qs

Searching & Sorting Algorithms

Searching & Sorting Algorithms

11th Grade

10 Qs

Sorting Questions

Sorting Questions

Assessment

Quiz

Computers

11th Grade

Hard

Created by

SAMUEL KEENER

Used 3+ times

FREE Resource

AI

Enhance your content

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

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}

8.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume that sort is called with the array {1, 2, 3, 4, 5, 6}. How many times will the expression indicated by /* Compare values / and the statement indicated by / Assign to temp */ execute?

Compare values: 15

Assign to temp: 0

Compare values: 15

Assign to temp: 5

Compare values: 15

Assign to temp: 6

Compare values: 21

Assign to temp: 5

Compare values: 21

Assign to temp: 6

9.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Assume that swap(arr, j, pos) exchanges the values of arr[j] and arr[pos]. Which of the following could be used to replace /* missing code */ so that executing the code segment sorts the values in array arr?

k = j - 1; k > 0; k--

k = j - 1; k >= 0; k--

k = 1; k < arr.length; k++

k = 1; k > arr.length; k++

k = 0; k <= arr.length; k++

Discover more resources for Computers