CS 2420 - Post-Midterm Exam 2 Material

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

A. 10,000

17 - Quiz For radix sort of 10,000 integers with values 1 to 1,000,000. Which best describes the running time? A. 10,000 B. 1,000,000 C. 10,000,000,000

Double rotation handles "inside" cases: • insertion in right subtree of left child • insertion in left subtree of right child

Double rotation handles "inside" cases: • insertion in _____ • insertion in _____

B. percolate down only

Heapsort uses which of the following? A. percolate up only B. percolate down only C. both percolate up and percolate down D. neither percolate up and percolate down

B. The Big-O behavior is better for a binary heap.

How does the average-case running time of insertion in a binary heap compare to that of a binary search tree? A. The Big-O behavior is the same for both. B. The Big-O behavior is better for a binary heap. C. The Big-O behavior is better for a binary search tree.

A. The Big-O behavior is the same for both.

How does the worst-case running time of insertion in a binary heap compare to that of a balanced binary search tree? A. The Big-O behavior is the same for both. B. The Big-O behavior is better for a binary heap. C. The Big-O behavior is better for a binary search tree.

3

How many (unique) non-terminals are in the grammar above?

2

How many (unique) terminals are in the grammar above?

5

How many production rules are in the grammar above?

0

How many swaps are necessary to restore the heap-order property when executing insert(R)?

2

How many swaps are necessary to restore the heap-order property when executing insert(V)?

No

Is Shellsort stable?

A. Yes

Is this a binary max heap? A. Yes B. No

B. No The key in (R) in the parent of the node containing Q is not smaller, since R comes after Q.

Is this a binary min heap? A. Yes B. No

Pigeonhole sort is impractical for ranges that are much larger than the number of list items N. • If range < N, cost is O(N). • If range ≈ N, cost is O(N). • If range >> N, cost is O(range).

Pigeonhole sort is impractical for ranges that are much _____ than the number of list items N. • If range < N, cost is O(___).././. • If range ≈ N, cost is O(___). • If range >> N, cost is O(___).

Radix sort is a bucket sort in which each bucket corresponds to the rightmost digit of the key. The bucket sort is then repeated for the next digit, and the next, until reaching the leftmost digit.

Radix sort is a bucket sort in which each bucket corresponds to __________. The bucket sort is then repeated for the __________.

E. 100,000

Suppose a list of 100 integer keys has a minimum value of 500 and a maximum value of 100,500. Which of the following best describes the running time of a counting sort on the list? A. 100 B. 500 C. 1,000 D. 10,000 E. 100,000

1234 54 4 404 774 1233 1234

Suppose that we are using radix sort to order the following array of ten integers: 1234 54 0 12 4 40 1233 404 3 774 Give the contents of the bucket corresponding to digit 4 after the first iteration of radix sort, in the order maintained by the sort. __________ Give the contents of the bucket corresponding to digit 3 after the second iteration of radix sort, in the order maintained by the sort. __________

101 In counting sort, the length of the C array is the range of keys to be sorted since C[i - minKey] is used to count the number of elements in the original array, where the key is equal to i. There are 101 keys (integers) between 1900 and 2000.

Suppose that we must sort an array of 100,000 integers, where the minimum integer is 1900 and the maximum integer is 2000. When using the counting sort algorithm, what is the length of the C array?

D. return arg1.compareTo(arg0);

Suppose that you define the reverse comparator in this following way: The body of the compare method must be which of the following statements? A. return arg0 - arg1; B. return arg1 - arg0; C. return arg0.compareTo(arg1); D. return arg1.compareTo(arg0); E. return compare(arg0, arg1); F. return compare(arg1, arg0);

The first self-balancing binary search trees are AVL trees.

The first self-balancing binary search trees are ___ trees.

False Regardless of balance, the tree is not a BST.

The following binary tree is an AVL tree: True False

True

The following binary tree is an AVL tree: True False

B. 2 10 21 35 11 21 500

1 - Quiz Which shows the ordering of items as they would be in the implicit (array) representation? A. 2 10 11 21 21 35 500 B. 2 10 21 35 11 21 500 C. 500 21 11 35 21 10 2 D. 500 35 21 21 11 10 2

A. merge sort

10 - Quiz Which of the following sorting algorithms is stable? A. merge sort B. quicksort C. heapsort D. None of these sorts is stable.

C. The relative ordering of equal keys may be disrupted.

