Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA QUESTIONS. INTRODUCTION TO CSC I. True or False. ____1. Binary search on an

ID: 3683404 • Letter: J

Question

JAVA QUESTIONS. INTRODUCTION TO CSC


I. True or False.

____1. Binary search on an array of length n looks in about n/2 locations in the worst
case.
____2. The smallest subscript in any array is always 1.
____3. A linear search always requires more comparisons than a binary search.
____4. If a program attempts to access an element outside of the range of the array
indexes, a run-time error will occur.
____5. An array cannot hold object types.
____6. The worst case data set for insertion sort is data in reverse order.
____7. One can find the size of an array by using the length() method.
____8. An array declared as an int[] can contain elements of different primitive types.
____9. With each comparison, a binary search eliminates approximately half of the items
remaining in the search pool.

II. Sort Algorithms. Suppose an array contains the following values
8 7 6 5 4 3 2 1
in that order. What order would the values be in after the second pass of each of the following on
the original array?
1. Selection Sort______________________
2. Insertion Sort______________________
3. Bubble Sort______________________

VI. Writing Methods. Keep it simple
1. Write a method called print that is passed an array of int as a parameter and prints
on separate lines the values in that array.

2. Write a method called largest that is passed an array of int as a parameter and returns the
largest value in the array.

3. Write a method called total that is passed a one-dimensional array of integers as a parameter
and returns the total of the values.

4. Write a method isSorted that is passed a one-dimensional array of integers and returns true if the
array is already in sorted order and false otherwise.

4. Write a variation of the method OrderedLinearSearch that is passed a one-dimensional array of
integers and a value that returns the last location of the value in the array, or -1 if the value is not
found. The array is in sorted order and can contain duplicates.

Explanation / Answer

I. True or False.

____1. Binary search on an array of length n looks in about n/2 locations in the worst
case. FALSE
____2. The smallest subscript in any array is always 1. FALSE
____3. A linear search always requires more comparisons than a binary search. FALSE.
____4. If a program attempts to access an element outside of the range of the array
indexes, a run-time error will occur. TRUE.
____5. An array cannot hold object types. FALSE.
____6. The worst case data set for insertion sort is data in reverse order. TRUE.
____7. One can find the size of an array by using the length() method. TRUE.
____8. An array declared as an int[] can contain elements of different primitive types. FALSE.
____9. With each comparison, a binary search eliminates approximately half of the items
remaining in the search pool. TRUE.