
Unit 10 Quizziz Review

Quiz
•
Mathematics
•
12th Grade
•
Hard
Nichole Niebur
Used 1+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following recursive method, which is intended to display the binary equivalent of a decimal number. For example, toBinary(100) should display 1100100.
Which of the following can replace /* missing code */ so that toBinary works as intended?
System.out.print(num % 2);
toBinary(num / 2);
System.out.print(num / 2);
toBinary(num % 2);
toBinary(num % 2);
System.out.print(num / 2);
toBinary(num / 2);
System.out.print(num % 2);
toBinary(num / 2);
System.out.print(num / 2);
Answer explanation
This will recursively call toBinary on the value of num / 2 until the value of the parameter is less than 2. Then either 0 or 1 is displayed depending on whether the parameter is even or odd. This represents the leftmost digit of the binary equivalent. After the base case is reached, either 0 or 1 will continue to be displayed for each of the previous recursive calls to toBinary.
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following recursive method, which is intended to return a String with any consecutive duplicate characters removed. For example, removeDupChars("aabcccd") returns "abcd".
Which of the following can replace /* missing code */ so that removeDupChars works as intended?
return removeDupChars(str.substring(2));
return removeDupChars(str.substring(1)) + str.substring(0, 1);
return removeDupChars(str.substring(2)) + str.substring(1, 2);
return str.substring(0, 1) + removeDupChars(str.substring(1));
return str.substring(1, 2) + removeDupChars(str.substring(2));
Answer explanation
This is executed when two consecutive characters are not the same. The first character in str is concatenated to the string returned from the recursive call to removeDupChars. Each time removeDupChars is recursively called, it uses the string that begins at the second character of str, thus working down to the base case. When the base case is reached, the string that is returned from each recursive call to removeDupChars represents an accumulation of the previously returned strings and is concatenated to the single character that was extracted before the recursive call.
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following method, which is intended to return the sum of all the even digits in its parameter num. For example, sumEvens(15555234) should return 6, the sum of 2 and 4.
Which of the following can be used as a replacement for /* missing statement */ so that the sumEvens method works as intended?
return sumEvens(num % 10);
return sumEvens(num / 10);
return num % 10 + sumEvens(num % 10);
return num % 10 + sumEvens(num / 10);
return num / 10 + sumEvens(num % 10);
Answer explanation
This statement is executed in the case where num has more than one digit and the rightmost digit is even. In this case, the method should return the rightmost digit (num % 10) plus the result of calling sumEvens recursively on all digits of num but the rightmost digit (sumEvens(num / 10)).
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following method.
Which of the following best describes the output produced by the method call mystery(val) ?
All integers from 1 to val, separated by spaces
All integers from val to 1, separated by spaces
The digits of val in their original order, separated by spaces
The digits of val in reverse order, separated by spaces
The last digit of val, then a space, then the first digit of val
Answer explanation
Each method call prints the current value of n and calls mystery recursively with the parameter n - 1. The base case is when the parameter n has the value 1; in this case, 1 is printed and no further recursive calls are executed.
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following recursive method.
Which of the following best describes the result of the call doSomething(myString) ?
The method call returns a String containing the contents of myString unchanged.
The method call returns a String containing the contents of myString with the order of the characters reversed from their order in myString.
The method call returns a String containing all but the first character of myString.
The method call returns a String containing only the first and second characters of myString.
The method call returns a String containing only the first and last characters of myString.
Answer explanation
When there is at least one character in str, the method returns the first character of str concatenated with the value returned by a recursive call. The parameter of the recursive call is the substring of str starting at the second character. As a result, the original string is reconstructed recursively.
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following recursive method.
Which of the following best describes the value returned by the method call calc(num) ?
The int value 9
The leftmost digit of num
The rightmost digit of num
The number of digits in num
The result of the integer division of num by 10
Answer explanation
In each recursive call, the rightmost digit of the parameter n is truncated. In the final call to calc, n contains only a single digit. The value of n, or the leftmost digit of the parameter num in the original call to calc, is returned.
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following code segment, which appears in a method in the same class as mergeSortHelper and merge.
int[] arr1 = {9, 1, 3, 5, 4};
int[] temp = new int[arr1.length];
mergeSortHelper(arr1, 0, arr1.length - 1, temp);
Which of the following represents the arrays merged the first time the merge method is executed as a result of the code segment above?
{9} and {1} are merged to form {1, 9}.
{1, 9} and {3} are merged to form {1, 3, 9}.
{1, 9} and {5, 4} are merged to form {1, 4, 5, 9}.
{1, 3, 9} and {5} are merged to form {1, 3, 5, 9}.
{1, 3, 9} and {4, 5} are merged to form {1, 3, 4, 5, 9}.
Answer explanation
The merge method appears after both recursive calls in the mergeSortHelper method, so it is not called until the condition from < to evaluates to false and there are no more recursive calls to execute. This occurs when the two parts of the array to merge each contain one element. The original array is split into {9, 1, 3} and {5, 4}. The array segment {9, 1, 3} is split into {9, 1} and {3}. The array segment {9, 1} is split into {9} and {1} and these two array segments are merged to form {1, 9}.
Create a free account and access millions of resources
Similar Resources on Wayground
15 questions
Unit 6 Pre-Assessment - Algorithms

Quiz
•
11th - 12th Grade
16 questions
AP Calculus AB - Important Formulas/Theorems

Quiz
•
11th - 12th Grade
20 questions
Algebra Unit 2 Review

Quiz
•
9th Grade - University
21 questions
Graphs & Key Features of Exponential Functions

Quiz
•
9th - 12th Grade
15 questions
Indefinite Integrals

Quiz
•
11th - 12th Grade
20 questions
Fundamental Theorem of Calculus (BPS)

Quiz
•
11th Grade - University
22 questions
Number Systems & Binary Maths

Quiz
•
10th - 12th Grade
18 questions
Lập trình C

Quiz
•
12th Grade
Popular Resources on Wayground
12 questions
Unit Zero lesson 2 cafeteria

Lesson
•
9th - 12th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
20 questions
Lab Safety and Equipment

Quiz
•
8th Grade
13 questions
25-26 Behavior Expectations Matrix

Quiz
•
9th - 12th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Mathematics
31 questions
Week 1 Student Practice Set

Quiz
•
9th - 12th Grade
16 questions
Multiplication Facts

Quiz
•
3rd - 12th Grade
15 questions
Solving Multistep Equations

Quiz
•
9th - 12th Grade
27 questions
Algebra 2 Unit 1 Lesson 1-7 review

Quiz
•
9th - 12th Grade
13 questions
Coordinate Plane Review

Lesson
•
9th - 12th Grade
58 questions
Integer Operations

Quiz
•
5th - 12th Grade
20 questions
Points, Lines, & Planes

Quiz
•
12th Grade
14 questions
Successful Online Learning

Quiz
•
1st - 12th Grade