CSCI 1302 Computer Science Exam 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,837
Questions: 29 | Attempts: 1,189

SettingsSettingsSettings
CSCI 1302 Computer Science Exam Quiz! - Quiz

Did you know the capacity of an ArrayList grows automatically and is used in the Java language? Computer science allows you to solve complicated and challenging problems. This science involves computer language that employs the ArrayList. These listings are important because they help with the flow of the programs such as Java, Python, and Swift. So, go with the flow and try the quiz; you will learn about the importance of the Array!


Questions and Answers
  • 1. 

    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

    Correct Answer
    C. IllegalArgumentException
    Explanation
    The constructor for an array-based list should throw an IllegalArgumentException if its parameter is zero or negative. This is because an IllegalArgumentException is typically thrown when a method or constructor receives an invalid argument. In this case, a zero or negative capacity for the internal array is considered invalid as it would not be able to store any elements.

    Rate this question:

  • 2. 

    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

    Correct Answer
    C. It is implemented as a class that uses an internal array to hold the elements of the list
    Explanation
    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 the elements and provides methods to add, remove, and access elements in a flexible manner. The use of an internal array allows for dynamic resizing of the ArrayList as elements are added or removed, making it a convenient data structure for storing and manipulating collections of objects.

    Rate this question:

  • 3. 

    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

    Correct Answer
    D. 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, the existing elements from index k to the end of the list (positions k..s-1) need to be moved toward the end of the array to make space for the new element. The elements at positions 0..k-1 do not need to be moved. Therefore, the correct answer is "the elements at current positions k..s-1 must be moved toward the end of the array".

    Rate this question:

  • 4. 

    The boolean contains(E element) method searches an ArrayList for a given element. 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

    Correct Answer
    A. Uses sequential search to locate the element
    Explanation
    The correct answer is "uses sequential search to locate the element". This is because the sequential search algorithm iterates through each element in the ArrayList one by one until it finds a match with the given element. This is an efficient implementation as it does not require any specific order or sorting of the elements in the list. If the element is not found, the search will continue until the end of the list and then return a result indicating that the element was not found.

    Rate this question:

  • 5. 

    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

    Correct Answer
    C. Searches a list for the occurrence of an object and returns its index
    Explanation
    The int indexOf(Object o) method of the List interface searches a list for the occurrence of an object and returns its index. This means that it checks each element in the list to see if it matches the given object, and if it finds a match, it returns the index of that element. If the object is not found in the list, it returns -1.

    Rate this question:

  • 6. 

    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

    Correct Answer
    C. 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 means that it represents the actual number of items that have been added to the list and are accessible. It does not refer to the length of the internal array or the number of bytes of memory that the list can hold.

    Rate this question:

  • 7. 

    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

    Correct Answer
    B. 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 the capacity determines the maximum number of elements that the list can hold. It is important to note that the capacity is not necessarily the same as the number of elements currently stored in the list. The capacity can be greater than the number of elements, allowing for potential future additions to the list without the need for resizing the internal array.

    Rate this question:

  • 8. 

    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

    Correct Answer
    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
    Explanation
    The given answer states that the recursive method should still handle the base case of an empty list, even though the scientists never ask for the size of an empty list. This is because an empty list is a valid case and should be accounted for in the recursive method. Additionally, the answer suggests that the recursive method can be modified to use a list of size 1 as the base case, which implies that the method can be optimized by considering a smaller input size as the base case. Both of these statements are correct.

    Rate this question:

  • 9. 

    A collection that is accessed in first in first out fashion is called?

    • A.

      A stack

    • B.

      A queue

    • C.

      A linked list

    • D.

      An array based collection

    Correct Answer
    B. A queue
    Explanation
    A collection that is accessed in first in first out fashion is called a queue. In a queue, the element that is inserted first is the first one to be removed. This data structure follows the principle of "First-In-First-Out" (FIFO), similar to waiting in a queue for a service. Elements are added at the end of the queue and removed from the front, maintaining the order in which they were added. This makes a queue suitable for scenarios where the order of insertion and removal is important, such as processing tasks in the order they were received.

    Rate this question:

  • 10. 

    The stack method that returns an element from the stack without removing it is:

    • A.

      Peek

    • B.

      Pop

    • C.

      Push

    • D.

      Spy

    Correct Answer
    A. Peek
    Explanation
    The stack method "peek" returns an element from the stack without removing it. This means that when the "peek" method is called, it will allow us to access the top element of the stack without actually removing it from the stack. This can be useful when we want to check the value of the top element without modifying the stack's contents.

    Rate this question:

  • 11. 

    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

    Correct Answer
    A. None of the above
    Explanation
    When the stack method push is called on an empty stack, it does not call the stack empty, throw an EmptyStackException, or add its argument to the stack. Instead, it simply adds the argument to the stack.

    Rate this question:

  • 12. 

    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

    Correct Answer
    B. False
    Explanation
    When using an array to implement a stack, the push method does not wrap around to the beginning of the stack when it reaches the end. Instead, it throws an error or returns a stack overflow message indicating that the stack is full. To implement a stack that wraps around to the beginning, a circular array or a linked list can be used.

    Rate this question:

  • 13. 

    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;

    Correct Answer
    B. Return first == null;
    Explanation
    The correct answer is "return first == null;". In a linked list implementation, the reference "first" points to the first node of the list. If the list is empty, the "first" reference will be null. Therefore, the statement "return first == null;" checks if the list is empty by comparing the "first" reference to null. If it is null, it means the list is empty and the method will return true. Otherwise, it will return false.

    Rate this question:

  • 14. 

    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

    Correct Answer
    B. Contiguous allocation
    Explanation
    An array-based list such as ArrayList uses contiguous allocation to allocate storage for its elements. This means that the elements are stored in adjacent memory locations, allowing for efficient access and retrieval of elements using their indices. Contiguous allocation also ensures that the elements are stored in a continuous block of memory, which can improve cache performance and reduce memory fragmentation.

    Rate this question:

  • 15. 

    The objects that form the units of memory allocation in a linked list are called?

    • A.

      Elements

    • B.

      Memory modules

    • C.

      Nodes

    • D.

      Memory modules

    Correct Answer
    C. Nodes
    Explanation
    In a linked list, the objects that form the units of memory allocation are called nodes. Each node contains data and a reference (or link) to the next node in the list. These nodes are connected in a sequential manner, allowing for efficient insertion and deletion operations. Therefore, the correct answer is nodes.

    Rate this question:

  • 16. 

    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

    Correct Answer
    B. If you remove the head of the list, what remains is also a list
    Explanation
    A list can be considered a recursive data structure because if you remove the head of the list, what remains is also a list. This is because a list is made up of nodes, where each node contains a value and a reference to the next node in the list. When the head node is removed, the reference of the second node becomes the new head, and the rest of the nodes are still connected in the same way, forming a new list. This recursive nature allows for operations like traversing the list or performing recursive algorithms on it.

    Rate this question:

  • 17. 

    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

    Correct Answer
    C. a field to store the element, and two references to keep track of successor and predecessor nodes
    Explanation
    A typical circular doubly linked list node has a field to store the element and two references to keep track of the successor and predecessor nodes. These references allow for easy traversal in both directions, making it possible to navigate the list forwards and backwards. By having these two references, the node can maintain a circular structure, where the last node points to the first node and the first node points to the last node, creating a loop.

    Rate this question:

  • 18. 

    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

    Correct Answer
    D. if you remove the head of the list, what remains is also a list
    Explanation
    A list can be considered a recursive data structure because if you remove the head of the list, what remains is also a list. This means that the structure of the list can be defined in terms of smaller versions of itself, leading to a recursive definition. Each element in the list can be seen as a node that contains a value and a reference to the rest of the list, which is another list. This recursive structure allows for operations such as traversing the list or performing recursive algorithms on it.

    Rate this question:

  • 19. 

    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

    Correct Answer
    C. No changes to the node class are necessary
    Explanation
    The correct answer is "no changes to the node class are necessary" because recursion can be implemented on linked lists without modifying the node class. Recursion relies on the recursive function calling itself on a smaller or simpler version of the problem. In the case of linked lists, the recursive function can be implemented in a separate function that takes the current node as a parameter and calls itself on the next node. This can be done without modifying the node class itself.

    Rate this question:

  • 20. 

    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

    Correct Answer
    A. assign the successor reference in the node with index k to the successor reference in the node with index k-1
    Explanation
    The correct answer is to assign the successor reference in the node with index k to the successor reference in the node with index k-1. This means that the node at index k will be removed from the linked list by bypassing it and directly connecting the previous node to the next node. This effectively removes the node from the linked list without any gaps or breaks in the sequence.

    Rate this question:

  • 21. 

    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

    Correct Answer
    C. Assigns an index to each of its elements
    Explanation
    A list is a collection that assigns an index to each of its elements. This means that each element in the list can be accessed using its corresponding index value. The list maintains the order of the elements based on their indices, allowing for efficient retrieval and manipulation of data. This characteristic distinguishes a list from other types of collections, such as dictionaries or sets, which may associate keys with elements or have no specific order. The JList class mentioned in the options is a specific implementation of a list in the Java programming language.

    Rate this question:

  • 22. 

    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);

    Correct Answer
    B. Ref = new node(e, ref.next);
    Explanation
    The correct answer is "ref = new node(e, ref.next)". This statement creates a new node with the element "e" and sets its next reference to the node that was originally referenced by "ref.next". By assigning this new node to "ref", we update the reference to point to the newly created node, effectively adding the element "e" just after the node referenced by "ref".

    Rate this question:

  • 23. 

    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

    Correct Answer
    B. A traversal
    Explanation
    A traversal is a systematic method that starts at the beginning of the list and processes every node. It involves moving through the list, visiting each node in a specific order, such as from left to right or from top to bottom. This process allows for the examination or manipulation of data stored in each node of the list. Therefore, a traversal is the correct term to describe this systematic method.

    Rate this question:

  • 24. 

    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

    Correct Answer
    C. Has at most two successors
    Explanation
    A binary tree is a type of tree data structure in which each item can have at most two successors, known as left child and right child. This means that each item in a binary tree can have either zero, one, or two successors. Therefore, the correct answer is "has at most two successors".

    Rate this question:

  • 25. 

    The head of a linked list is also a linked list.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The statement is false because the head of a linked list is not a linked list itself. The head of a linked list is a reference to the first node of the linked list. It contains the address of the first node and does not possess the properties or methods of a linked list.

    Rate this question:

  • 26. 

    The last item in a doubly-linked list can sometimes have a sucessor.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In a doubly-linked list, each node has references to both its previous and next nodes. The last item in a doubly-linked list does not have a successor because there is no node after it. Therefore, the statement that the last item in a doubly-linked list can sometimes have a successor is false.

    Rate this question:

  • 27. 

    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

    Correct Answer
    D. A kind of binary search tree
    Explanation
    AVL tree is a kind of binary search tree that is self-balancing. It ensures that the heights of the left and right subtrees of any node differ by at most 1, which helps in maintaining a balanced tree structure. This self-balancing property allows for efficient operations such as insertion, deletion, and searching in logarithmic time complexity. Unlike other options mentioned, an AVL tree is specifically designed to maintain balance, making it a specialized type of binary search tree.

    Rate this question:

  • 28. 

    A node in a binary tree can have two parents.

    • A.

      True

    • B.

      False

    • C.

      Neither

    Correct Answer
    B. False
    Explanation
    A node in a binary tree cannot have two parents because by definition, a binary tree is a tree data structure in which each node has at most two children. Each node can have a maximum of one parent, except for the root node which has no parent. Therefore, the statement that a node in a binary tree can have two parents is incorrect.

    Rate this question:

  • 29. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    In a complete binary tree, all levels except the last level must be completely filled, and the last level must be filled from left to right. Therefore, it is not necessary for the subtrees of a node in a complete binary tree to be equal in height. Some nodes may have subtrees of different heights depending on the structure of the tree.

    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
  • Sep 03, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 15, 2011
    Quiz Created by
    Lonesarah
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.