final review

.pdf

School

York University *

*We aren’t endorsed by this school

Course

1022

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

21

Uploaded by freecloud19

Report
2020/12/22 Final Test: Attempt review Dashboard / My courses / LE/EECS1022 A - Programming_for Mobile Computing_(Fall 2020-2021) / Tests / Final Test Started on Tuesday, 15 December 2020, 10:29 PM State Finished Completed on Tuesday, 15 December 2020, 11:33 PM Time taken 1 hour 4 mins Grade 24.00 out of 32.00 (75%) Question 1 Incorrect Mark 0.00 out of 1.00 Given the following function f1, give the best order of growth of the running time (i.e., The time complexity using Big-O notation). public int fl(int[] a, int key) { int lo = U, mid, hi = a.length-!; while (lo <= hi) { mid = (lo + hi)/Z; if (key < a[mid]) hi = mid - 1; else if (a[mid] < key) lo = mid + |; else return mid; // success: find the key return the index of } return -1; // failure: key is not in the array: Select one; Oo(1) O(N) O(log N) O(NlogN) © O(N?) O( N2 log N) Compilation errors none of the above The correct answer is: O(log N) https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 1/21
2020/12/22 Final Test: Attempt review Question 2 Correct Mark 1.00 out of 1.00 In Java, which of the following statements are CORRECT. . ArrayList implements List interface. Il. HashMap implements Map interface Il ArrayList stores two objects key and value. Select one; | only. Il only. Il only. | and III. ° land Il Il and III. l, Il and Ill. none of the above The correct answer is: | and Il. https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 2/21
2020/12/22 Final Test: Attempt review Question 3 Correct Mark 1.00 out of 1.00 Given the following function f2, give the best order of growth of the running time (i.e., The time complexity using Big-O notation). public int f2 (int N) { int x = 0; for (Ant 1= 1; 1 < N5 i+¢) { for(int j =0; j < i; j++) { X++; } } return x; Select one; O(1) O(N) O(logN) O(NlogN) o Q(NZ) v Runtime Exception Compilation errors none of the above The correct answer is: O( N2 ) https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 3/21
2020/12/22 Final Test: Attempt review Question 4 Correct Mark 1.00 out of 1.00 Which of the following statements are CORRECT I. The Java compiler always adds a default constructor to a user defined class. II. Each instantiated object will have its own copy of a class variable. ITI. A class can have multiple constructors. Select one; | only. Il only. © 1l only. | and IIl. | and II. Il and Il1. l, Il and Ill. none of the above The correct answer is: lll only. Question B Correct Mark 1.00 out of 1.00 What is the output from the following Java program fragment? | | try { ~ foxr (Int 1. = 1; i <€ 3; a+¥) ¢ | System.out.print (i) ; | System.out.println(l / 0); | } } catch (Exception ex) { } e S Write the answer without adding anything to it (such as extra quotes, leading or trailing text, = signs, ...). Write XXX in case of errors. Answer: 1 v The correct answer is: 1 https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 4/21
2020/12/22 Final Test: Attempt review Question 6 Correct Mark 1.00 out of 1.00 For what value of the parameter k would the return of this method be 57 If there is more than one such value, write any one of them (and only one) as your answer. public int methodA(int k) { int total = 0; For (dnt 1 = 2:52) if (i <= 10) i++; if (i > 10) break; iF (1 »= k) total++; } return total; } Write the answer without adding anything to it (such as extra quotes, leading or trailing text, = signs, ...). Write XXX in case of errors. Answer: 6 v The correct answer is: 6 Question 7 Incorrect Mark 0.00 out of 1.00 What is the value of String s4 after the following Java program fragment is executed? String S1 = "EECS$yokr$universityz"; String S2 = "Hi"; String S3 = "student”; String S4 = Sl.substring(S1.indexOf("r")+1, S1.indexOf("z")) + S3.substring(@) + S2; Write the answer without adding anything to it (such as leading or trailing text, = signs, ...). Write XXX in case of errors. Answer: "S$universitysHi" x The correct answer is: "$universitystudentHi" https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 5/21
2020/12/22 Final Test: Attempt review Question 8 Correct Mark 1.00 out of 1.00 Which of the following Java statements will print true I. System.out.println("Hello, ABC".matches ("ABC")) ; II. System.out.println("xyz, ABC".matches(".*ABC.*")); ITII. system.out.println("XYZ, ABC".matches(".ABC.*")) ; Select one: | only. ° 1l only. v Il only. | and III. | and II. Il and Il1. l, Il and IIl. none of the above The correct answer is: Il only. Question 9 Correct Mark 1.00 out of 1.00 Which of the following contains string(s) that DO NOT match the regular expression ab*c$? Select one: - "abc" "fac" © "1223" v none of the above The correct answer is; "1223" https://eclass.yorku.ca/eclass/mod/quiz/review.php?attempt=863173&cmid=431492 6/21
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help