
Unit 8 - Searching and Sorting
Authored by Terresa Uzzle
Computers
9th - 12th Grade
Used 4+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following method:
public String mystery(String myString, int index) {
if (index >= myString.length()) {
return myString;
}
return myString + mystery(myString.substring(index), index + 2);
}
What is printed as a result of executing the following line of code?
System.out.println(mystery("CSA is the best!", 0));
CSA is the best!
CSA is the best!CSA is the best!A is the best! the best!est!
CSA is the best! A is the best! The best! est! est!
CSA is the best!A is the best! The best!est!
CSA is the best!A is the best! The best!
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the code to the left:
Which of the following replacements for /* missing code */ will cause the loop in the method to run the maximum number of iterations (method runs in the worst case)?
I. {11, 28, 5, 25, 86}
II. {86, 25, 11, 5, 28}
III. {11, 25, 5, 99, 28}
I only
II only
III only
I and II only
I and III only
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
The following method is intended to return the index of the location of target in the array arr, -1 otherwise:
public int find(String[] arr, String target) {
for (int i = arr.length - 1; i >= 0; i--) {
if (target.equals(arr[i])){
return i;
}
return -1;
}
return -1;
}
Which of the following best explains why the method does not work as intended?
There are two return statements that return -1
It starts traversing at the end of the array
When the target is not the last element, it returns -1 instead of traversing the rest of the array
The array index goes out of bounds
There is no error; it works as intended
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Suppose the binarySearch method is called with an array containing 10 elements sorted in increasing order. What is the maximum number of times that the statement indicated by /* calculate midpoint */ could execute?
4
5
9
10
11
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the method to the left, which implements a recursive binary search that returns an index in arr where the value x appears if x appears in arr between arr[left] and arr[right], inclusive; otherwise returns -1.
The following code segment appears in a method in the same class as bSearch.
int[] nums = {2, 3, 3, 6, 7, 9};
int result = bSearch(nums, 0, nums.length - 1, 3);
What is the value of result after the code segment has been executed?
1
2
3
4
5
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the method to the left, which implements a recursive binary search that returns an index in myList where target appears, if target appears in myList between the elements at indices low and high, inclusive; otherwise returns -1.
Assume that inputList is an ArrayList of Integer objects that contains the following values.
[0, 5, 10, 15, 20, 25, 25, 25, 25]
What value will be returned by the call binarySearch(inputList, 0, 8, 25)?
-1
5
6
7
9
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Consider the sort method to the left. This method correctly sorts the elements of array data into increasing order.
Assume that selectSort is called with the array {16, 13, 12, 50, 40, 10}. 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 */) ?
{10, 12, 12, 50, 40, 10}
{10, 12, 13, 16, 40, 50}
{10, 13, 12, 50, 40, 16}
{10, 12, 13, 50, 40, 16}
{10, 12, 13, 50, 40, 10}
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
User Interface Design - Topic 1
Quiz
•
12th Grade
20 questions
TEST1.PY
Quiz
•
10th Grade - University
20 questions
Berpikir Komputasional
Quiz
•
9th - 12th Grade
16 questions
Serial Communication - Sensors
Quiz
•
9th Grade
15 questions
Integrasi Aplikasi Office 365
Quiz
•
10th Grade
10 questions
Initial Assessment - Cybersecurity Awareness
Quiz
•
9th Grade - Professio...
15 questions
Q1 W1 M1 PRE-TEST
Quiz
•
10th Grade
20 questions
Database&Relation
Quiz
•
12th Grade
Popular Resources on Wayground
7 questions
History of Valentine's Day
Interactive video
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
15 questions
Valentine's Day Trivia
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
10 questions
Exploring Valentine's Day with Charlie Brown
Interactive video
•
6th - 10th Grade
18 questions
Valentines Day Trivia
Quiz
•
3rd Grade - University
20 questions
El Verbo IR Practice
Quiz
•
9th Grade
20 questions
-AR -ER -IR present tense
Quiz
•
10th - 12th Grade
10 questions
Valentine's Day History and Traditions
Interactive video
•
6th - 10th Grade
20 questions
Graphing Inequalities on a Number Line
Quiz
•
6th - 9th Grade
20 questions
Exponent Properties
Quiz
•
9th Grade
21 questions
Presidents Day Trivia
Quiz
•
6th - 12th Grade