CSCI 1302 Exam: Computer Science! Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Lonesarah
L
Lonesarah
Community Contributor
Quizzes Created: 2 | Total Attempts: 1,825
Questions: 10 | Attempts: 645

SettingsSettingsSettings
CSCI Exam Quizzes & Trivia

How much do you know about computer science? Are you aware that computer disciplines are a well-utilized field and are very important for the progression of computer knowledge? Do you know the difference between an array and array list, why they have different names, and the array-based list's capacity? The array list grows on its own as you add to it, so it takes care of itself. Compute this quiz, and you see how much do you score. All the best.


Questions and Answers
  • 1. 

    The E get(int index) method of the List interface should throw an exception if:

    • A.

      The index passed to it is negative

    • B.

      The index passed to it non negative

    • C.

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

    • D.

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

    Correct Answer
    C. The index passed to it is negative or greater or equal to the size of the list
    Explanation
    The correct answer is "the index passed to it is negative or greater or equal to the size of the list". This is because the get() method should throw an exception if the index is either negative or greater than or equal to the size of the list. In both cases, the index is out of bounds and accessing an element at that index would result in an error.

    Rate this question:

  • 2. 

    The difference between an array and an ArrayList is:

    • A.

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

    • B.

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

    • C.

      C. arrays have a fixed size and cannot grow to accommodate more elements

    • D.

      D. All of these

    Correct Answer
    C. C. arrays have a fixed size and cannot grow to accommodate more elements
    Explanation
    The correct answer is c. arrays have a fixed size and cannot grow to accommodate more elements. This statement accurately describes the difference between an array and an ArrayList. Arrays have a fixed size that is determined when they are created, and they cannot grow or shrink dynamically. In contrast, an ArrayList is a resizable collection that can grow or shrink as needed to accommodate more or fewer elements. Therefore, the statement accurately highlights the key difference between these two data structures.

    Rate this question:

  • 3. 

    The position of an item within a list is called its:

    • A.

      A. index

    • B.

      B. rank

    • C.

      C. level

    • D.

      D. number

    Correct Answer
    A. A. index
    Explanation
    The position of an item within a list is commonly referred to as its "index". The index represents the specific location or order of an item in the list, allowing for easy reference and retrieval of the item when needed. It is a fundamental concept in programming and data structures, as it enables efficient manipulation and access to elements within a list.

    Rate this question:

  • 4. 

    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.

      IllegalArgumentException

    • B.

      IllegalStateException

    • C.

      NullPointerException

    • D.

      RuntimeException

    Correct Answer
    A. IllegalArgumentException
    Explanation
    The constructor for an array-based list should throw an IllegalArgumentException if its parameter is zero or negative. This is because the capacity of the internal array should be a positive value, and passing a zero or negative value would be considered an invalid argument. The IllegalArgumentException is the appropriate exception to indicate that the input parameter is not valid.

    Rate this question:

  • 5. 

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

    • A.

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

    • B.

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

    • C.

      Is the length of its internal array

    • D.

      None of these

    Correct Answer
    B. Is the number of elements that are currently stored in the list
    Explanation
    The size of an array-based list such as ArrayList refers to the number of elements that are currently stored in the list. This is because the size of the list is determined by the number of elements that have been added to it, rather than the amount of memory it can hold or the length of its internal array.

    Rate this question:

  • 6. 

    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 number of elements that are currently stored in the list

    • C.

      is the size of its internal array

    • D.

      None of these

    Correct Answer
    C. is the size of its internal array
    Explanation
    The capacity of an array-based list such as ArrayList refers to the size of its internal array. This means that it determines the maximum number of elements that the list can hold. It is not related to the number of bytes of memory or the number of elements currently stored in the list.

    Rate this question:

  • 7. 

    An ArrayList is so-called because:

    • A.

      You can use array subscript notation to work with the ArrayList

    • B.

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

    • C.

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

    • D.

      All of these

    Correct Answer
    B. it is implemented as a class that uses an internal array to hold the elements of the list
    Explanation
    The correct answer is that an ArrayList is implemented as a class that uses an internal array to hold the elements of the list. This means that the ArrayList class internally manages an array to store and manipulate the elements in the list. Other options mentioned, such as using array subscript notation or passing it as a parameter to any method that expects an array, are not specific to ArrayList and can also be applicable to other types of arrays.

    Rate this question:

  • 8. 

    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 0..k must be moved toward the beginning of the list

    • B.

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

    • C.

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

    • D.

      the element at position k is overwritten

    Correct Answer
    B. the elements at current positions k..s-1 must be moved toward the end of the array
    Explanation
    When a new element is added to an ArrayList at index k, all the elements at positions k to s-1 (where s is the size of the list) must be moved toward the end of the array to make space for the new element. This is because ArrayLists are dynamically resizable arrays, and when a new element is added, the array needs to accommodate it by shifting the existing elements to make room. The elements at positions 0 to k-1 do not need to be moved as they are not affected by the insertion. The element at position k is not overwritten, but rather shifted along with the other elements.

    Rate this question:

  • 9. 

    The boolean contains(E element) method searches an ArrayList for a given element. Correct and efficient implementation of this method.

    • A.

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

    • B.

      Uses binary search to locate the element

    • C.

      Uses sequential search to locate the element

    • D.

      Returns 0 if the element is not found in the list

    Correct Answer
    C. Uses sequential search to locate the element
    Explanation
    The correct answer is that the method uses sequential search to locate the element. Sequential search is a simple and straightforward approach where the method iterates through the ArrayList one element at a time until it finds a match for the given element or reaches the end of the list. This method is efficient for small lists or when the element being searched for is likely to be near the beginning of the list. However, for large lists or when the element is likely to be towards the end of the list, binary search would be a more efficient approach.

    Rate this question:

  • 10. 

    If a new element is added to an ArrayList whose internal array if already full:

    • A.

      The add method throws an exception

    • B.

      A new, bigger internal array is created, the elements are moved to the new array, the old internal array is deleted, and then the new element is added

    • C.

      The new element is not added, and -1 is returned

    • D.

      The new element is not added, and null is returned

    Correct Answer
    B. A new, bigger internal array is created, the elements are moved to the new array, the old internal array is deleted, and then the new element is added
    Explanation
    When a new element is added to an ArrayList whose internal array is already full, the ArrayList creates a new, bigger internal array. Then, it moves all the elements from the old array to the new array. After that, the old internal array is deleted. Finally, the new element is added to the ArrayList.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 12, 2011
    Quiz Created by
    Lonesarah

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.