Overview Lesson #5
Below is a list of all the lessons this overview lesson will cover.
- ArrayLists
- Recursion
- Sorting and Searching
- Common Sorting Methods
- Common Searching
- Mergesort
- Quicksort
Lesson Quiz
The first two questions in this quiz cover ArrayLists and Recursion. The remaining questions cover material taught in lessons 3-7 above.
1. Which of the following is an advantage of arrays over ArrayLists?
2. Which of the following is not a common use of recursion?
3. What is the time complexity of the following code?
public void temp(int n) {
for (int i = 0; i < n; i++) {
System.out.println(n);
temp(n-1);
}
}
4. Which of the sorting methods would be the most efficient in finding the top 5 scores in a competition with 500 thousand participants?
5. Which of the sorting methods would be most efficient in sorting an array of one million integers where each integer is a number between 1 and 3?
6. What is one advantage Quicksort has over Merge Sort?
7. The following code is an incorrect implementation of binary search. Which line contains the mistake?
public static int binarySearch(int[] arr, int val) {
int left = 0;
int right = arr.length - 1;
while (left <= right) { // Line 1
int mid = left + right / 2; // Line 2
if (arr[mid] == val) {
return mid;
} else if (val < arr[mid]) { // Line 3
right = mid - 1;
} else {
left = mid + 1; // Line 4
}
}
return -1; // Line 5
}
Written by Alan Bi
Notice any mistakes? Please email us at learn@teamscode.com so that we can fix any inaccuracies.