
Unit 10 APCSA

Quiz
•
Computers
•
12th Grade
•
Medium
Jeff Cougger
Used 5+ times
FREE Resource
44 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method.
public int addFun(int n)
{
if (n <= 0)
return 0;
if (n == 1)
return 2;
return addFun(n - 1) + addFun(n - 2);
}
What value is returned as a result of the call addFun(6) ?
12
10
16
26
32
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method, which implements a recursive binary search.
/** 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.
* Precondition: arr is sorted in ascending order.
* left >= 0, right < arr.length, arr.length > 0
*/
public static int bSearch(int[] arr, int left, int right, int x)
{
if (right >= left)
{
int mid = (left + right) / 2;
if (arr[mid] == x)
{
return mid;
}
else if (arr[mid] > x)
{
return bSearch(arr, left, mid - 1, x);
}
else
{
return bSearch(arr, mid + 1, right, x);
}
}
return -1;
}
The following code segment appears in a method in the same class as bSearch.
int[] nums = {0, 4, 4, 5, 6, 7};
int result = bSearch(nums, 0, nums.length - 1, 4);
What is the value of result after the code segment has been executed?
1
2
3
4
5
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method, which implements a recursive binary search.
/** 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.
* Precondition: myList is sorted in ascending order.
* low >= 0, high < myList.size(), myList.size() > 0
*/
public static int binarySearch(ArrayList<Integer> myList,
int low, int high, int target)
{
int mid = (high + low) / 2;
if (target < myList.get(mid))
{
return binarySearch(myList, low, mid - 1, target);
}
else if (target > myList.get(mid))
{
return binarySearch(myList, mid + 1, high, target);
}
else if (myList.get(mid).equals(target))
{
return mid;
}
return -1;
}
Assume that inputList is an ArrayList of Integer objects that contains the following values.
[0, 10, 30, 40, 50, 70, 70, 70, 70]
What value will be returned by the call binarySearch(inputList, 0, 8, 70) ?
-1
5
6
7
8
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method.
public static int calcMethod(int num)
{
if (num == 0)
{
return 10;
}
return num + calcMethod(num / 2);
}
What value is returned by the method call calcMethod(16) ?
10
26
31
38
41
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following two static methods, where f2 is intended to be the iterative version of f1.
public static int f1(int n)
{
if (n < 0)
{
return 0;
}
else
{
return (f1(n - 1) + n * 10);
}
}
public static int f2(int n)
{
int answer = 0;
while (n > 0)
{
answer = answer + n * 10;
n--;
}
return answer;
}
The method f2 will always produce the same results as f1 under which of the following conditions?
I. n < 0
II. n = 0
III. n > 0
I only
II only
III only
II and III only
I, II, and III
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method.
public String goAgain(String str, int index)
{
if (index >= str.length())
return str;
return str + goAgain(str.substring(index), index + 1);
}
What is printed as a result of executing the following statement?
System.out.println(goAgain("today", 1));
today
todayto
todayoday
todayodayay
todayodaydayayy
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Directions: Select the choice that best fits each statement. The following question(s) refer to the following information
Consider the following binarySearch method. The method correctly performs a binary search.
Consider the following code segment.
int [ ] values = {1, 2, 3, 4, 5, 8, 8, 8};int target = 8;
What value is returned by the call binarySearch (values, target) ?
-1
3
5
6
8
Create a free account and access millions of resources
Similar Resources on Wayground
43 questions
C++ Chapter 10

Quiz
•
9th - 12th Grade
41 questions
Midterm prep 7th

Quiz
•
7th Grade - University
40 questions
PENILAIAN AKHIR SEMESTER PWPB XII

Quiz
•
12th Grade
45 questions
TRY OUT MID KLS 8 SEM GENAP

Quiz
•
8th Grade - University
40 questions
Quizz PTS Kelas XI Struktur Data Array

Quiz
•
11th Grade - University
40 questions
Informatika XII

Quiz
•
12th Grade - University
40 questions
Semester Final 2025

Quiz
•
10th Grade - University
40 questions
3 Tri C# 1

Quiz
•
12th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

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

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade