Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

College board quiz #17

Open
Aryanboxout opened this issue Mar 14, 2023 · 0 comments
Open

College board quiz #17

Aryanboxout opened this issue Mar 14, 2023 · 0 comments

Comments

@Aryanboxout
Copy link
Owner

  1. Answer D

Incorrect. The statement numbers[0].length returns the number of columns in numbers and numbers.length returns the number of rows. In this case, the outer loop will loop r from 0 to 3, not including 3. However, r is then used as the row index in printing numbers[r][c] and there are only two rows in numbers. An ArraylndexOutOfBoundsExeception will be thrown when the code attempts to access a third row that does not exist.

Answer D

Correct. List is an interface, which an ArrayList implements. Please note that List is no longer tested as part of the AP CSA exam and ArrayList will be used instead. To determine the size of an ArrayList we need to call the method size(). Each word will be separated by a comma, but no comma should appear after the last element in the list. Therefore, a comma is added as long as k does not equal the last index, sizeOfList – 1, since list indices start at 0.

Answer C

Correct. In the first iteration of the binary search, it will check the value at index (0 + 7) / 2 which is index 3. Since 8 is greater than data[3], start is assigned mid + 1 which is 4 and the process will repeat. In the second iteration of the while loop, it will check the value at index (4 + 7) / 2 which is index 5. Since data[5] is 8, 5 is returned.

Answer E

Correct. Choice I iterates from startIndex to the end of the array words as expected, but when it adds elements to result it adds the current word followed by a second word starting at the end of the array words. This will result in duplicate words being added to result. Choice II starts at the end of the array words and adds each word to result working right to left until it reaches the startIndex. By starting at the end of the array, the elements are concatenated in reverse order. Choice III starts by adding the elements of words to temp in reverse order. The second loop starts at the beginning of temp (which was the end of words) and adds each subsequent element to result until it reaches the element that was at startIndex and is now at temp.length – startIndex resulting in result containing the required elements in reverse order.

Answer B

Incorrect. The recursive call is being added to the value of k, which is either 0 or 1. This will sum up the number of values that are equal to v.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant