Docsity

CS 2420: Introduction to Algorithms and Data Structures, Exercises of Algorithms and Programming

Partial preview of the text

Download CS 2420: Introduction to Algorithms and Data Structures and more Exercises Algorithms and Programming in PDF only on Docsity!

CS 2420: Introduction to Algorithms and Data Structures SAMPLE QUESTIONS — Make your own key, none will be posted by the course staff Do not limit your studying to finding the answers to these sample questions. The first midterm exam is to be taken on Gradescope, and the time limit is 50 minutes. The exam is available 9:40a to 3:55p Mountain Time on Friday, February 26. While taking the exam, a student may not consult any materials other than their own handwritten 8.5x11” sheet of notes, and they may not collaborate with anyone (including non-students) while taking the exam. The following are nine practice exam problems. Each point represents about 1 minute of exam time; therefore, all practice questions are a total of 70 points and 70 minutes. 1. (4 points) Consider the following Java code. public class MyClass { public static void doSomething(char c, float[] f) { 7??? } public static void main(String[] args) { char letter = ‘a’; float[] arr = {1.2, 3.4, 5.6, 7.8}; doSomething(letter, arr); System. out.println(letter) ; System. out.print1n(f[0]); } } Which of the following is definitely true? Fill in one or more choices. © The value printed in the penultimate statement of main is ‘a’. © The value printed in the penultimate statement of main is not ‘a’. © The value printed in the last statement of main is 1.2. © The value printed in the last statement of main is not 1.2. 2. (5 points) Is the following statement true or false? Justify your answer. All Java interfaces are abstract classes, but not all abstract classes are Java interfaces. 3. (12 points) Given the following class definition fragments and class instantiations, complete the table below. Assume that the methods shown here do not appear in any other classes. (E.g., The Restaurant class does not define a toString method.) class Building { public Point getLocation() ... } class Restaurant extends Building { public int getSeatCount() ... } class Lab extends Building { public String toString() ... } class Diner extends Restaurant { public boolean equals(Object other) ... }