Final Exam

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

213654

A certain binary tree has the following inorder traversal: 4, 2, 5, 1, 3, 6 and has the following preorder traversal: 4, 5, 2, 6, 3, 1 What is its postorder traversal? Write your answer as a six-digit number with no spaces or commas. For example, if you thought the answer were 1, 2, 3, 4, 5, 6, then enter your answer as 123456

C

Adding a lastNode reference to the List's instance variables makes which operation more efficient? A. contains() B. remove() C. add() D. getLength()

B

As implemented in chapter 26, what is returned if you search a BST for an item but the item is not in the BST? A. -1 B. null C. ItemNotFoundException D. NullPointerException

B, C, G, H

Consider the following adjacency matrix where, for example, the T on row A indicates an edge going from vertex A to vertex B (reference screen shot on desktop): Which of the following statements are true about the graph represented by this matrix? A. There is a path from vertex C to vertex D B. There are two edges leading into vertex B C. This is a digraph D. There is no way to get to vertex C from any of the other vertices E. If this graph were complete, it would contain 25 edges F. The graph contains 5 edges G. There are three edges leading out of vertex E H. There is a path from vertex A to vertex D I. This is a complete graph

CBEFHI

Consider the graph shown in figure 29-10. In what order does a breadth-first traversal visit the vertices in the graph when you begin at vertex C and visit the nodes in alphabetic order? Write your answer as a string listing the vertices in the order they would be visited. For example, CABDEFGHI is a correctly formatted (but incorrect) answer.

BEFCHI

Consider the graph shown in figure 29-10. In what order does a depth-first traversal visit the vertices in the graph when you begin at vertex B and visit the nodes in alphabetic order? Write your answer as a string listing the vertices in the order they would be visited. For example, CABDEFGHI is a correctly formatted (but incorrect) answer.

C, D, E

Consider the graph shown in figure 29-23 (b) of the text, in the exercises section. Which of the following describe that graph? A. Complete B. Weighted C. Undirected D. Cyclic E. Connected F. Digraph

127

How many nodes are in a full binary tree with height 7?

D

If a BST has maximum height, what is the average time complexity for searching for an item? A. O(log n) B. O(n^2) C. O(n log n) D. O(n)

10

If a complete 10-node digraph is represented using an adjacency matrix, where true represents an edge between two nodes, how many times will false appear in the matrix?

A

If a given BST is a full binary tree, what is the average time complexity for searching for an item? A. O(log n) B. O(n log n) C. O(n) D. O(n^2) E. O(1)

E

If a maxheap contains n elements, what is the efficiency of calling removeMax() to remove all of the elements, one at a time, putting them into a new array? A. O(n^2) B. O(1) C. O(log n) D. O(2^n) E. O(n log n) F. O(n)

94, 95

If a maxheap has 100 elements in it, implemented using an array with an empty element at index 0, the element with index 47 has two children, and their indexes are ________ and ________.

23

If a maxheap has 100 elements in it, implemented using an array with an empty element at index 0, what is the index of the parent of the element whose index is 47?

A, B, F, H

If a maxheap has 100 elements in it, implemented using an array with an empty element at index 0, which of the following are true? A. The element with index 2 must be larger than the element with index 4 B. The heap is complete C. The element with index 2 must be larger than the element with index 7 D. The element with index 2 must be larger than the element with index 3 E. The smallest element must have index 100 F. Every subtree must be a maxheap G. The heap is full H. The largest element must have index 1

D

If you add("CAT", 47) and then add ("CAT", 99), what should happen? A. "CAT" should end up in the table twice, once with 47 and once with 99 B. "CAT" should end up in the table with 47, and an exception should be thrown C. "CAT" should end up in the table with 47, but no exception should be thrown D. "CAT" should be updated to 99

A

If you add("CAT", 47) and then add ("DOG", 47), what should happen? A. "CAT" and "DOG" should end up in the table, each with a value of 47 B. "CAT" should end up in the table, and "DOG" should be ignored C. "CATDOG" should end up in the table with 47 D. None of the above

B

If you add("MOUSE", 70) and add("RAT", 75) and "MOUSE".hashCode() is 75, and "RAT".hashCode() is 51, will this cause a collision? A. Yes B. No C. None of the above D. All of the above