11 - Quiz Suppose that a list of key-value maps is sorted using an unstable algorithm. A. The relative ordering of equal keys will be disrupted. B. The relative ordering of equal keys will not be disrupted. C. The relative ordering of equal keys may be disrupted.

True

12 - True or false It is possible to choose one example list to "prove" that a sorting algorithm is not stable. True False

False

13 - True or false It is possible to choose one example list to "prove" that a sorting algorithm is stable. True False

False

14 - True or false The running time of pigeonhole sort depends on the ordering of items in the list to be sorted. True False

C. 10,000

15 - Quiz A list of 10,000 integer keys has min value of 500 and max value of 600, which best describes pigeonhole sort run-time? A. 100 B. 500 C. 10,000 D. 100,000

D. 100,000

16 - Quiz A list of 10,000 integer keys has min of 500 and max of 100,500, which best describes pigeonhole sort run-time? A. 500 B. 1,000 C. 10,000 D. 100,000

D. None has a better average growth rate in doubly-linked.

19 - Quiz Which operation has a better average growth rate in a doubly-linked list than singly-linked? A. adding a new "first" item B. searching for an item C. removing an item D. None has a better average growth rate in doubly-linked.

A. Yes, a binary MIN heap

2 - Quiz Is this tree a binary heap? A. Yes, a binary MIN heap B. Yes, a binary MAX heap C. Yes, a binary MIN-MAX heap D. No

C. jobN jobR jobT jobJ jobC

20 - Quiz Which is NOT a valid topological sort of the vertices? A. jobN jobT jobJ jobR jobC B. jobN jobT jobR jobJ jobC C. jobN jobR jobT jobJ jobC D. All are valid.

A. preorder

21 - Quiz Which traversal prints: 50 37 14 20 17 49 99 89? A. preorder B. inorder C. postorder D. level order

True

22 - True or False This implicit array representation is a valid min-max heap: [ 2, 2, 2, 2, 2, 2 ]. True False

True

23 - True or False This implicit array representation is a valid min heap: [ 1, 2, 9, 3, 2, 11, 10, 5, 6, 7, 4 ]. True False

C. 14

24 - Quiz What is the item in the deepest unbalanced node? A. 50 B. 37 C. 14 D. 20

C. Complete binary tree

25 - Quiz Which is a tree whose height is at most logN and in which every node with a right child must also have a left child? A. Binary trie B. Binary search tree C. Complete binary tree D. AVL tree

B. Hash table

26 - Quiz Which of these data structures does not yield an efficient sort? A. Binary search tree B. Hash table C. Binary heap D. All yield an efficient sorting algorithm

D. current.next = new Node(x, current.next);

27 - Quiz In a singly-linked list, which inserts a new node with item x after the node referenced by current? A. current = new Node(x, current); B. current = new Node(x, current.next); C. current.next = new Node(x, current); D. current.next = new Node(x, current.next);

B. 2L - 1

28 - Quiz What is the minimum number of nodes in a binary tree with L leaves? A. log L B. 2L - 1 C. 2L D. 2^L

C. binary min heap

3 - Quiz For which data structure is finding the minimum always O(1)? A. binary search tree B. balanced binary search tree C. binary min heap D. binary max heap

Algorithm: 1. Create an auxiliary array of empty "pigeonholes" (one pigeonhole for each key in the range of the original array). 2. Iterate through the original array, putting each item into the pigeonhole corresponding to its key. 3. Iterate over the pigeonhole array in order, putting items from non-empty pigeonholes back into the original array.

3-step algorithm for Pigeonhole sort.

B. 2

4 - Quiz How many non-terminals are in this grammar? A. 1 B. 2 C. 3 D. 4

Algorithm: 1. Set up an array of ten initially empty buckets. 2. Iterate through original array, putting each item in its bucket. least significant digit (LSD) = key % 10 3. Visit the buckets in order and put items back the original array. 4. Repeat 1-3 for every other digit in the keys.

4-step algorithm for Radix sort.

General algorithm: 1. Set up an array of initially empty buckets. 2. Iterate through unsorted array, putting each item in its bucket. 3. Sort each non-empty bucket. 4. Visit the buckets in order and put items in sorted array.

4-step general algorithm for Bucket sort.

B. 2

5 - Quiz How many terminals are in this grammar? A. 1 B. 2 C. 3 D. 4

D. 4

6 - Quiz How many production rules are in this grammar? A. 1 B. 2 C. 3 D. 4

A. aba

7 - Quiz Which of the following sentences can be derived? A. aba B. abba C. aabbaa D. All three sentences can be derived.

