CSC 311-2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

For an array of 10 elements, answer (1) how many operations does swapElements() perform. Count the number of multiplications, additions, memory accesses, and assignments. Next, answer (2). Does this operation count change when the length of the array increases? NOTE: The multiplication and addition operations are used to calculate the memory location of the indexed array. (1) 3 reads, 3 writes, 4 multiplications, and 4 additions; (2) NO (1) 4 reads, 4 writes, 3 multiplications, and 3 additions; (2) NO (1) 3 reads, 3 writes, 4 multiplications, and 4 additions; (2) YES (1) n reads, n writes, 4n multiplications, and 4n additions; (2) YES

(1) 3 reads, 3 writes, 4 multiplications, and 4 additions; (2) NO

A Map data structure may have how many duplicate keys?

0

For a log-log plot of a polynomial order of growth with an exponent of 4, what is the slope of the straight-line plot?

4

By declaring the private instance variable of type List, what does the following implementation of ListClientExample provide? Requires the ArrayList type. Requires the Array type. Does not allow changing the list object's implementation without changing its interface. Allows for changing the list object's implementation without changing its interface.

Allows for changing the list object's implementation without changing its interface

The Java Collections Framework (JCF) defines an interface called List and provides two implementations, which are: ArrayList & LinkedList String & ArrayList StringList & LinkedList Map & Stack

ArrayList & LinkedList

In a doubly linked list, which of the following is correct? Each node contains a link to the next node and a link to the previous node. Each node contains a link to the tail node. The LinkedList object contains only a link to the last element of the list. Each node contains a link to the head node.

Each node contains a link to the next node and a link to the previous node.

In the DOM tree below, the <head> node has one child, <body>, and the <body> node has one child, <p>. True False

False

When does the run time performance of a List implementation *not* matter very much? When the problem size is large enough that the order of growth predicts which data structure is better. If the list operations don't take up a substantial fraction of the run time of your entire program. If the lists, you are working with are very large. When the space consumed by the link fields in a linked list are significant.

If the list operations don't take up a substantial fraction of the run time of your entire program.

In the MyLinearMap implementation which uses an underlying ArrayList, assume we have written the following remove method. If findEntry's order of growth (time complexity) is linear then remove has what order of growth? O(n^3) O(1) O(n) O(nm)

O(n)

What is the order of growth for the following algorithm? 0(n) 0(1) 0(n^m) 0(10)

O(n)

Notice from the object diagram below, that the Index class maps from a search term (key) to a Set object. What type of objects does the Set instance contain directly (i.e., what type is specified in the instantiation of the generic Set)? String Map TermCounter Integer

TermCounter

Comparable is a generic type. True False

True

Constant time: An algorithm is "constant time" if the run time does not depend on the size of the input. For example, if you have an array of n elements and you use the bracket operator ([]) to access one of the elements, this operation takes the same number of operations regardless of how big the array is. True False

True

DFS (depth-first search) starts at the root of a tree and selects the first child. If the child has children, it selects the first child again. When it gets to a node with no children, it backtracks, moving up the tree to the parent node, where it selects the next child if there is one; otherwise, it backtracks again. When it has explored the last child of the root, it's done. Is this true? True False

True

If the slope on a log-log plot is close to 1, that suggests the algorithm is linear. True False

True

Implementing the Iterable interface allows an object to be the target of the enhanced for statement (sometimes called the "for-each loop" statement). True False

True

In the context of web search, an index is a data structure that makes it possible to look up a search term and find the pages where that term appears. True False

True

It is dangerous to use mutable objects as keys in data structures that use hashing. True False

True

The doubly linked implementation is better than ArrayList for adding and removing at the beginning, and just as good as ArrayList for adding and removing at the end. True False

True

To avoid dealing with the details of computer hardware, we usually identify the basic operations that make up an algorithm — like addition, multiplication, and comparison of numbers — and count the number of operations each algorithm requires. True False

True

In the following table, "MyLinkedList" is implemented as a singly linked list. "LinkedList" refers to the JCF implementation, a doubly linked list. Which operation's run-time performance is improved in the doubly linked list over the singly listed list from the choices below? add at the end, remove from end add at the beginning, remove from the end get / set add at the end, remove from beginning