D

If you add("MOUSE", 70) and later remove("MOUSE"), what should happen? A. A compiler error, because remove should include an int value B. The location in the array that contained the key "MOUSE" should be replaced with null C. The location in the array that contained the key "MOUSE" should have its value set to -1 D. The location in the array that contained the key "MOUSE" should be designated as available

A, B, C

If you have linked data, with instance variables for the first and last nodes, which methods would be O(1) operations? A. Adding an element to the end of the linked data B. Adding an element to the beginning of the linked data C. Removing an element from the beginning of the linked data D. Removing an element from the end of the linked data

A, C

In Java's List interface (java.util.List), which of the following are true? A. A sort() method is included in the interface B. Indexes for elements begin at 1, not 0. C. indexOf() returns -1 if the specified item is not found. D. The method that returns the length of the ArrayList is getLength() E. Both add() methods return a boolean.

66486

In Java, what is the hash code for "CAT"?

19

In a complete graph with 20 vertices, how many vertices will be in each node's adjacency list?

B

In a perfect hash function, what is the complexity of both the add method and the get method? A. O(n^2) B. O(1) C. O(n log n) D. O(n) E. O(log n)

D

In a priority queue, elements are added to the back of the queue. When an element is removed, which one should be removed? A. Always remove the element from the front of the queue. B. Always remove the element from the back of the queue. C. The element with the highest priority. If there is a tie, remove the one closest to the back. D. The element with the highest priority. If there is a tie, remove the one closest to the front.

D

In an array implementation of a hash table, what is the best way to implement the getValue() method that returns the value for a specified key? A. A linear search of the key in the underlying array. B. A binary search for the key in the underlying array. C. Use the hash of the specified key to see if the key is at the expected index. If it is, return the value. If it is not, return null. D. Use the hash of the specified key to see if the key is at the expected index. Perform a linear probe beginning at that index.

A. B

In an array implementation of a hash table, you are likely to have an array for the elements, as well as a variable indicating the number of elements in the table. What is the recommended way to implement the clear() method? A. Set the number of elements to zero B. Set all elements in the array to null C. Set all elements in the array to "available" D. Print a message to the screen saying that the table has been cleared

false

In general, we can expect that a recursive solution will perform more efficiently than a non-recursive solution. True/False

Brett

In the BST shown in (d) of figure 25-5, what is the inorder predecessor of Brittany?

jared

In the BST shown in (d) of figure 25-5, what is the inorder predecessor of Jim?

jared

In the BST shown in (d) of figure 25-5, what is the inorder successor of Doug?

D

In the array-based implementation of queue described in chapter 11, if the queue reaches the end of the array, where should new elements be added? A. Always increase the capacity of the array and continue adding new elements to the end B. Remove the current last item and replace it with the new item C. Remove the first item, shift all other elements down, and add to the last location in the array D. to the beginning of the array if there is room

A, C

In the basic implementation of Linked List, which operations have efficiency O(1)? A. remove (best case) B. adding elements to the end C. getLength D. remove (worst case)

B, C, D, F

In the deque ADT (double-ended queue), which of the following behaviors would we expect? A. Adding elements to the middle B. Removing elements from the back C. Adding elements to the front D. Removing elements from the front E. Removing elements from the middle F. Adding elements to the back

1214

In the example described in section 22.2, h(555-1264) would be 1264. What would be h(444-1214)?

GDBHEIACF

In the following binary tree, what will be the order that the nodes will be visited using inorder traversal? Type your answer by typing all 9 letters in the order they will be visited without typing spaces. For example, a wrong answer (but correctly formatted) would be ABCDEFGHI (reference screen shot on desktop).

GDHIEBFCA

In the following binary tree, what will be the order that the nodes will be visited using postorder traversal? Type your answer by typing all 9 letters in the order they will be visited without typing spaces. For example, a wrong answer (but correctly formatted) would be ABCDEFGHI (reference screen shot on desktop).

ABDGEHICF

In the following binary tree, what will be the order that the nodes will be visited using preorder traversal? Type your answer by typing all 9 letters in the order they will be visited without typing spaces. For example, a wrong answer (but correctly formatted) would be ABCDEFGHI (reference screen shot on desktop).

IllegalStateException

In the java.util.Queue interface, what is the type of exception that will be thrown if you attempt to add() an element but there is no room to add it?

10

Suppose a binary tree has 513 nodes. If you know this tree is complete, but not full, what is its height?

E

Suppose the hash table is full, and each key has a different hash code. What will be the average efficiency of the getValue() and remove() operations? A. getValue() is O(1) and remove() is O(1) B. getValue() is O(1) and remove() is O(n) C. getValue() is O(n) and remove() is O(1) D. getValue() is O(n) and remove() is O(n) E. Can't be determined from the above information.

D

Suppose the hash table is full, and each key has the same hash code. What will be the average efficiency of the getValue() and remove() operations? A. getValue() is O(1) and remove() is O(1) B. getValue() is O(1) and remove() is O(n) C. getValue() is O(n) and remove() is O(1) D. getValue() is O(n) and remove() is O(n) E. Can't be determined from the above information.

C

Suppose you find that your array is full, or nearly full, and you decide to double the size of the array and move the elements into the new array. After you create the new array, how should you move the elements into the new array? A. The position in the new array should be the same as the position in the old array. B. Remove all gaps from the data by putting all the elements as close to the beginning of the array as possible. C. Use the hash value of each key to determine its placement in the new array. D. None of the above. Array resizing should not happen in a hash table.

21

Suppose you have a directed graph with 10 nodes, represented by an adjacency matrix. If you were to add another node, how many new cells would be added to the adjacency matrix?

50

Suppose you have an array of 100 elements, and you want to add them all to an empty maxheap. Using the approach described in section 26.14, how many times will the reheap method need to be executed?

C, D

Which of the following operations are O(1) for an array-based implementation of List? A. toArray() B. Adding to the beginning of the list C. getEntry() D. Adding to the end of the list when resizing is not needed E. contains()

A, B

Typically, what should happen if we attempt to add an item to a BST but the item is already in the tree? Check all that should happen A. The value of that item should be returned. B. The tree should not change. C. NullPointerException should be thrown D. The duplicate item should be added so that it appears twice in the BST. E. null should be returned.

21

Using the hashing algorithm described in 21.4 ("typical hashing"), if tableSize is 103, then both of the following phone numbers will map to the same index: 555-4759, and 555-4038 will map to the same index. What is that index?

B

What is clustering? A. A way to make candy B. It's a consequence when using linear probing C. It is a technique used to find and delete duplicate data. D. It is a way to improve hash functions E. No answer text provided.

B

What is the complexity of the add() algorithm for a maxheap of size n? A. O(1) B. O(log n) C. O(n log n) D. O(n) E. O(2^n) F. O(n^2)

c

What is the complexity of the removeMax() algorithm for a maxheap of size n? A. O(1) B. O(n^2) C. O(log n) D. O(n log n) E. O(n) F. O(2^n)

C

What is the efficiency of adding an array of n items to an initially empty maxheap, if the reheap() method is used on all of the nodes except the leaf nodes? A. O(n log n) B. O(log n) C. O(n) D. O(n^2) E. O(1) F. O(2^n)

A

What is the efficiency of adding n items to an initially empty maxheap, if each element is added by calling the add() method? A. O(n log n) B. O(n^2) C. O(log n) D. O(n) E. O(2^n) F. O(1)

D

What is the efficiency of the heap sort algorithm, on average? A. O(1) B. O(n^2) C. O(n) D. O(n log n) E. O(2^n) F. O(log n)

10

What is the height of a full binary tree with 1023 nodes?

15

What is the height of the tallest binary tree that contains 15 nodes?

90

What is the largest number of edges a 10-node digraph can have?

55

What is the next number Fibonacci number in this sequence? 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, _______

C

What is the purpose of hashing? A. It splits a string into several smaller strings B. It converts int values to strings C. It converts search keys to indexes D. It is a technique for cooking potatoes for breakfast.

A

What is the purpose of linear probing? A. It locates an empty spot in the array when a collision occurs B. It counts how many spots in the array are empty. C. It checks to make sure your heart is still beating. D. It looks for duplicates in the array

B

What is the purpose of the described private makeRoom() method in the array-based implementation of List? A. It doubles the size of the array when the array is too small. B. It shifts values to the right in order to make a spot for a new element to be added. C. It sets the size of the array to MAX_CAPACITY D. It makes sure that the size of the array is at least DEFAULT_CAPACITY.

B

What is the purpose of the described private method getNodeAt() A. It returns the node before the last node. B. It returns the node at a given position. C. It returns the last node. D. It returns the first node containing a specified value.

D

What is the time complexity of the BST method isEmpty? A. O(n) B. O(log n) C. O(n log n) D. O(1) E. O(n^2)

D

What is the time complexity of the binary tree method preorderTraversal? A. O(n log n) B. O(n^2) C. O(1) D. O(n) E. O(log n)

8

What value should be in position 1 after the following code is executed, assuming myList refers to a list of type Integer? myList.add(5); myList.add(1, 6); myList.add(1, 7); myList.add(1, 8); myList.add(1, 9); myList.remove(1);

A

When using separate chaining, what should happen if two keys have the same hashcode? A. Both key-value pairs should be stored at the same location. B. Delete the old key-value pair and insert the new one. C. Replace the old key-value pair with the new one. D. Do not add either key-value pair to the collection.

C

When you add("CAT", 47) to the hash table, what should be stored in the array? A. "CAT" but not 47 B. 47 but not "CAT" C. Both "CAT" and 47 D. None of the above

A, B

Which instance variables (data fields) are used in the textbook's basic implementation of a Link List? A. A reference to the first node B. A count of the number of items in the linked chain C. A reference to the second-to-last element D. A reference to the last node

C

Which methods should probably be implemented first in order to make it easier to test other methods? A. isEmpty and getLength B. getLength and toArray C. add and toArray D. add and remove

A, B, C, E

Which of the following would we expect to be features of the ADT List? A. Add a new entry to the middle of the list B. Add a new entry to the beginning of the list C. Determine the number of items in the list D. Duplicates are not allowed E. Add a new entry to the end of the list

A, C, D

Which of the following are features of a doubly linked chain implementation of Deque? A. Each Node has an instance variable pointing to the previous Node. B. LinkedDeque will require an instance variable to keep track of the number of items in the deque C. Each Node has an instance variable pointing to the next Node. D. LinkedDeque will have instance variables for the first node and the last node.

A, B, C, D

Which of the following are properties of a good hash function? A. It is easy to calculate B. It converts a key to an integer C. It minimizes collisions D. If two objects are considered the same using the equals() method, then they should have the same hash code. E. It maps many different keys to the same index

B, D

Which of the following are true about adjacency matrices compared to adjacency lists A. An adjacency list for vertex n will tell you all the vertices that can reach vertex n. B. It is faster to determine if two vertices are connected using a matrix than a list C. For a weighted graph, an adjacency list won't work, but an adjacency matrix will work. D. For a sparse graph, an adjacency list uses less memory than an adjacency matrix.

A, D, E, G

Which of the following are true about binary trees? A. If a binary tree is full, then it must be completely balanced B. If a binary tree is complete, then it must also be full C. The root's left subtree must have the same height as the root's right subtree D. If a binary tree is full, then it must also be complete E. If a binary tree is completely balanced, then it must also be full F. Each node must have one or two children G. If the subtrees in each node of a binary tree differ in height by either 1 or 0, then the binary tree is balanced

C, D

Which of the following are true about hash functions? A. It requires a string as input B. If the hash function is applied to two different keys, then the result is guaranteed to be two different int outputs. C. If the cost of the hash function is low, then adding an entry to a hashTable is O(1) D. It returns an int as output

A, B, C, E

Which of the following are true about merge sort A. Java's Arrays.sort() method sometimes uses a merge sort. B. The algorithm involves splitting an array into two smaller arrays, sorting each part, and then merging them together again. C. In the worst case, it is O(n log n) D. In the best case, it is O(n). E. Like quick sort, it uses a divide-and-conquer approach

C, D, E

