代做Algorithms and Data Structures SAMPLE EXAM代写Java编程
- 首页 >> Python编程Algorithms and Data Structures (M)
SAMPLE EXAM
This exam is multiple-choice and contains 25 questions ((i)-(xxv)). You should select one answer (a, b, c, d) for each question. Each correct answer is worth 2 marks. Incorrect answers will result in a penalty of two thirds of a mark to discourage guessing. A negative mark overall for this question will be rounded up to zero.
(i) Which of the following would we use to declare a class named A with a single generic type?
(a) public class A
(b) public class A
(c) public class A(E) { ... }
(d) public class A(E, F) { ... }
(ii) Which of the following methods is not in the Collection interface?
(a) clear()
(b) isEmpty()
(c) size()
(d) getSize()
(iii) You can use a for-each loop to traverse all elements in a container object that implements which of the following interfaces?
(a) Iterator
(b) Collection
(c) Iterable
(d) ArrayList
(iv) If list is a LinkedList that contains 1 million int values and A and B are the following fragments of code:
A:
for (int i = 0; i < list.size(); i++)
sum += list.get(i);
B:
for (int i: list)
sum += i;
Which of the following statements is true?
(a) Code fragment A runs faster than code fragment B
(b) Code fragment B runs faster than code fragment A
(c) Code fragment A runs as fast as code fragment B
(d) It is impossible to tell which of A or B is faster without knowledge of the size of the input integers
(v) What will be displayed by the following code?
List
list.add("A");
list.add("B");
list.add("C");
list.add("D");
for (int i = 0; i < list.size(); i++)
System.out.print(list.remove(i));
(a) ABCD
(b) AB
(c) AC
(d) BCD
(vi) What is the output from the following code?
import java.util.*;
public class Test {
public static void main(String[] args) {
(vii) For a sorted list of 1024 elements, a binary search takes at most x
(viii) The following recursive algorithm is to calculate the nth Fibonacci number, Fib(n).
The time complexity for Fib(n) is:
(ix) Consider the following code:
public static void main(String[] args) {
map.put("123", "Steve Price");
map.put("222", "Steve Price");
Which one of the following statements is true?
(d) A runtime error occurs because two entries with the same key "123" are added to the map.
(x) What is the worst-case time complexity for quick-sort?
(xi) What is the best-case time complexity for quick-sort?
(xiii) Which of the following AVL Trees would result from inserting the values
1, 10, 16, 7, 5 and 2 into an empty AVL tree in the given order (i.e. with balancing)?
(xiv) What is the preorder traversal ofthe binary search tree below?
(a) 1, 2, 4, 3, 2, 6, 6, 9, 8, 10
(b) 2, 4, 3, 1, 6, 5, 8, 10, 9, 7
(c) 7, 5, 1, 3, 2, 4, 6, 9, 8, 10
(d) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
(xv) What is the postorder traversal ofthe binary search tree in (xiii)?
(a) 1, 2, 4, 3, 2, 6, 6, 9, 8, 10
(b) 2, 4, 3, 1, 6, 5, 8, 10, 9, 7
(c) 7, 5, 1, 3, 2, 4, 6, 9, 8, 10
(d) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
(xvi) What is the inorder traversal ofthe binary search tree in (xiii)?
(a) 1, 2, 4, 3, 2, 6, 6, 9, 8, 10
(b) 2, 4, 3, 1, 6, 5, 8, 10, 9, 7
(c) 7, 5, 1, 3, 2, 4, 6, 9, 8, 10
(d) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
2.While not at end of file f, repeat:
2.2. Insert val into the correct position in the
The complexity of this algorithm is:
(xviii) Consider the following statements:
(S4) When you create an ArrayList x using new ArrayList<> (10), x.size() is 10
Which of the following is correct?
(a) only S2, S3 and S4 are true
(ixx) What is list after the following code is executed?
ArrayList
(xx) What is the output from the following code?
LinkedHashSet
(LinkedHashSet
(a) [bubblegum, starburst, smarties, dolly mixture]
(b) [starburst, smarties, dolly mixture]
(c) [bubblegum, starburst, dolly mixture]
(d) [starburst, smarties, dolly mixture]
(xxi) What are the best-case and worst-case complexities of the MergeSort algorithm respectively?
(xxii) Consider the following code:
public static void main(String[] args) {
Which one of the following statements is true?
(a) A runtime error occurs because more than one entry with the same key 150 are added to the map
(xxiii) Suppose that we use a closed bucket hash table H of size 520 to store a set
The load factor of H is approximately: