What is the name of a condition that appears at the very inside of a recursion method to stop the recursion?
What is a base case?
What sorting method uses checks that make direct comparisons between two numbers and swaps the larger term up in the list, essentially "floating" the largest numbers higher?
What is bubble sort
What is the name of a criterion put into a method as an initial condition?
What is a parameter?
What is the name of a class that inherits attributes from another class by extending it?
What is a subclass?
Observe the following code:
int[] nums = new int[3];
How long is the list?
3 integers long.
What would happen if a recursive method had no base case?
It would repeat forever.
What is the name of the number used for comparisons in quick sort?
What is a pivot?
What is another name for a function commonly used in the APCS term list?
What is a method?
What is the most parent class of the parent classes?
Object
Observe the following code:
int[] nums = new int[];
How long is the list?
10 integers long.
4. Consider the following recursive method.
public void printStars(int n)
{
if(n==1)
System.out.println("*");
else
{
System.out.print("*");
printStars(n-1)
}
}
What will be printed when printStars(4) is called?
****
Are selection sorts as efficient, more efficient, or the same efficiency as insertion sorts when the lists get into very large sizes?
They are the same (both go to n^2)
Declare an integer num equal to 0 that exists INSIDE a method.
int num = 0;
Declare an empty class named Question.
public class Question
{
}
Which is easier to change the size of, an ArrayList or an array?
ArrayList
What will return from factorial(3)?
public int factorial(int n) {
//baes case
if(n==0 || n==1)
return 1;
return n*factorial(n-1);
}
6
Look at this list:
{7,8,2,4,6,3}
What would it look like after the first step in a quicksort?
{2,4,6,3,7,8}
What do you call the process of making classes made several times to take in different types of parameters?
What is overloading?
Are interfaces abstract?
They are implicitly abstract.
What method would you get the size of an ArrayList?
ArrayList.size();
We have a number of bunnies and each bunny has two big floppy ears. We want to compute the total number of ears across all the bunnies recursively (without loops or multiplication). Write the missing line of code.
public int bunnyEars(int bunnies) {
//base case
<<MISSING CODE>>
return 0;
else
return 2 + bunnyEars(bunnies-1);
}
if(bunnies ==0)
The algorithm below can best be described as:
public static int mystery(int[] array, int a)
{
int low = 0;
int high = array.length-1;
while(low<=high)
{
int mid = (high + low)/2;
if(a< array[mid])
high = mid-1;
else if(a>array[mid])
low = mid +1;
else
return mid;
}
return -1
}
Binary Search
What number for the parameter will produce a result of __?
public boolean only14(int[] nums) {
boolean hasYucky = true;
for(int i = 0; i<nums.length;i++)
{
if(nums[i]!=1&&nums[i]!=4)
hasYucky = false;
}
return hasYucky;
}
If an array only contains 14's
Where does an abstract method in a superclass gets called into a concrete method?
Inside of a subclass (child)
This array fills itself with int of the position inside the list. Replace the missing line of code.
public int[] fizzArray(int n) {
int[]array=new int[n];
for(int i = 0; i<n; i++)
{
//Make the arraylist at the position into that integer.
<<MISSING CODE>>
}
return array;
}
array[i] = i;