COMP-2210 Practice Exam 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which big O expression best characterizes the worst case time complexity of the following method? * int count = 0; for (int i = 1; i < N; i++) { int j = 1; while (j < N) { j++; count++; } } * A.) O(NlogN) B.) O(N^2) C.) O(logN) D.) O(N)

B

Which sorting algorithm has the following time complexity profile? Best case: O(N), Average case: O(N^2), Worst case: O(N^2). A.) selection sort B.) insertion sort C.) merge sort D.) quicksort

B

Which sorting algorithm has the following time complexity profile? Best case: O(NlogN), Average case: O(NlognN), Worst case: 0(N^2). A.) selection sort B.) insertion sort C.) merge sort D.) quicksort

D

Which list below orders the functions from slowest growth rate to fastest growth rate (that is, most scalable to least scalable. A.)logN, N, NlogN, N^2 B.)N^2, NlogN, N, logN C.)N, N^2, NlogN, logN D.)logN, NlogN, N, N^2

A

Which sorting algorithm has the following time complexity profile? Worst case: O(N^2), Average case: O(N^2), Worst case: O(N^3). A.) selection sort B.) insertion sort C.) merge sort D.) quicksort

A

What would happen when you try to run and compile the following code? * public int search(Comparable[] a, Comparable target) { //compareTo method used for comparison } //... Comparable[] a = {"red", new Book("A", "T", 123), new Integer(5) search(a, new Double(3.14)); * What would happen when you try to run and compile the following code? * public int search(Comparable[] a, Comparable target) { //compareTo method used for comparison } //... Comparable[] a = {"red", new Book("A", "T", 123), new Integer(5) search(a, new Double(3.14)); * A.) A compile-time error is generated. B.)Compilation succeeds but a runtime error is generated. C.) Compilation succeeds and the program runs without error. D.) Compile-time warnings are issued, but the program runs without error.

B

Which big O expression best characterizes the word case time complexity of the following method? * count = 0; int i = 1; while (i < N) { count++ i - i * 2; } A.) O(1) B.)O(logN) C.)O(N) D.)O(N^2)

B

Suppose an array of N elements in reverse(i.e., descending) order is passed to a sorting method, and you observe that the method takes time proportional to N^2. Which sorting algorithm is definitely not implemented in this method? A.)selection sort B.) insertion sort C.)merge sort D.) quicksort

C

What value should we expect the variable cmp to contain after the following code executes? * String s1 = "War"; String s2 = "Eagle"; int cmp = s2.compareTo(s1); * A.) -1 B.) 1 C.) some negative integer D.) some positive integer

C

What would happen when you try to run and compile the following code? * What would happen when you try to run and compile the following code? * public int search(Comparable[] a, Comparable target) { //compareTo method used for comparison } //... Comparable[] a = {"red", new Book("A", "T", 123), new Integer(5) search(a, new Double(3.14)); * A.) A compile-time error is generated. B.)Compilation succeeds but a runtime error is generated. C.) Compilation succeeds and the program runs without error. D.) Compile-time warnings are issued, but the program runs without error. * public int search(Object[] a, Object target) { //compareTo method used for comparison } //... Object[] a = {"red", new Book("A", "T", 123), new Integer(5) search(a, new Double(3.14)); *

C

Which of the sorting algorithms, as implemented in class, was not an in-place sort? A.)selection sort B.)insertion sort C.)merge sort D.)quicksort

C


Ensembles d'études connexes

HTM 2464 Midterm 1 Ch. 1-4 & 16 Smartbooks

View Set

management of patients with upper respiratory tract disorders (C18)

View Set

Psych Chapter 14 Social Psychology

View Set

Chapter 13 The Peripheral Nervous System and Reflex Activity

View Set

Nutrition Exam 1 (PS #1, PS #2, PS #3 and PS #4)

View Set