add at the end, remove from end

Java provides an interface called Map that specifies the methods a map should provide; the put(key, value) method does what? none of these adds a new key-value pair to the Map, or if the key is already in the map, does not change the value adds a new key-value pair to the Map, or if the key is already in the map, it replaces the value associated with key looks up a key and returns the corresponding value

adds a new key-value pair to the Map, or if the key is already in the map, it replaces the value associated with key

Since MyLinearMap uses an ArrayList (see below) which must contain all entries of the same type, what must be true about all of the map's keys and values? only the keys must be of type K, the types of values may vary only the keys must be of type V all of the keys must be of type V, and all of the values must be of type K all of the keys must be of type K, and all of the values must be of type V

all of the keys must be of type K, and all of the values must be of type V

The following code snippet represents what type of class? a class that is derived from more than one parent an anonymous class an abstract class a child class

an anonymous class

Why does the ArrayList JCF implementation have a smaller memory footprint than the linked list versions? because each node is linked from the tail node because each node contains link fields because each node is stored compactly in memory without link fields because each node is linked from the head node

because each node is stored compactly in memory without link fields

When a deque is used as a stack, elements are pushed and popped from which part of the deque? beginning tail middle end

beginning

What type of traversal is being performed by the iterator in the following example? NOTE: You will need to recall this from the textbook and lectures. none of these depth-first search (DFS) breadth-first search (BFS) random search

depth-first search (DFS)

For adding elements at the end, we expect a singly linked list to be faster than an array-based list. true false

false

What data structure does the following DFS algorithm use to backtrack to a parent node when it reaches a leaf node? it stores children in a local queue none of these it uses the call stack of the execution environment (JVM) it uses a local stack variable

it uses the call stack of the execution environment (JVM)

Which Java *package* is the Java Collections Framework (JCF) contained in? NOTE: Do not confuse the Java module where the JCF is located and its package. The package is within the module. java.util java.math java.io java.net

java.util

In a log-log plot, if the run time is proportional to n^k for any exponent k, we expect to see a straight line with a slope of? m 2 k n

k

This equation implies that if we plot runtime versus n on a log-log scale, we expect to see what kind of curve? polynomial linear exponential logarithmic

linear

Java provides an interface called Map that specifies the methods a map should provide; the get(key) method does what? adds a new key-value pair to the Map, or if the key is already in the map, does not change the value looks up a key and returns the corresponding value adds a new key-value pair to the Map, or if the key is already in the map, it replaces the value associated with key none of these

looks up a key and returns the corresponding value

The following Entry class implies what about the key and value for each entry in the map? only the keys must be the same for all entries in the map they can vary from one entry to another since Map.Entry is a generic only the values must be the same for all entries in the map none of these

none of these

If you use ArrayList to implement a stack data structure in Java, you'll need to do which of the following? add and remove from the middle only add and remove from the end only remove from the beginning and add to the end add to the beginning and remove from the end

only add and remove from the end

In Java, the Deque interface provides which methods which make it compatible with a stack data structure? seek, pop, push, and isFull push, pop, peek, and isEmpty push, pop, insert, get get, set, remove, create

push, pop, peek, and isEmpty

For ____ problems, a quadratic algorithm might be faster than a linear algorithm, or linear might be faster than constant time. very large small large slow

small

Given the following order of growth comparisons between the array and linked list implementations of the List interface, which one is linear when inserting elements at the beginning of the list? the linked list implementation the array implementation neither both

the array implementation

If you assign the deque variable like so: LinkedList deque = new LinkedList(); what is true? you can only use the deque interface you can use only the queue interface you can use all the methods in the List interface you can't use the deque variable as a deque data structure

you can use all the methods in the List interface


Set pelajaran terkait

Data Structures Midterm CHAPTER 8

View Set

C243 Ch. 8 Intercompany Indebtedness

View Set

Impact of European Colonialism in the Americas

View Set

4A: Dónde vs. Adónde Additional Practice

View Set

Chapter 7: Assisting with the Nursing Process

View Set

II Lecture Chapter 20 Multiple Choice and True False Quiz

View Set