CSCI 1302 Exam: Computer Science! Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Lonesarah
L
Lonesarah
Community Contributor
Quizzes Created: 2 | Total Attempts: 1,845
| Attempts: 653 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. The position of an item within a list is called its:

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.

Submit
Please wait...
About This Quiz
CSCI 1302 Exam: Computer Science! Quiz - Quiz

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?... see moreDo 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.
see less

2. 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?

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.

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

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.

Submit
4. 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.

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.

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

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.

Submit
6. An ArrayList is so-called because:

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.

Submit
7. The difference between an array and an ArrayList is:

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.

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

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.

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

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.

Submit
10. The capacity of an array-based list such as ArrayList.

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.

Submit
View My Results

Quiz Review Timeline (Updated): Aug 29, 2024 +

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

  • Current Version
  • Aug 29, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • May 12, 2011
    Quiz Created by
    Lonesarah
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
The position of an item within a list is called its:
A constructor for an array-based list takes an integer parameter, to...
If a new element is added to an ArrayList whose internal array if...
A new element is added to an ArrayList object at index k. Assuming the...
The size of an array-based list such as ArrayList.
An ArrayList is so-called because:
The difference between an array and an ArrayList is:
The E get(int index) method of the List interface should throw an...
The boolean contains(E element) method searches an ArrayList for a...
The capacity of an array-based list such as ArrayList.
Alert!

Advertisement