D. None of these choices.

8 - Quiz In main, what is the value of args[3]? A. 2 B. 3 C. 4 D. None of these choices.

B. insertion sort

9 - Quiz Which of the following sorting algorithms is stable? A. selection sort B. insertion sort C. Shell sort D. None of these sorts is stable.

B. False Like for Assignment 3, isolate code that compares two elements to a single helper method. (Such code must check whether to use Comparable or Comparator, potentially cast to Comparator, and finally call compareTo or compare.) Do not replicate this code throughout the class.

A BinaryMaxHeap class with two blocks of code for add, one for Comparable and one for Comparator is a good design and easy to read. A. True B. False

A complete binary tree is completely filled, with the possible exception of the bottom level (filled left to right). • The height of an N-node tree is at most log N.

A complete binary tree is completely filled, with the possible exception of the ___ level (filled ___ to ___). • The height of an N-node tree is at most ___.

A stable sorting algorithm maintains the relative order of items with equal keys.

A stable sorting algorithm maintains the _____.

E. "1"

A. "java" B. "MyProgram" C. "hello" D. 1 E. "1" F. "world" G. 2 H. "2"

B. An ArrayIndexOutOfBoundsException occurs.

A. The code does not compile. B. An ArrayIndexOutOfBoundsException occurs. C. A message is displayed asking the user to check the command line and try again. D. The program properly writes to each other three files.

Abstract data types: • List • Stack • Queue (FIFO) • Priority queue • Map Data structures: • Array • Linked list • Graph (adjacency lists or adjacency matrix) • Binary search tree • Hash table (linear probing, quadratic probing, or separate chaining) • Binary heap

Abstract data types: ____ ____ ____ Data structures: ____ ____ ____ options: Hash table (linear probing, quadratic probing, or separate chaining), List, Stack, Binary search tree, Binary heap, Linked list, Queue (FIFO), Priority queue, Map, Array, Graph (adjacency lists or adjacency matrix)

abstract data type (ADT) data structure

An _____ is defined in terms of its behavior (i.e., possible values and operations) from the point of view of the user. This is in contrast to a _____, which is a concrete representation of data from the point of view of the implementer.

False

An unsorted array can be sorted in linear time, using the buildHeap operation. True False

B. [5] The root's left child (X) is at 2*1 = 2. The node containing R (a right child) is at 2*2 +1 = 5. Alternatively, count from top to bottom, left to right.

Assuming the root is at [1], where is R stored? A. [4] B. [5] C. [6] D. None of the above

insert - percolate up delete - percolate down buildHeap- percolate down

Binary heap: insert - percolate _____ delete - percolate _____ buildHeap - percolate _____

A. binary min heap

By default, is Java's PriorityQueue a binary min heap or a binary max heap? A. binary min heap B. binary max heap

deepest unbalanced node - 56 kind of rotation - double

Consider inserting 59 into the following AVL tree. Rebalancing must occur. The deepest unbalanced node contains which integer? Which kind of rotation is needed to restore balance?

B. logarithmic

Consider the operation of inserting an arbitrary item in a self-balancing BST (e.g., AVL tree, red-black tree). What is the growth rate of this operation in the average and worst cases? A. constant B. logarithmic C. linear D. N log N E. quadratic

B. logarithmic

Consider the operation of searching for an arbitrary item in a self-balancing BST (e.g., AVL tree, red-black tree). What is the growth rate of this operation in the average and worst cases? A. constant B. logarithmic C. linear D. N log N E. quadratic

Input: unsorted array A with integer keys N = number of items Find the min and max keys in A. O(N) Compute the range R. O(1) Create a new integer array C of size R, and set all C[i] to 0. O(R) For each key in A, update the appropriate counter in C (i.e., C [ key(A[i]) - min ]). O(N) Accumulate the counts in C. I,e., add the value at C[i-1] to value at C[i]. O(R) Fill in a new sorted array S, backwards. O(N) >>>>>Each A[i] is copied to S [C [ key(A[i]) - min ] ]. >>>>>To ensure that duplicate keys in A get their own cell, decrement C [ key(A[i]) - min ] before each copy. Output: sorted array S Total cost: O(N+R)

Counting sort algorithm with the cost per each step.

<start> → <a><b> <start> → <b> <a> → aa <a> → aa<a> <b> → b <b> → bb<b>

Create a grammar for these phrases: an even number of a's followed by an odd number of b's (recall: 0 is even)

