Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume we are using quicksort to sort an array in ascending order. Into which array location does quicksorts strategy place a pivot element after partitioning?

Assume we are using quicksort to sort an array in ascending order. Into which array location does quicksorts strategy place a pivot element after partitioning?

lowest index in array still available

highest index in array still available

closer to its correct final location

its final correct location

1 points

QUESTION 2

Complete the following code that is intended to provide a comparator interface that will be used to create an object that implements the Comparator interface so that object can compare Auto objects.

___________________________ 
{ 
 int compare(Auto a, Auto b); 
} 

public class Comparator

public class Comparator implements Comparator

public interface Auto

public interface Comparator

1 points

QUESTION 3

Which selection sort iteration guarantees the array is sorted for a 10-element array?

9th iteration

10th iteration

1st iteration

impossible to tell

1 points

QUESTION 4

In the textbook, we found that the number of element visits for merge sort totaled

n + 5nlog2n. Lets consider sorting 1024 elements. How many visits are needed?

1.024

6,144

51,200

52,224

1 points

QUESTION 5

Can you search the following array using binary search?

int[] A = {6, 5, 4, 2, 0, 1, -1, -17}; 

Yes. Binary search can be applied to any array.

No. Binary search can be applied to a sorted array only.

Yes, but the algorithm runs slower because the array is in descending order.

No, negative numbers are not allowed because they indicate that a value is not present.

1 points

QUESTION 6

Given the following code snippet for searching an array:

int[] arr = {23, 25, 29, 34, 42}; 
int newVal = 15; 
int pos = Arrays.binarySearch(arr, newVal); 

What value will pos have when this code is executed?

0

1

-1

-2

1 points

QUESTION 7

Suppose you have a phone number and need to find the address that it corresponds to. If there are 2,000,000 entries, how many do you expect to search in a printed phone directory before finding the address you are looking for?

Approximately 50,000 records.

Approximately 75,000 records.

Approximately 1,000,000 records.

Approximately 1,200,000 records.

1 points

QUESTION 8

In each iteration, selection sort places which element in the correct location?

The smallest in the array.

The smallest element not yet placed in prior iterations.

The largest element in the array.

A random element.

1 points

QUESTION 9

Suppose an array has n elements. We visit element #1 one time, element #2 two times, element #3 three times, and so forth. How many total visits will there be?

2n

n(n+1)/2

n2

n3

1 points

QUESTION 10

After one iteration of selection sort working on an array of 10 elements, what must hold true?

The array cannot be sorted.

One element must be correctly placed.

At least two elements are correctly placed.

The largest element is correctly placed.

1 points

QUESTION 11

If the Arrays static method binarySearch is called on an array of 10 elements and returns a value of 10, what can be concluded?

I the element is not found

II that value cannot be returned from method binarySearch

III if added, the element would be the largest element in the array

I

II

III

I and III

1 points

QUESTION 12

A version of which sort algorithm is used in the sort method in the Java Arrays class?

merge sort

quicksort

selection sort

insertion sort

1 points

QUESTION 13

Consider the following code snippet:

public static void sort(int[] a) 
{ 
 for (int i = 1; i < a.length; i++) 
 { 
 int next = a[i]; 
 int j = i; 
 while (j > 0 && a[j - 1] > next) 
 { 
 a[j] = a[j - 1]; 
 j--; 
 } 
 a[j] = next; 
 } 
} 

What sort algorithm is used in this code?

insertion sort

selection sort

merge sort

quicksort

1 points

QUESTION 14

Which of the following arrays can be used in a call to the Arrays.sort method?

I Any array with primitive numeric data, such as int, double,

II Arrays of String or numeric wrapper classes like, Integer, Double,

III Any class that implements the Comparable interface

I

II

I and II

I, II and III

1 points

QUESTION 15

If a call to the Arrays static method binarySearch returns a value of -10, what can be concluded?

I the element is not in the array

II the element is at index 10

III the element can be inserted at index 9

I

II

III

I and III

1 points

QUESTION 16

Another name for linear search is ____ search.

sorted

sequential

random

binary

1 points

QUESTION 17

After 9 iterations of selection sort working on an array of 10 elements, what must hold true?

The largest element is correctly placed by default.

One more iteration is needed to complete the sort.

The smallest element is incorrectly placed.

The largest element is incorrectly placed.

1 points

QUESTION 18

Suppose a developer gets class XYZ files and documentation from a subcontractor. This class does not implement the Comparable interface. What must be true in order for the developer to sort an array of XYZ objects without modifying the xyz class?

The XYZ class must implement the Sortable interface.

XYZ objects must be randomly distributed.

XYZ objects must be ordered.

The developer must supply a comparator object belonging to a class that implements the Comparator interface.

1 points

QUESTION 19

Consider an array with n elements. If we visit each element n times, how many total visits will there be?

n

2n

nn

n2

1 points

QUESTION 20

Suppose we are using binary search on an array with approximately 1,000,000 elements. How many visits should we expect to make in the worst case?

1

16

20

30

1 points

Click Save and Submit to save and submit. Click Save All Answers to save all answers.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago