ArrayLists
2D-Arrays/Recursion
Searching/Sorting
Miscellaneous
100

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

100

How do you know if recursion is taking place in a method?

If a method calls itself, which would create a recursive case.

100

Large or small datasets for binary Search?

Unsorted or sorted data for linear search?

Large, unsorted

100

Who won the womens NCAA basketball tournament and who won the mens NCAA basketball tournament?

UCLA - womens, Michigan - mens

200

If an ArrayList called myList contains 10 integers and you do System.out.println(myList.size());  - what is printed ?

10

200

{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]

200

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.

200

What is January’s birthstone?

Garnet

300
On a piece of paper, write the full code for creating an ArrayList of an object data type Dragon. Make sure all syntax is correct.


ArrayList<Dragon> myDragonList1 = new <Dragon>();

300

What would happen if a base case is never true in a recursive method?

Infinite recursion would occur 

300

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

300

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)

400

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

400

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

400

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

400

 What does SPF in sunscreen stand for?

Sun Protection Factor

500

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:

  • First compute the average of all values
  • Remove all values less than the average
  • Modify the original list
  • Return the number of values removed

Starter code:

import java.util.ArrayList;

public class TemperatureUtils
{
   public int  removeBelowAverage(ArrayList<Integer> temps)
   {
       // to be implemented
   }
}

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;
}

500

Write a recursive method countEven that returns the number of even integers in an array.

The method should:

  • Use recursion (no loops)
  • Check one element at a time
  • Move to the next index each recursive call
  • Return the total count of even numbers

Starter code:

public class RecursionPractice
{
   public static int countEven(int[] arr, int index)
   {
       // to be implemented
   }
}

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);
}

500

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.

500

What was the first-ever video game console?

The Magnavox Odyssey

M
e
n
u