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
Consider the following code.
int[][] grid = new int[4][3];
int c = 1;
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
grid[i][j] = c;
c++;
}
}
What are the contents of the array?
1 2 3
4 5 6
7 8 9
10 11 12
Large or small datasets for binary Search?
Unsorted or sorted data for linear search?
Large, unsorted

What is printed when mysterm(3) is called?
1, 2, 3
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 returned when n=4?

24
ArrayList<Dragon> myDragonList1 = new <Dragon>();
What are the contents of arr after the following code has been executed?
int[][] arr = { {3,2,1},{1,2,3}};
for (int row = 1; row < arr.length; row++)
{
for (int col = 1; col < arr[0].length; col++)
{
if (arr[row][col] % 2 == 1)
{
arr[row][col] = arr[row][col] + 1;
}
if (arr[row][col] % 2 == 0)
{
arr[row][col] = arr[row][col] * 2;
}
}
}
{ {3, 2, 1}, {1, 4, 8}}
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?
Stack Overflow Error
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
A two-dimensional array, imagePixels, holds the brightness values for the pixels in an image. The brightness can range from 0 to 255. What does the following method compute?
public int findMax(int[][] imagePixels)
{
int r, c;
int i, iMax = 0;
for (r = 0; r < imagePixels.length; r++)
{
for (c = 0; c < imagePixels[0].length; c++)
{
i = imagePixels[r][c];
if (i > iMax)
iMax = i;
}
}
return iMax;
}
The maximum brightness value for all pixels in imagePixel
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
How many times is mystery() called in mystery(4)?

5 times
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;
}
Given the following code segment, what is the value of sum after this code executes?
int[][] m = { {1,1,1,1},{1,2,3,4},{2,2,2,2},{2,4,6,8}};
int sum = 0;
for (int k = 0; k < m.length; k++)
{
sum = sum + m[m.length-1-k][1];
}
9
Consider the following algorithm, which implements the selection sort algorithm.
int[] elements = {4, 10, 3, 1, 2, 8, 9, 6};
for (int j = 0; j < elements.length - 1; j++) {
int minIndex = j;
for (int k = j + 1; k < elements.length; k++) {
if (elements[k] < elements[minIndex]){
minIndex = k;
}
}
int temp = elements[j];
elements[j] = elements[minIndex];
elements[minIndex] = temp;
}
What are the contents of the array elements after 1 pass of the outer loop?
[1, 2, 3, 4, 10, 8, 9, 6]
Consider the following code:
public static int mysteryRecur(int n){
if(n <= 0)
return 1;
else if(n <= 3)
return 3;
else
return mysteryRecur(n / 2) + n;
}
What is returned when the call mysteryRecur(20) is run?
38