Data structures using JAVA mid term
Q1. Software engineers typically break the software development process into the following four phases: analysis, ____, implementation, testing and debugging.
a. design
b. requirements gathering
c. white box analysis
d. algorithm analysis
Q2. Which of the following functions g(n) has a constant growth rate?
a. n
b. n2
c. n log n
d. 1
Q3. A(n) ____ is a step-by-step problem-solving process in which a solution is arrived at in a finite amount of time.
a. design plan
b. algorithm
c. process plan
d. structured program
Q4. In the ____ process, the program is modified to fix the (identified) problems or to enhance it.
a. software life cycle
b. implementation
c. software maintenance
d. testing
Q5. In ____ copying, each reference variable refers to its own object.
a. shallow
b. deep
c. method
d. object
Q6. The three fundamental stages a program goes through are: implementation, use, and maintenance.
a. true
b. false
Q7. Encapsulation is the ability to handle data and operations as separate units.
a. true
b. false
Q8. Finalizers are value-returning methods that return the final value of a variable.
a. true
b. false
Q9. Software engineers typically break the software development process into the following four phases: analysis, design, implementation, testing, and debugging.
a. true
b. false
Q10. Polymorphism is the ability to use the same expression to denote different operations.
a. true
b. false
Q11. A checked exception is any exception checked for by the programmer.
a. true
b. false
Q12. If there are three classes, Shape, Circle and Square, what is the most likely relationship between them?
a. Square is a superclass, and shape and circle are subclasses of Square.
b. Shape is a superclass, and circle and square are subclasses of Shape.
c. Shape, circle and square are all sibling classes.
d. These three classes cannot be related.
Q13. Inheritance is an example of what type of relationship?
a. is-a
b. has-a
c. was-a
d. had-a
Q14. An abstract method ____.
a. is any method in the abstract class
b. cannot be inherited
c. has no body
d. is found in a subclass and overrides methods in a superclass using the reserved word abstract
Q15. If you have created an exception class, you can define other exception classes extending the definition of the exception class you created.
a. true
b. false
Q16. Any new class you create from an existing class is called a(n) ____.
a. base class
b. superclass
c. derived class
d. extended class
Q17. To determine whether a reference variable that points to an object is of a particular class type, Java provides the operator instanceof.
a. true
b. false
Q18. The class Throwable is derived from the class Exception.
a. true
b. false
Q19. An abstract class ____.
a. does not have any subclasses
b. is a superclass with many subclasses
c. cannot be instantiated
d. is the base class of all other classes
Q20. An abstract class can define ____.
a. only abstract methods
b. only non-abstract methods
c. abstract and non-abstract methods
d. only abstract instance variables
Q21. What does the following statement do: Vector thisVector = new Vector();
a. Creates an empty vector
b. Creates a vector with 10 elements
c. This statement does not do anything
d. Creates an array
Q22. A list is a collection of elements of the same type.
a. true
b. false
Q23. The method remove for unordered lists uses which combination of methods to remove an item from the list?
a. seqSearch and removeAt
b. removeAt and replaceAt
c. retrieveAt and removeAt
d. seqSearch and replaceAt
Q24. The elements of an object of the class UnorderedArrayList are always sorted.
a. true
b. false
Q25. Which method would you most likely use to add an element to an end of a vector?
a. insertElementAt
b. addElement
c. copyInto
d. lastElement
Q26. The method clone in the class Vector returns a copy of the vector.
a. true
b. false
Q27. A list is full if length is equal to maxSize.
a. true
b. false
Q28. The method ____ removes the elements from the list, leaving it empty.
a. deleteElements
b. removeAt
c. clearList
d. deleteList
Q29. The class ArrayListClass is the subclass of the classes that implement a list.
a. true
b. false
Q30. Which of the following methods requires the shifting of elements?
a. replaceAt
b. retrieveAt
c. insertEnd
d. insertAt
Q31. In an ordered list, we need to modify the algorithms (from a normal linked list) to implement the search, insert, and delete operations.
a. true
b. false
Q32. Searching, inserting, and deleting require traversal of the linked list.
a. true
b. false
Q33. What is the time-complexity to insert an item at the end of a linked list?
a. O(1)
b. O(n)
c. O(n2)
d. O(log n)
Q34. What is the time-complexity of the LinkedListClass copy constructor?
a. O(1)
b. O(n)
c. O(n2)
d. O(log n)
Q35. Building a linked list forward places the new item to be added at the beginning of the linked list.
a. true
b. false
Q36. To delete a given item from an ordered linked list, there is no need to search the list to see whether the item to be deleted is in the list.
a. true
b. false
Q37. In the class LinkedListClass, the search method is declared as ____.
a. public
b. private
c. abstract
d. protected
Q38. By using one reference variable to insert an item into a linked list, the order of the sequence of events is irrelevant.
a. true
b. false
Q39. In an ordered linked list the search algorithm is somewhat improved because the list is ____.
a. larger
b. smaller
c. higher
d. sorted
Q40. In a doubly linked list, some of the operations require modification from how they were implemented for a regular linked list, because of the ____ reference variable(s) in each node.
a. null
b. two
c. three
d. four
Q41. public static int rFibNum(int a, int b, int n)
{
if(n == 1)
return a;
else if(n == 2)
return b;
else
return rFibNum(a, b, n - 1) + rFibNum(a, b, n - 2);
}
What is the limiting condition of the code above?
a. n >= 0
b. a >= 1
c. b >= 1
d. n >= 1
Q42. The body of a recursive method contains a statement that causes the same method to execute before completing the current call.
a. true
b. false
Q43. The overhead associated with iterative methods is greater in terms of both memory space and computer time, when compared to the overhead associated with executing recursive methods.
a. true
b. false
Q44. public static int exampleRecursion (int n)
{
if (n==0)
return 0;
else
return exampleRecursion(n-1) + n*n*n;
}
How many base cases are in the code above?
a. 0
b. 1
c. 2
d. 3
Q45. The general case is the case for which the solution is obtained directly.
a. true
b. false
Q46. A recursive method in which the first statement executed is a recursive call is called a tail recursive method.
a. true
b. false
Q47. Recursive algorithms are implemented using while loops.
a. true
b. false
Q48. private int func1(int m, int n) {
if (m==n || n==1)
return 1;
else
return func1(m-1,n-1) + n*func1(m-1,n);
}
Which of the following would be an invalid call to the method above?
a. func1(0, 1)
b. func1(1, 0)
c. func1(4, 9)
d. func1(99999, 99999)
Q49. There are two base cases in the recursive implementation of generating a Fibonacci sequence.
a. true
b. false
Q50. private int func2(int m, int n) {
if (n == 0)
return 0;
else
return m + func2(m, n-1);
}
What is the limiting condition of the code above?
a. n >= 0
b. m > n
c. m >= 0
d. n > m