Which of the following are true about queues? A. Queues operate based on a "last in, first out" rule B. New entries are added to the front of the queue C. Queues exhibit FIFO behavior D. Queues are a useful way to simulate customers standing in line E. Entries are removed from the front of the queue

B, D, E, F

Which of the following are true about tail recursion? A. The Fibonacci algorithm in 7.37 is an example of tail recursion. B. Some programming languages automatically convert tail recursive methods into iterative methods. C. Replacing tail recursion with iteration is a good way to improve execution time. D. Replacing tail recursion with iteration is a good way to improve memory usage. E. Tail recursive methods can typically be converted to iterative methods. F. Tail recursion occurs when the last action performed by a recursive method is a recursive call.

A, B, D

Which of the following are true about the Radix Sort algorithm A. Its efficiency is O(n) B. Given strings of equal length to sort, it will generally outperform quick sort. C. Given any data to sort, it will generally outperform quick sort. D. The algorithm involves first grouping the data based on the last character in the data.

A, B, C

Which of the following are true about the Shell Sort algorithm? A. It uses some of the main ideas from insertion sort. B. The worst-case behavior for shell sort is better than for insertion sort and selection sort. C. It is named shell sort because Shell is the name of the person who invented the algorithm. D. No answer text provided.

A, B, D,

Which of the following are true about the insertion sort algorithm A. It is more efficient on data that is already mostly sorted. B. In the best case, it is O(n) C. It is generally more efficient than bubble sort. D. In the worst case, it is O(n^2). E. The algorithm involves making multiple side-by-side comparisons for each pass.

B, C

Which of the following are true about the queue interface as described in the Java API documentation of java.util.queue()? A. The offer method will throw an exception if there is no room to add an element. B. remove and poll both will remove an element from the front of the queue if one exists C. The remove method is essentially the same as the dequeue method described in the text. D. peek will throw an exception if the queue is empty.

B, D

Which of the following are true about the queue interface as described in your text? A. isEmpty will throw an exception if the queue is empty B. There is a method that will look at the front element of the queue without removing it from the queue C. The method that removes the front element is called enqueue D. dequeue will throw an exception if the line is empty E. There is a method that returns the size of the queue

B, C, D, E

Which of the following are true about the quick sort algorithm? A. Quick sort performs roughly the same, regardless of how the pivot is selected. B. It involves selecting a pivot and then grouping the rest of the array based on how they compare to the pivot. C. The worst case is O(n^2) D. It is sometimes used by Java's Arrays.sort() method. E. The average case is O(n log n)

A, B, D

Which of the following are true about the selection sort algorithm? A. It is the algorithm used by the boy in the sorting algorithm video http://csunplugged.org/sorting-algorithms/ B. In the worst case, it is O(n^2) C. In the best case, it is O(n) D. It involves selecting the smallest element and swapping it to the beginning of the array E. It is more efficient on data that is already mostly sorted.

B, D, E, G, H, I, J

Which of the following are true about the tree shown in figure 23-5 of your text? A. K and L are siblings B. N and P are siblings C. S is a child of A D. D has 7 descendants E. G is a descendant of A F. The height of the tree is 3 G. There are 11 leaves H. D has three children I. A is an ancestor of T J. H is a leaf

D

Which of the following best describes the complexity of the recursive Fibonacci algorithm given in section 7.37? A. O(n^2) B. O(n) C. O(n!) D. O(2^n) E. O(log n)

A, B

Which of these would benefit from an ensureCapacity() method? A. An array-based implementation of stack B. An array-based implementation of queue C. A link-based implementation of queue D. A link-based implementation of stack

preorder traversal

visits a node before visiting either of its subtrees

inorder traversal

visits a node's left subtree, and then the node itself, and then the node's right subtree

postorder traversal

visits a nodes left subtree and right subtree before visiting the node itself

level order traversal

visits all the nodes in a level, from left to right, before moving on to the nodes in the next level


Kaugnay na mga set ng pag-aaral

Menedzsment kvantitatív módszerei

View Set

Exam #2 Macroeconomics Chapter 8

View Set

Chapter 14: Monopoly and Antitrust Policy

View Set

LEED Green Associate v4: Integrative Strategies

View Set

AP Gov. Unit 3 Practice Questions vg

View Set