Site icon Tutor Bin

North Lake College Computer Science Java Worksheet

North Lake College Computer Science Java Worksheet

Description

QUESTION 1

  1. What kind of underlying structure does Java use to create an ArrayList?
    a. queue structure
    b. array
    c. list structure
    d. stack structure

5 points

QUESTION 2

  1. Which of the following operations are supported by a list? (Mark all that apply.)
    a. Find how many elements are in this list.
    b. Retrieve an element from this list.
    c. Insert a new element to this list.
    d. Delete an element from this list.
    e. Find whether an element is in this list.

5 points

QUESTION 3

  1. Which of the following statements are true? (Mark all that apply.)
    a. MyArrayList is implemented using an array. The array is dynamically created. If the capacity of the array is exceeded, create a new larger array and copy all the elements from the current array to the new array.
    b. MyLinkedList is also implemented using an array structure.
    c. A linked structure consists of nodes. Each node is dynamically created to hold an element. All the nodes are linked together to form a list.
    d. MyArrayList and MyLinkedList are two concrete implementations of MyList.

4.5 points

QUESTION 4

  1. In the implementation of MyArrayList, which of the following are true? (Mark all that apply.)
    a. capacity is always greater than size.
    b. size indicates the number of elements in the list.
    c. size is reduced by 1 if an element is deleted from the list.
    d. capacity is the length of the array used to store the elements in the list.
    e. capacity is reduced by 1 if an element is deleted from the list.

4.5 points

QUESTION 5

  1. In the implementation of MyArrayList, which of the following is false?
    a. Capacity never reduces
    b. Size never reduces
    c. If the current capacity equals to size, capacity is doubled when a new element is added to MyArrayList
    d. Inside MyArrayList, a regular array is used to store elements.

4.5 points

QUESTION 6

  1. Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants?
    a. ArrayList
    b. stack
    c. priority queue
    d. queue

4.5 points

QUESTION 7

  1. Which data structure is appropriate to store customers in a clinic for taking flu shots?
    a. ArrayList
    b. queue
    c. priority queue
    d. stack

4.5 points

QUESTION 8

  1. Which data structure is appropriate to store patients in an emergency room?
    a. priority queue
    b. queue
    c. stack
    d. ArrayList

4.5 points

QUESTION 9

  1. A stack can be viewed as a special type of list, where the elements are accessed, inserted, and deleted only from the end (called the tail) of the stack.

4.5 points

QUESTION 10

  1. A queue represents a waiting list. A queue can be viewed as a special type of list, where the elements are inserted into the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue.

4.5 points

QUESTION 11

  1. In the implementation of MyLinkedList, which of the following are true? (Mark all that apply.)
    a. If a linked list contains one element, first points to the node and last is null.
    b. If a linked list is empty, first is null and last is null.
    c. MyLinkedList has a capacity property.
    d. last.next is always null.
    e. MyLinkedList has the properties named first and last to point to the beginning and ending nodes in a linked list.

4.5 points

QUESTION 12

  1. Suppose list1 is a MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code:A:
    while (list1.size() > 0)
    list1.remove(0);B:
    while (list2.size() > 0)
    list2.remove(0);
    a. Code fragment B runs faster than code fragment A.
    b. Code fragment A runs as fast as code fragment B.
    c. Code fragment A runs faster than code fragment B.

4.5 points

QUESTION 13

  1. Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: A:
    for (int i = 0; i < 100000; i++)
    list1.add(0, i);B:
    for (int i = 0; i < 100000; i++)
    list2.add(0, i);
    a. Code fragment A runs faster than code fragment B.
    b. Code fragment B runs faster than code fragment A.
    c. Code fragment A runs as fast as code fragment B.

4.5 points

QUESTION 14

  1. Suppose list1 is an MyLinkedList. What order would the following code have? for (int i = 0; i < 100000; i++)
    {
    num = i * 5;
    list1.add(i, num);
    }
    a. O(n2)
    b. O(n)
    c. O(1)
    d. O(logn)

4.5 points

QUESTION 15

  1. If a value is added to the middle of an ArrayList, what happens in the underlying array? (The new size will still be less than the capacity.)
    a. All array values at and before the indicated position will be shifted to the left, and then the new value is placed in the indicated position
    b. The array is always deleted and a new array is created with the old values and the new value inserted where specified
    c. The new value is placed in the indicated position
    d. All array values at and after the indicated position will be shifted to the right, and then the new value is placed in the indicated position

4.5 points

QUESTION 16

  1. If the first value in an ArrayList is deleted, what happens in the underlying array?
    a. All array values after the first position will be shifted to the left.
    b. A brand new array is created with all values except the first one.
    c. All array values after the first position will be shifted to the right.
    d. That spot of the underlying array is just removed from the array.

4.5 points

QUESTION 17

  1. In the node class for a doubly linked list, what is the minimum set of instance variables required?
    a. element: E
    next: Node<E>
    previous: Node<E>
    head: Node<E>
    b. next: Node<E>
    previous: Node<E>
    c. element: E
    next: Node<E>
    d. element: E
    next: Node<E>
    previous: Node<E>

4.5 points

QUESTION 18

  1. In a singly linked list, the next in the last node is equal to ___________.
    a. null
    b. the last node in the list
    c. the previous node
    d. the first node in the list

4.5 points

QUESTION 19

  1. In a doubly linked list, the next in the last node is equal to ___________.
    a. the previous node
    b. the first node in the list
    c. null
    d. the last node in the list

4.5 points

QUESTION 20

  1. In a circular linked list, the next in the last node is equal to ___________.
    a. the previous node
    b. the last node in the list
    c. null
    d. the first node in the list

4.5 points

QUESTION 21

  1. Imagine you have a MyStack object with 10 nodes and a method that should return the value in the bottom node. How many nodes must the method look at?

4.5 points

QUESTION 22

  1. Imagine you have a MyQueue object with 10 nodes and a method that should return the value in the last node. How many nodes must the method look at?

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version