What is advantage of using an ArrayList vs a 1-D array?
It is flexible and dynamic in size and there are built-in methods you can utilize with ArrayLists too such as .add, .set
How do you know if recursion is taking place in a method?
If a method calls itself, which would create a recursive case.
Large or small datasets for binary Search?
Unsorted or sorted data for linear search?
Large, unsorted
Who won the womens NCAA basketball tournament and who won the mens NCAA basketball tournament?
UCLA - womens, Michigan - mens
If an ArrayList called myList contains 10 integers and you do System.out.println(myList.size()); - what is printed ?
10
{3, 2 ,2}
{3,2,1}
{4,1,2}
If this 2D array was initialized as "myArray", how would you access the number 4? Assume there are no errors in this code above.
myArray[2][0]
Explain the difference between selection sort and insertion sort in detail
Selection sort finds the smallest number in an array and swaps the appropriate elements for each index, insertion sort compares adjacent elements and inserts the element where it needs to go.
What is January’s birthstone?
Garnet
ArrayList<Dragon> myDragonList1 = new <Dragon>();
What would happen if a base case is never true in a recursive method?
Infinite recursion would occur
How many checks will occur with a linear search on the following array if the target value is 17:
{12,9,5,20,27,17,40,20}
6
What food manufacturing company headquartered in Battle Creek, Michigan, uses several animal mascots to sell its cereals, such as Newton the Owl, Tony the Tiger and a rooster named Cornelius?
The Kellogg Company (Kellogg’s)
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(2);
list.add(3);
list.add(10);
list.add(2);
for(int i = 0; i < list.size() - 1; i++)
{
if(list.get(i) > list.get(i + 1))
{
System.out.print(list.get(i) + " ");
}
}
What is printed?
10
Consider the following recursive method.
public static int mystery(int n)
{
if (n == 0)
{
return 3;
}
else
{
return n + mystery(n - 1);
}
}
What is returned as a result of the call mystery(6)?
39
How many checks will a computer need to do on the following array using a binary search if the target value is 19:
{3,5,10,12,15,20,22,19}
4
What does SPF in sunscreen stand for?
Sun Protection Factor
A class stores a list of integers representing daily temperatures. Write a method removeBelowAverage that removes all values that are strictly below the average of the list.
The method should:
Starter code:
Syntax does not need to be perfect for this, but I would like to see the logic make sense and there needs to be a good attempt at syntax.
public static int removeBelowAverage(ArrayList<Integer> temps)
{
int sum = 0;
for (int num : temps)
{
sum += num;
}
double average = (double) sum / temps.size();
int removed = 0;
for (int i = temps.size() - 1; i >= 0; i--)
{
if (temps.get(i) < average)
{
temps.remove(i);
removed++;
}
}
return removed;
}
Write a recursive method countEven that returns the number of even integers in an array.
The method should:
Starter code:
I am looking for correct logic more than perfect syntax, but make a solid attempt at good syntax.
public static int countEven(int[] arr, int index)
{
if (index == arr.length)
{
return 0;
}
if (arr[index] % 2 == 0)
{
return 1 + countEven(arr, index + 1);
}
return countEven(arr, index + 1);
}
Explain how merge sort works and when you would want to use it
Merge sort uses a divide and conquer approach to sorting data. It divides an array into a bunch of different sub arrays, then it eventually sorts each sub array one by one until it puts itself back together. You would use it for larger data sets because it would be more efficient than insertion or selection sort.
What was the first-ever video game console?
The Magnavox Odyssey