Csci 1302 Final On Chapter 19,20,21,22

31 Questions

Settings
CSCI Exam Quizzes & Trivia

Questions and Answers
  • 1. 
    The E get(int index) method of the List interface should throw an exception if 
    • A. 

      The index passed to is negative or greater than the size of the list

    • B. 

      The index passed to it is negative or greater or equal to the size of the list

    • C. 

      the index passed to it non negative

    • D. 

      The index passed to it is negative

  • 2. 
    The difference between an array and an ArrayList is 
    • A. 

      D. All of these

    • B. 

      Arrays have a fixed size and cannot grow to accommodate more elements

    • C. 

      An array keeps track of its length while an ArrayList does not track comparable information

    • D. 

      An ArrayList uses a LinkedList to hold its elements, an array does not.

  • 3. 
    A constructor for an array-based list takes an integer parameter, to be used as the capacity of the internal array of the list. Which exception should the constructor throw if its parameter is zero or negative?
    • A. 

      IllegalStateException

    • B. 

      NullPointerException

    • C. 

      IllegalArgumentException

    • D. 

      RuntimeException

  • 4. 
    An ArrayList is so called because
    • A. 

      You can use array subscript notation to work with the ArrayList

    • B. 

      You can pass it as a parameter to any method that expects an array

    • C. 

      It is implemented as a class that uses an internal array to hold the elements of the list

    • D. 

      All of these

  • 5. 
    A new element is added to an ArrayList object at index k. Assuming the list has size s and does not have to be resized, 
    • A. 

      The elements at current positions k..s must be moved toward the end of the array

    • B. 

      The element at position k is overwritten

    • C. 

      The elements at current positions 0..k must be moved toward the beginning of the list

    • D. 

      The elements at current positions k..s-1 must be moved toward the end of the array

  • 6. 
    The boolean contains(E element) method searches a ArrayList for a given element. A correct and efficient implementation of this method
    • A. 

      Uses sequential search to locate the element

    • B. 

      Returns 0 if the element is not found in the list

    • C. 

      Uses binary search to locate the element

    • D. 

      Throws an exception if the element is not found in the list

  • 7. 
    The int indexOf(Object o) method of the List interface
    • A. 

      Adds an object to a list and returns the index of the newly added object

    • B. 

      Uses binary search to locate the given object, and then returns its index

    • C. 

      Searches a list for the occurrence of an object and returns its index

    • D. 

      None of these

  • 8. 
    The size of an array-based list such as ArrayList
    • A. 

      None of these

    • B. 

      Is the length of its internal array

    • C. 

      Is the number of elements that are currently stored in the list

    • D. 

      Is the number of bytes of memory that the list can hold

  • 9. 
    The capacity of an array-based list such as ArrayList
    • A. 

      Is the number of bytes of memory that the list can hold

    • B. 

      is the size of its internal array

    • C. 

      Is the number of elements that are currently stored in the list

    • D. 

      None of these

  • 10. 
    Scientists in a certain laboratory are working with a linked list class that uses recursion to compute its size. The scientists know that an empty list has size 0, so they never ask a linked list to compute its size when the list is empty. Under these circumstances,
    • A. 

      the recursive method should still handle the base case of an empty list, because it will still occur even though the scientists never ask for the size of an empty list and the recursive method can be modified to use a list of size 1 as the base case are both correct

    • B. 

      The recursive method can become more efficient by eliminating the test for a base case

    • C. 

      The recursive method should still handle the base case of an empty list, because it will still occur even though the scientists never ask for the size of an empty list

    • D. 

      the recursive method can be modified to use a list of size 1 as the base case

  • 11. 
    A collection that is accesed in first in first out fashion is called
    • A. 

      A stack

    • B. 

      A queue

    • C. 

      A linked list

    • D. 

      An array based collection

  • 12. 
    The stack method that returns an element from the stack without removing it is 
    • A. 

      Peek

    • B. 

      Pop

    • C. 

      Push

    • D. 

      Spy

  • 13. 
    If the stack method push is called on an empty stack
    • A. 

      None of the above

    • B. 

      It calls the stack empty

    • C. 

      It throws an emptystackexception

    • D. 

      It adds it argument to the stack

  • 14. 
    When using an array to implement a stack, the push method will wrap around to the beginning of the stack when it reaches the end.
    • A. 

      True

    • B. 

      False

  • 15. 
    in a linked list implementation using a reference first to point to the first node of the list, a method isEmpty() can test to see if the list is empty by executing the statement(s)
    • A. 

      If (isEmpty()) return true; else return false;

    • B. 

      Return first == null;

    • C. 

      Return null;

    • D. 

      First = null; return first;

  • 16. 
    To allocate storage for its elements, an array-based list such as ArrayList uses
    • A. 

      Linked allocation

    • B. 

      Contiguous allocation

    • C. 

      Capacity allocation

    • D. 

      Fixed size allocation

  • 17. 
    The objects that form the units of memory allocation in a linked lists are called
    • A. 

      Elements

    • B. 

      Memory modules

    • C. 

      Nodes

    • D. 

      Memory modules

  • 18. 
    A list can be considered a recursive data structure because
    • A. 

      Linked allocation

    • B. 

      If you remove the head of the list, what remains is also a list

    • C. 

      Contiguous allocation

    • D. 

      A list can be considered a recursive data structure because

  • 19. 
    In a typical circular doubly linked list, a node has
    • A. 

      A field to store the element, and two references to keep track of two predecessor nodes, and a reference to keep track of the end of the list

    • B. 

      Either one of a field to store the element, and two references to keep track of two successor nodes, and a reference to keep track of the start of the list or a field to store the element, and two references to keep track of two predecessor nodes, and a reference to keep track of the end of the list

    • C. 

      a field to store the element, and two references to keep track of successor and predecessor nodes

    • D. 

      a field to store the element, and two references to keep track of two successor nodes, and a reference to keep track of the start of the list

  • 20. 
    A list can be considered a recursive data structure because
    • A. 

      A list can be considered a recursive data structure because

    • B. 

      None of these: only methods can be considered recursive.

    • C. 

      List objects are instances of list classes

    • D. 

      if you remove the head of the list, what remains is also a list

  • 21. 
     In order to use recursion on linked lists
    • A. 

      It is necessary to modify the class that represents nodes, by adding a reference needed to support recursion

    • B. 

      the class that represents nodes must implement the Repeatable interface

    • C. 

      No changes to the node class are necessary

    • D. 

      it is necessary to modify the class that represents nodes, by adding a reference needed to support recursion and the class that represents nodes must implement the Repeatable interface are both true

  • 22. 
    To remove a node with a positive index k from a linked list,
    • A. 

      assign the successor reference in the node with index k to the successor reference in the node with index k-1

    • B. 

      Start a reference r at the head of the list, walk r forward k steps, and then set r to null

    • C. 

      Decrement k by 1, and then use recursion

    • D. 

      Decrement k by 1, and set the reference to the node to be removed to null

  • 23. 
    A list is a collection that 
    • A. 

      Associates keys with elements

    • B. 

      None of the above

    • C. 

      Assigns an index to each of its elements

    • D. 

      Is implemented by the JList class

  • 24. 
    To add an element e just after a node referenced by ref, you should use the statement 
    • A. 

      Ref.next = new node (e, ref.next);

    • B. 

      Ref = new node(e, ref.next);

    • C. 

      Add(ref);

    • D. 

      Ref.next = new node(e);

  • 25. 
    A systematic method that starts at the beginning of the list and processes every node is called
    • A. 

      A travesty of list processing

    • B. 

      A traversal

    • C. 

      A walk down the list

    • D. 

      A list processing function

  • 26. 
    A binary tree is a collection of items in which each item
    • A. 

      Has no successor

    • B. 

      Has exactly two successors

    • C. 

      Has at most two successors

    • D. 

      Has one successor

  • 27. 
    The head of a linked list is also a linked list
    • A. 

      True

    • B. 

      False

  • 28. 
    The last item in a doubly linked list can sometimes have a sucessor.
    • A. 

      True

    • B. 

      False

  • 29. 
    An AVL tree is 
    • A. 

      None of the above

    • B. 

      A kind of heap

    • C. 

      A king of priority queue

    • D. 

      A kind of binary search tree

  • 30. 
    A node in a binary tree can have two parents
    • A. 

      True

    • B. 

      False

    • C. 

      Neither

  • 31. 
    The subtrees of a node in a complete binary tree must be equal in height
    • A. 

      True

    • B. 

      False