A. 0 C. 20 to 24 bytes Compressed file: • encoding info = (1 byte to store char + 4 bytes to store integer weight) * 4 unique characters = 20 bytes • encoded characters 100 11 0 0 11 0 0 11 101 101 11 = 21 bits / 8 = 3 bytes B. original file is smaller The original file has 11 characters, which is 11 bytes. The compressed file is 20+3 = 23 bytes.

Draw the Huffman tree for file: mississippi What is the binary encoding for 's' using the tree? A. 0 B. 1 C. 00 D. 11 E. none of the above About how many bytes are required to store the compressed file? A. 3 bytes or less B. 10 to 15 bytes C. 20 to 24 bytes D. more than 30 bytes E. none of the above How does the size of the compressed file compare to the original file? A. compressed file is smaller B. original file is smaller C. both files are about the same size

A. True E.g., F's code of 1 is not the beginning of any other character's code. Therefore, when consuming the encoding of the next character in a compressed file, if we read 1, it is for certain the code for F and not the case that we should continue reading bits to see if it is the code for another character.

Each character has a unique encoding prefix, and it is not possible to confuse one character's entire encoding with the beginning of another's. A. True B. False

A. It is the number of times the character occurs in the original file.

Each leaf node in the Huffman tree contains a character from the original file to be compressed, as well as an integer. What is the significance of the integer (called the "weight" of this character)? A. It is the number of times the character occurs in the original file. B. It is the ASCII code for the character. C. None of the above. D. It is the position of the character in the original file.

B. It is the sum of the weights in its child nodes.

Each non-leaf (i.e., internal) node in the Huffman tree contains just an integer. What is the significance of the integer? A. It is the number of characters in the compressed file. B. It is the sum of the weights in its child nodes. C. It is the depth of the node. D. None of the above.

A. push in front of the first element, pop the first element

For a singly-linked list implementation of the stack, where are the pushes and pops performed? A. push in front of the first element, pop the first element B. push after the last element, pop the last element . push after the last element, pop the first element D. push in front of the first element, pop the last element E. push after the first element, pop the first element

B. even

For any node X at __________ depth in a min-max heap, the key stored at X is the minimum of its subtree. A. odd B. even C. any D. power-of-two

1100

Given the following binary trie of some common English prepositions, what is the binary encoding for by? Provide the exact binary string with no extra spaces or punctuation.

Heap operations lead to a O(NlogN) sorting algorithm.

Heap operations lead to a O(_____) sorting algorithm.

A. A distance of infinity is reported.

