Exam 16: Basic Data Structures

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Consider the following code snippet: LinkedList<String> words = new LinkedList<String>(); Words.addFirst("xyz"); Words.addLast("jkl"); Words.addLast("def"); System.out.print(words.removeFirst()); System.out.print(words.removeLast()); System.out.print(words.removeLast()); What does this code print?

(Multiple Choice)
4.7/5
(33)

Which of the following statements about removing a node from a linked list is correct?

(Multiple Choice)
4.9/5
(33)

If the current size of an array list is less than the length of the buffer, adding an element at the end of an array list takes ____ time.

(Multiple Choice)
4.8/5
(45)

Complete the following code, which is intended to add an element to the top of a stack implemented as a linked list. Node newNode = new Node(); NewNode.data = element; _________________ _________________

(Multiple Choice)
4.9/5
(41)

Assume that you have a hash table in which there are few or no collisions. What is the time required to locate an element in this hash table?

(Multiple Choice)
4.9/5
(33)

Given the LinkedListStack class implementation discussed in section 16.3 (partially shown below), select the statement(s) to complete the peek method. public class LinkedListStack { Private Node first; Public LinkedListStack() { First = null; } Public Object peek() { If (empty()) { Throw new NoSuchElementException(); } _____________________________ } ).. }

(Multiple Choice)
4.8/5
(28)

Which of the following statements about a linked list and its iterator is NOT correct?

(Multiple Choice)
4.8/5
(40)

Which of the following statements about a linked list iterator is NOT correct?

(Multiple Choice)
4.8/5
(33)

Insert the missing code in the following code fragment. This fragment is intended to add a new node to the head of a linked list: public class LinkedList { ) . . Public void addFirst(Object element) { Node newNode = new Node(); 1 NewNode.data = element; _________ 2 _________ 3 } ) . . }

(Multiple Choice)
4.7/5
(35)

In the textbook implementation, the Node class is a private inner class of the LinkedList class. Which of the following statements regarding this implementation is NOT correct?

(Multiple Choice)
4.9/5
(35)

In a linked list data structure, when does the reference to the first node need to be updated? I inserting into an empty list II deleting from a list with one node III deleting an inner node

(Multiple Choice)
4.8/5
(40)

Assume that you have a hash table in which there are an average number of collisions. What is the time required to find an element in this hash table?

(Multiple Choice)
4.8/5
(35)

Which operations from the array list data structure could be used in the implementation of the push and pop operations of a stack data structure? I addLast II addFirst III removeFirst

(Multiple Choice)
5.0/5
(38)

Complete the following code snippet, which is intended to compress a hash code to become a valid array index: _____________________ If (h < 0) { h = -h; } Position = h % arrayLength;

(Multiple Choice)
4.8/5
(31)

Suppose we maintain a linked list of length n in sorted order. What would be the big-Oh notation for the add operation?

(Multiple Choice)
4.8/5
(35)

Given the partial ArrayList class declaration below, select an expression to complete the contains method. public class ArrayList { Private Object[] elements; Private int currentSize; Public ArrayList() { Final int INITIAL_SIZE = 10; Elements = new Object[INITIAL_SIZE]; CurrentSize = 0; } Public boolean contains(Object item) { For (int i = 0; ________________ ; i++) { If (elements[i].equals(item)) { Return true; } } Return false; } ).. }

(Multiple Choice)
5.0/5
(40)

Using the textbook's implementation of a singly linked list and linked list iterator, the following steps are required to remove a node from the middle of a linked list. Place these steps into the order in which they should be performed. I The preceding node's next reference must be updated to skip the removed node. II The iterator's position reference must be set to the previous reference. III The previous reference must be checked to see if it is equal to the position reference.

(Multiple Choice)
4.8/5
(35)

Which of the following statements about adding an element to a hash table is NOT correct?

(Multiple Choice)
4.7/5
(36)

Given the ArrayStack class implementation discussed in section 16.3 (partially shown below), select the statements needed to complete the push method. public class ArrayStack { Private Object[] elements; Private int currentSize; Public ArrayStack() { Final int INITIAL_SIZE = 10; Elements = new Object[INITIAL_SIZE]; CurrentSize = 0; } Public void push(Object element) { GrowIfNecessary(); ________________ ________________ } }

(Multiple Choice)
4.7/5
(46)

What type of access does the use of an iterator with a LinkedList provide for its elements?

(Multiple Choice)
4.7/5
(35)
Showing 21 - 40 of 104
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)