If a shortest path algorithm (BFS or Dijkstra's) is run and a vertex is not reachable from the starting point, what happens? A. A distance of infinity is reported. B. A distance of -1 is reported. C. A distance of zero is reported. D. The algorithm enters an infinite loop. E. The algorithm's results are undefined.

C. O(N)

If two elements of a sorted array are swapped, how much time will it take to sort the array again using insertion sort? A. O(1) B. O(logN) C. O(N) D. O(NlogN) E. O(N2)

C. 1.25

In a separate chaining hash table with load factor λ = 1.25 , what is the average length of a list? A. 0.8 B. 1.0 C. 1.25 D. none of the above

True

In general, there is more than one possible binary min heap for a set of items, depending on the order of insertion. True False

In practice, heapsort is slower than mergesort and quicksort, but is much easier to implement.

In practice, heapsort is _____ than mergesort and quicksort, but is much easier to implement.

B. 5 is the only possible output

In the method below, which statement about the possible outputs is correct? A. 0 is a possible output B. 5 is the only possible output C. Any integer is a possible output D. None of the above

C. postorder

In which of the following traversals is the node processed after the recursive calls to the children are complete? A. inorder B. level order C. postorder D. preorder E. none of the above

Use an array, kept in sorted order • cost of insert: O(N) • cost of findMin: O(1) • cost of deleteMin: O(1) Use an array, kept in unsorted order. • cost of insert: O(1) • cost of findMin: O(N) • cost of deleteMin: O(N) Use a (balanced) BST. • cost of insert: O(logN) • cost of findMin: O(logN) • cost of deleteMin: O(logN) Use a binary heap. • cost of insert: O(1) average case, O(logN) worst case • cost of findMin: O(1) average and worst cases • cost of deleteMin: O(logN) average and worst cases

Insert Big-O behaviors for each operation. Use an array, kept in sorted order • cost of insert: ___ • cost of findMin: ___ • cost of deleteMin: ___ Use an array, kept in unsorted order. • cost of insert: ___ • cost of findMin: ___ • cost of deleteMin: ___ Use a (balanced) BST. • cost of insert: ___ • cost of findMin: ___ • cost of deleteMin: ___ Use a binary heap. • cost of insert: ___ average case, ___ worst case • cost of findMin: ___ average and worst cases • cost of deleteMin: ___ average and worst cases

Index 1: 7 Index 2: 36 Index 3: 10 Index 4: 50 Index 5: 44 Index 6: 25

Insert the following integers, one at a time and in the order given, to a binary min heap. (Do not use the buildHeap operation.) 50, 10, 25, 44, 36, 7 The integer items are stored in a basic array, according to the implicit representation presented in the lecture videos. Assume that the root item is stored at index 1. To indicate the state of the binary min heap after all items have been inserted, fill in the blank by providing the integer item stored at each array index. Index 1: Index 2: Index 3: Index 4: Index 5: Index 6:

A. Yes Just one example list that when sorted by the algorithm has entries with duplicate keys reordered proves the algorithm is not stable.

Is it possible to choose one example list to "prove" that a sorting algorithm is not stable? A. Yes B. No

B. No Sorting algorithms that are not stable are not guaranteed to reorder entries with equal keys. An example list for which the relative ordering of entries with duplicate keys are maintained could have been sorted by a stable or not stable algorithm.

Is it possible to choose one example list to "prove" that a sorting algorithm is stable? A. Yes B. No

No

Is it valid to derive 1 = z; ?

Yes

Is it valid to derive x = y + z + 2; ?

D. No, the node containing 15 is the deepest unbalanced.

Is the following binary search tree an AVL tree? If not, which node is the deepest unbalanced? A. Yes, it is an AVL tree. B. No, the node containing 13 is the deepest unbalanced. C. No, the node containing 14 is the deepest unbalanced. D. No, the node containing 15 is the deepest unbalanced. E. No, the node containing 16 is the deepest unbalanced.

Min-heap order property: For every node X with parent node P, the key in P is "smaller than or equal to" the key in X.

Min-heap order property: For every node X with parent node P, the key in P is "____ than or equal to" the key in X.

Pigeonhole sort is a bucket sort that uses one bucket for each possible key value. (aka count sort)

Pigeonhole sort is a bucket sort that uses __________. (aka count sort)

True

Plotting running times with O(1) behavior can be tricky, due to the natural oscillation of very small running times. Another option for verifying that the running times you have collected exhibit the expected growth rate is to show that the running times are not steadily increasing as N increases. True False

The running time is O(kN), where k = number of digits.

Running time of Radix sort.

A. complete binary tree D. binary min-max heap

Select all that apply for this tree: A. complete binary tree B. binary max heap C. binary min heap D. binary min-max heap E. binary search tree F. balanced binary search tree

Single rotation handles "outside" cases: • insertion in left subtree of left child • insertion in right subtree of right child

Single rotation handles "outside" cases: • insertion in _____ • insertion in _____

D. 10,000 The running-time behavior of pigeonhole sort depends on both the size of the list (N) and its range of values (R). O(N + R)

Suppose a list of 10,000 integer keys has a minimum value of 500 and a maximum value of 600. Which of the following best describes the running time of a pigeonhole sort on the list? A. 100 B. 500 C. 1,000 D. 10,000 E. 100,000

E. 100,000 The running-time behavior of pigeonhole sort depends on both the size of the list (N) and its range of values (R). O(N + R)

Suppose a list of 100 integer keys has a minimum value of 500 and a maximum value of 100,500. Which of the following best describes the running time of a pigeonhole sort on the list? A. 100 B. 500 C. 1,000 D. 10,000 E. 100,000

3

Suppose that an item X is stored at index 7 in the array that backs a binary min heap. At which index is X's parent stored? (Assume that the root item is stored at index 1.)

3

Suppose that insert(3) is called for the following binary min heap. What index of the backing array does the newly-inserted integer 3 occupy when the method returns? Assume that the contents of the root node are stored at index 1.

A. The sorting algorithm used may be selection sort. D. The sorting algorithm used may be quicksort. E. The sorting algorithm used may be heapsort.

Suppose that we have the following list of key-value pairs, where the name of a city is the key and an area code is the value: ("Tulsa", 981), ("Atlanta", 678), ("Houston", 281), ("Baltimore", 410), ("Salt Lake City", 385), ("Atlanta", 404), ("Denver", 720), ("New York City", 347), ("Salt Lake City", 801) After sorting by key, we get the following version of the list: ("Atlanta", 404), ("Atlanta", 678), ("Baltimore", 410), ("Denver", 720), ("Houston", 281), ("New York City", 347), ("Salt Lake City", 385), ("Salt Lake City", 801), ("Tulsa", 981) Which of the following statements is true? (Select all that apply.) A. The sorting algorithm used may be selection sort. B. The sorting algorithm used may be insertion sort. C. The sorting algorithm used may be merge sort. D. The sorting algorithm used may be quicksort. E. The sorting algorithm used may be heapsort.

A. The sorting algorithm used may be selection sort. B. The sorting algorithm used may be insertion sort. C. The sorting algorithm used may be merge sort. D. The sorting algorithm used may be quicksort. E. The sorting algorithm used may be heapsort.

Suppose that we have the following list of key-value pairs, where the name of a city is the key and an area code is the value: ("Tulsa", 981), ("Atlanta", 678), ("Houston", 281), ("Baltimore", 410), ("Salt Lake City", 385), ("Atlanta", 404), ("Denver", 720), ("New York City", 347), ("Salt Lake City", 801) After sorting by key, we get the following version of the list: ("Atlanta", 678), ("Atlanta", 404), ("Baltimore", 410), ("Denver", 720), ("Houston", 281), ("New York City", 347), ("Salt Lake City", 385), ("Salt Lake City", 801), ("Tulsa", 981) Which of the following statements is true? (Select all that apply.) A. The sorting algorithm used may be selection sort. B. The sorting algorithm used may be insertion sort. C. The sorting algorithm used may be merge sort. D. The sorting algorithm used may be quicksort. E. The sorting algorithm used may be heapsort.

Both Shellsort and quicksort are "in place" sorting algorithms, requiring only the original array of length 100,000 in terms of memory. Merge sort requires an array of length 100,000 (for the merge step), in addition to the original array of length 100,000 in terms of memory. Pigeonhole sort requires an array of length 300,000 (for the pigeonholes), in addition to the original array of length 100,000 in terms of memory.

Suppose that we must sort an array of 100,000 integers, where the minimum integer is -99,999 and the maximum integer is 200,000. Which of the following sorting algorithms requires the most space / memory? A. Shellsort B. merge sort C. quicksort D. pigeonhole sort E. All of the sorting algorithm choices require the same amount of space / memory.

D. 3 Place D in the hole created at the root. Percolate down: swap D with X (the max of X and P), swap D with R (the max of C and R), swap D with N (the max of L and N).

Suppose we execute deleteMax(), how many swaps are needed to percolate down? A. 0 B. 1 C. 2 D. 3

C. [6] A new node containing M is placed at the node containing E's right child. Percolate up swaps E and M. (Percolation then terminates since P is larger than M.)

Suppose we execute insert(M), at what index is M at completion? A. [4] B. [5] C. [6] D. None of the above

C. The code compiles and runs without error. Like in Assignment 3, the constructor of BinaryMaxHeap is overloaded to accept a Comparator instance, which is satisfied by the lambda expression above. When the constructors without Comparator are used, the generic type is assumed to be (and casted to) Comparable.

Suppose we try to use the BinaryMaxHeap class in the way given below. What happens? A. The code does not compile. B. A runtime exception occurs. C. The code compiles and runs without error

B. False It is called "Bad" because it should result in a lot of collisions — leading to worse than O(1) behavior for typically efficient hash table operations (e.g., put, containsKey, remove).

The StudentBadHash class is called "Bad" because it contains a hashCode method that is an invalid / incorrect implementation of a hash function. A. True B. False

The first two steps are O(N), the last step is O(NlogN).

The binary heap can be used to sort N items. 1. Add each item into a binary heap without regard to order. 2. Apply buildHeap(). 3. Call deleteMin() N times. The items exiting the heap are in sorted order. The first two steps are _____, the last step is _____.

False

The counting sort algorithm cannot handle duplicate keys. True False

The key for Radix sort must either be an integer or reducible to an integer (e.g., a character).

The key for Radix sort must either be an _____ or _____.

True

The min-max heap has the same structure property as the min heap. True False

A. minimum

Unless explicitly stated, highest priority ≡ _____. A. minimum B. maximum

C. The methods are about the same. If k is almost as large as N, then the the O(k*logN + N) behavior of findKLargestHeap becomes O(N log N), which is the same as the behavior of findKLargestSort.

What do you expect if N is very large and k is almost as large as N? A. findKLargestSort is fastest. B. findKLargestHeap is fastest. C. The methods are about the same.

B. findKLargestHeap is fastest. If k is a small constant and N is very large, then the N term dominates O(k*logN + N) behavior of findKLargestHeap to make it O(N). This is a better growth rate than O(N log N) for findKLargestSort.

What do you expect if k is a small constant and N is very large? A. findKLargestSort is fastest. B. findKLargestHeap is fastest. C. The methods are about the same.

B. O(N)

What do you think is the lower bound on the average running time of any sorting algorithm? A. O(log N) B. O(N) C. O(N log N) D. O(N2) E. O(N3)

D. O(N + k log N)

What is the behavior of finding the k smallest items in a collection of size N using the binary heap option? A. O(N) B. O(k + N) C. O(k log N) D. O(N + k log N) E. O(N log N)

E. O(N log N)

What is the behavior of finding the k smallest items in a collection of size N using the quicksort option? A. O(N) B. O(k + N) C. O(k log N) D. O(N + k log N) E. O(N log N)

A. O(1)

What is the behavior of insert for a binary heap, in the average case? A. O(1) B. O(log N) C. O(N) D. O(N log N)

B. O(log N)

What is the behavior of insert for a binary heap, in the worst case? A. O(1) B. O(log N) C. O(N) D. O(N log N)

C. 101

What is the encoding for character 'O' in this binary trie? A. 00 B. 11 C. 101 D. 010 E. 110

C. O(N log N)

What is the lower bound on the average running time of any sorting algorithm that compares items? A. O(log N) B. O(N) C. O(N log N) D. O(N2) E. O(N3)

C. O(k*log N + N) This method for finding the k largest items uses buildHeap to construct the binary max heap, O(N), and then calls extractMax k times, O(k*logN).

What is the run-time behavior of findKLargestHeap(list, k) for a list of size N and k ≤ N? A. O(log N) B. O(N) C. O(N log N) D. O(N2) E. O(N3)

C. O(N log N) This method for finding the k largest items is dominated by the sorting algorithm, which is O(N log N).

What is the run-time behavior of findKLargestSort(list, k) for a list of size N and k ≤ N? A. O(log N) B. O(N) C. O(N log N) D. O(N2) E. O(N3)

O(logN)

What is the run-time behavior of findMin() for a balanced binary search tree? A. O(1) B. O(log N) C. O(N) D. O(N log N) E. O(N2)

B. O(N) In a binary max heap, the minimum item may be at any leaf node. In a complete binary tree with N nodes, ⌈N/2⌉ of them are leaf nodes.

What is the run-time behavior of findMin() for a binary max heap? A. O(1) B. O(log N) C. O(N) D. O(N log N) E. O(N2)

A. O(1)

What is the run-time behavior of findMin() for a binary min heap? A. O(1) B. O(log N) C. O(N) D. O(N log N) E. O(N2)

A. O(1) On average, percolation terminates early after only a few swaps up the tree. This is because the majority of the nodes in a complete binary tree are in the bottom few rows, and it is most likely that is where the newly-inserted node belongs.

What is the run-time behavior of insert(x) for a binary heap, in the average case? A. O(1) B. O(log N) C. O(N) D. O(N log N) E. O(N2)

B. O(log N) In the worst case, percolation goes from a leaf node all the way up to the root node.

What is the run-time behavior of insert(x) for a binary heap, in the worst case? A. O(1) B. O(log N) C. O(N) D. O(N log N) E. O(N2)

B. O(N) The constructors that take a list of elements with which to initialize the heap must use the buildHeap operation, which efficiently establishes the structure and order property of the heap in O(N) time

What is the run-time behavior of the following snippet of code, in the worst case? A. O(log N) B. O(N) C. O(N log N) D. O(N2)

C. O(N log N) In the worst case, the add method is O(logN) and it is being called N times

What is the run-time behavior of the following snippet of code, in the worst case? A. O(log N) B. O(N) C. O(N log N) D. O(N2)

C. O(N4)

What is the running time of the following program fragment? A. O(N2) B. O(N3) C. O(N4) D. O(N5) E. None of the above

C. null If a key does not previously exist in the table, put returns null.

What is the value of x? A. "0" B. "12345678" C. null D. "Alan Turing" E. none of the above

C. "Alan Turing" If a key does previously exist in the table, put returns the previously mapped value.

What is the value of x? A. "12345678" B. null C. "Alan Turing" D. "Sir Alan Turing" E. none of the above

C. null If a key does exist in the table, remove returns null.

What is the value of x? A. "0" B. "12345678" C. null D. "Alan Turing" E. none of the above

D. "Alan Turing" If a key exists in the table, remove returns the mapped value.

What is the value of x? A. "0" B. "12345678" C. null D. "Alan Turing" E. none of the above

A. O(1)

What would be the running time for merging two doubly-linked lists (each size N) into one doubly-linked list? A. O(1) B. O(logN) C. O(N) D. O(NlogN) E. O(N2)

First, satisfy structure property. Second, satisfy order property.

When inserting a new item to a binary heap: First, satisfy _____ property. Second, satisfy _____ property. options: order, structure

C. F The objective of Huffman's algorithm is shorter encodings for more frequently occurring characters.

Which character is the most frequently occurring character (or at least tied for the most)? A. C B. E C. F D. O

A. Array

Which is best if access of an arbitrary item is the most frequent operation? A. Array B. Linked list C. Stack D. Queue (FIFO) E. Binary heap

E. Binary heap

Which is best if accesses are limited to the minimum item? A. Stack B. Queue (FIFO) C. Hash table D. Binary search tree E. Binary heap

A. Stack

Which is best if accesses are limited to the most-recently inserted item? A. Stack B. Queue (FIFO) C. Hash table D. Binary search tree E. Binary heap

D. Hash table

Which is best if duplicates are not permitted? A. Array B. Linked list C. Graph D. Hash table E. Binary heap

B. Graph

Which is best if each item has the potential to be connected to other items? A. Stack B. Graph C. Hash table D. Binary search tree E. Binary heap

D. Binary search tree

Which is best if finding a range of items (e.g. where x is between a and b) is required? A. Stack B. Linked list C. Hash table D. Binary search tree E. Binary heap

B. Linked list

Which is best if the number of items is expected to increase and decrease frequently? A. Array B. Linked list C. Stack D. Queue (FIFO) E. Binary heap

B. containsValue(V value) With no key to hash, every cell of the backing array must be examined (until the value is found or the end of the array is reached).

Which method is O(table length) for a quadratic probing hash table? A. containsKey(K key) B. containsValue(V value) C. isEmpty() D. none of the above

A. basic array B. binary heap C. self-balancing binary search tree

Which of the following data structures can be used to implement the priority queue abstract data type? (Select all that apply.) A. basic array B. binary heap C. self-balancing binary search tree

B. insertion sort D. merge sort G. radix sort H. counting sort

Which of the following is a stable sorting algorithm? (Select all that apply.) A. selection sort B. insertion sort C. Shellsort D. merge sort E. quicksort F. heapsort G. radix sort H. counting sort

D. A class that extends another class may implement only one interface.

Which of the following is false? A. An abstract class may implement an interface. B. A class that contains an abstract method must be declared abstract itself or a compiler message will result. C. A class may implement multiple interfaces. D. A class that extends another class may implement only one interface. E. An interface may extend another interface.

B. xy C. xxyy D. xxxxxxxyy

Which of the following sentences can be derived from the grammar above? (Select all that apply.) A. x B. xy C. xxyy D. xxxxxxxyy E. y F. yx G. yyyyyyyxxxx

D. all of the above All of these sorting algorithms can handle key-value pairs in which the key is an integer.

Which of these sorting algorithms can be used on the following list of key-value pairs? (-9, "cat"), (77, "dog"), (2, "apple"), (19, "bird"), (0, "mouse") A. pigeonhole sort B. merge sort C. heapsort D. all of the above

A. pigeonhole sort Pigeonhole sort, as well as radix and counting sort, require the keys to be integers.

Which of these sorting algorithms cannot be used on the following list of key-value pairs? ("cat", -9), ("dog", 77), ("apple", 2), ("bird", 19), ("mouse", 0) A. pigeonhole sort B. merge sort C. heapsort D. all of the above

We can achieve O(N) by applying percolate down to the nodes in reverse-level order.

buildHeap operation We can achieve O(N) by applying percolate _____ to the nodes in reverse-level order.


Set pelajaran terkait

2021 Private Pilot Test Prep (Ch 4 & 5, ALL & AIR ONLY)

View Set

Info Sec & Network Quiz Chapter 8

View Set

Nclex review: Pneumonia and Respiratory Meds

View Set

La formation des questions: Posez la question qui a pour réponse l'expression soulignée. Faites les deux versions (et avec "est-ce que", et avec inversion)

View Set

Unit 9 Life insurance underwriting and policy issue

View Set

6.15 Software-Defined Network (SDN)

View Set