Exam 2 CS 235 Study Guide

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

What is the maximum black-height of a Red-Black Tree with 7 nodes? a. 2 b. 3 c. 4 d. 7

a. 2

A map consists of a set of keys, each with one or more values. Which typically is/are unique? a. Both b. Neither c. The keys d. The values

c. The keys

A Red-Black tree may not be as balanced as an AVL tree for the same series of inputs. a. True b. False

a. True

To restore the AVL property after inserting a element, we start at the insertion point and move towards root of that tree. a. True b. False

a. True

Is it possible to have all black nodes in a Red-Black tree? a. Yes, with a complete tree of all black nodes. b. No, the root is always red. c. Yes, a red node always has black children. d. No, the number of black nodes is even.

a. Yes, with a complete tree of all black nodes.

If the size of a heap is n, the performance a. is O(log n) for insertion. b. is O(1) for deletion. c. is O(n) for deletion. d. is O(n2) for restructuring.

a. is O(log n) for insertion.

Suppose set A contains the strings "apples", "oranges", and "pineapples". Then the strings "apples" and "grapes" are inserted. How many items are in A after these two insertions? a. 3 b. 4 c. 5 d. No way to be sure

b. 4

What is true of shell and/or merge sorts? a. A merge sort is a stable sort. b. A merge sort is faster than a shell sort (on average). c. A shell sort is a stable sort. d. Merge and shell sorts sort in place.

a. A merge sort is a stable sort.

Let H(value) be a function that returns the hash code of "value". If A == B, then ________. a. H(A) == H(B) b. H(A) != H(B) c. H(A) may be equal to H(B), but it is not likely because it is random d. There is no known relation between H(A) and H(B).

a. H(A) == H(B)

What is the expected run time for inserting into a hash table? a. O(1) b. O(n c. O(log n) d. O(n*log n)

a. O(1)

Given an empty AVL tree, how could you populate the tree without performing any rotations? a. Build the tree with the given inputs. b. Recursively find the median of the set of elements, insert, and then construct left and right subtrees with elements less and greater than the median element. c. Sort set of data and insert in reverse order. d. Use trial and error.

b. Recursively find the median of the set of elements, insert, and then construct left and right subtrees with elements less and greater than the median element.

The merge step of merge sort depends on which of the following characteristics? a. The original array was of an even length. b. The subarrays are sorted. c. The two subarrays are relatively small. d. The two subarrays are the same size.

b. The subarrays are sorted.

While insertion sort is generally O(n2), it is ______. a. always O(n2). b. sometimes O(n) c. sometimes O(n*log n) d. sometimes O(n2*log n)

b. sometimes O(n)

How many different type of nodes are in a 2-3-4 tree (including internal and leaf nodes)? a. 3 b. 5 c. 4 d. 2

c. 4

Which of the following can help to reduce collisions in a hash table? a. Expanding the table size. b. Using quadratic probing instead of linear probing. c. A and B. d. None of the above.

c. A and B.

What types of maps would NOT be useful in a Huffman Code algorithm? a. A map of characters to ints, representing the frequencies of each character. b. A map of characters to strings, representing the encoding of each character. c. A map of strings to characters, representing the decodings of each string. d. All of the above are useful.

c. A map of strings to characters, representing the decodings of each string.

How does a 2-3 tree maintain balance? a. The root is always a 3-node. b. Through rotations if a new node ever causes an imbalance. c. All of its leaf nodes are at the lowest level. d. By always adding both children nodes at the same time.

c. All of its leaf nodes are at the lowest level.

When using a map to implement a phone directory, the ______ should be the key and the ______ should be the value. a. Hash code, name b. Hash code, phone number c. Name, phone number d. Phone number, name

c. Name, phone number

What do Red-Black trees, 2-3-4 trees, and AVL trees all have in common? a. They all are binary search trees. b. They all have binary search trees. c. They are all self balancing trees. d. They are all largely unused--binary search trees are superior.

c. They are all self balancing trees.

When collisions are resolved using linear probing, ______. a. infinite loops regularly result b. probing terminates not later than the end of the hash table c. the insertion occurs at the first available slot that was not previously occupied d. the insertion occurs at the first available slot, even it was previously occupied

c. the insertion occurs at the first available slot that was not previously occupied

Which of the following most accurately describes the shell sort algorithm? a. Shell sort is divide-and-conquer approach to bubble sort. b. Shell sort sorts one smaller subarray using insertion sort before sorting the entire array. c. After each subarray sort, a new subarray with approximately the same number of elements is sorted. d. The last step is to perform an insertion sort on the entire array, which has been presorted by the earlier sorts.

d. The last step is to perform an insertion sort on the entire array, which has been presorted by the earlier sorts.

What kind of mapping is used in a map from keys to values? a. one-to-many b. one-to-one c. many-to-many d. many-to-one

d. many-to-one

If you wanted to use a data structure to store a club roster (names only), which of the following should you use? a. either a map or a set, either is equally fine b. map c. neither a map nor a set will perform well here d. set

d. set

Quadratic probing a. avoids collisions in hash tables. b. sometimes results in an unresolvable infinite loop. c. supports clustering of hash table keys. d. uses a hash table of prime size and it is never more than half full.

d. uses a hash table of prime size and it is never more than half full.

Good hashing functions a. maximize the clustering of hash values that are consecutive in the probe order b. may require extensive and slow polynomial calculations. c. return the value associated with a given pair. d. will distribute the keys uniformly over the hash table buckets.

d. will distribute the keys uniformly over the hash table buckets.

__________ traversal doesn't exist. a. Preorder b. Postorder c. Inorder d. Outorder

d. Outorder

If a particular binary tree is full and has 100 leaf nodes, how many internal nodes does it have? a. 99 b. 100 c. 101 d. Not determinable.

a. 99

How can you verify that a list is sorted? a. Check each element in the list and make sure that it is not less than its predecessor. b. Check several random indices and ensure that they are in order. c. Verify that each position in the list has its index as its value (e.g. spot 0 in the array is 0). d. Any of the above.

a. Check each element in the list and make sure that it is not less than its predecessor.

In the left rotation pseudo code where the AVLnode contains left and right pointers, a height, and a Height() function that returns the height of a node. What is missing? AVLtree left_rotate(AVLnode x) { AVLnode w = x-right x-right = w-left w-left = x x-height = max(Height(x-left), Height(x-right)) + 1 w-height = max(????) + 1 return w }

a. Height(w-left), x-height b. x-height, Height(w-right) c. Height(w-left), x d. Height(w-left)

Suppose you have a binary search tree. Which kind of traversal would print the contents in increasing order? a. Inorder. b. Preorder. c. Postorder. d. It doesn't matter, all would work.

a. Inorder.

What is the best case performance of the quicksort algorithm? a. O(n) b. O(n2) c. O(n log n) d. O(log n)

a. O(n)

Which of the following most accurately describes the heap sort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Sorting the first element, and then adding items from the rest of the list recursively. c. Splitting the array evenly in half, and sorting the halves recursively. d. Splitting the array in halves based on size, and sorting the halves recursively.

a. Placing every item into a heap and moving the top item into the sorted list.

A binary tree's conceptual counterpart of a double-linked list ______. a. consists of links to children and parents: three links per node b. consists of links to left and right subtrees: two links per node c. consists of links to parents: one link per node d. does not exist

a. consists of links to children and parents: three links per node

With a heap, a. insertion traces a path from a leaf to the root. b. removal traces a path from the leaf to the root. c. the largest complete tree of height h has 2h nodes. d. the smallest full tree of height h has 2(h-1) nodes.

a. insertion traces a path from a leaf to the root.

Balance, in the context of AVL trees, refers to ___________. a. the difference between the heights of the right and left nodes b. the difference between the heights of the right node and the root node c. the difference between the number of nodes from the root to right and left nodes d. the difference between the number of nodes to the right and left of the node

a. the difference between the heights of the right and left nodes

When hashing, the "Big O" for find, insert, and erase should be ___, ____, and ____, respectively. a. log n, log n, log n b. 1, 1, 1 c. log n, 1, 1 d. 1, log n, log n

b. 1, 1, 1

What is the worst case possible height of AVL tree? a. 2 * log n b. 1.44 * log n c. O(n) d. Depends upon implementation.

b. 1.44 * log n

Set A has 10 members and set B has 14 members. The intersection of the two sets has 5 members. How many members are in the union of the two sets? a. 10 b. 19 c. 14 d. 24

b. 19

In this sequence, 11 4 20 45 32 60 98 70, which element seems to be the pivot? a. 4 b. 20 c. 70 d. 98

b. 20

If the number 5 is deleted from the above tree, what would be the level-order traversal order? a. 1 0 4 10 7 9 b. 4 1 10 0 7 9 c. 7 1 9 0 4 10 d. 9 1 10 0 4 9

b. 4 1 10 0 7 9

If the value 35 is inserted in the max-heap array {40, 30, 20, 10, 15, 16, 17, 8, 4}, the new heap is a. 40, 30, 20, 10, 15, 16, 17, 8, 4, 35 b. 40, 35, 20, 10, 30, 16, 17, 8, 4, 15 c. 40, 30, 20, 10, 35, 16, 17, 8, 4, 15 d. 40, 35, 20, 10, 15, 16, 17, 8, 4, 30

b. 40, 35, 20, 10, 30, 16, 17, 8, 4, 15

If the number 3 is inserted into the following binary tree, what would be the pre-order traversal order? .............5 .........../....\ .........1.........10 ....../ \...... / ......0 .4 ....7 ....................\ ......................9 a. 0 1 3 4 5 7 9 10 b. 5 1 0 4 3 10 7 9 c. 5 1 10 0 4 7 3 9 d. None of the above.

b. 5 1 0 4 3 10 7 9

Which of the following most accurately describes the bubble sort algorithm? a. Finding the largest chunk of the sorted list, and then sorting afterward. b. Gradually shifting larger items to the back of the array, or smaller items to the front. c. Picking the smallest item and moving it to the front of the list until the list is sorted. d. Placing each item into the correct position in the list one at a time, like a hand of cards.

b. Gradually shifting larger items to the back of the array, or smaller items to the front.

What is the worst case performance of bubble sort? a. O(n) b. O(n2) c. O(n3) d. O(n) exchanges, O(n2) comparisons

b. O(n2)

Which of the following most accurately describes the merge sort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Splitting the array evenly in half, and sorting the halves recursively. c. Splitting the array in halves based on size, and sorting the halves recursively. d. Sorting the first element, and then adding items from the rest of the list recursively.

b. Splitting the array evenly in half, and sorting the halves recursively.

What is the difference between sort and stable_sort? a. Stable_sort is less likely to crash your program. b. Stable_sort will preserve ordering of duplicate items. c. Stable_sort is slightly faster. d. They are identical.

b. Stable_sort will preserve ordering of duplicate items.

What is "chaining?" a. Keeping track of the locations visited by particular item in a hash table when finding collisions. b. Storing a linked list in each table entry that contains each value that hashes to the same location. c. The process of checking for open spots in a hash table if there is a collision. d. The process of cleaning up a hash table that has had too many collisions.

b. Storing a linked list in each table entry that contains each value that hashes to the same location.

Which of the following is NOT an invariant of a Red-Black tree? a. A node is either red or black. b. The root is always red. c. A red node always has black children d. The number of black nodes in any path from the root to the leaf is the same.

b. The root is always red.

An internal node of a 2-3-4 Tree always has one more child than the number of elements in the node. a. False b. True

b. True

Unlike a vector, a set does not support the subscript operator (e.g. mySet[0]). If someone still wanted to iterate through each item in a set, they should __________. a. Use a vector instead, it cannot be done b. Use an iterator c. Use the at() function d. Use the toString() function and read the resulting string

b. Use an iterator

In a binary search tree, all of the following are synonyms except _______. a. a node's inorder predecessor b. a node's parent c. the largest value in the node's left subtree d. the value found by going left from the node, and then going right as far as possible

b. a node's parent

What are the correct intermediate steps of the following data set when it is being sorted with the Quick sort? 15,20,10,18 a. 10, 20,15,18 -- 10,15,20,18 -- 10,15,18,20 b. 10, 20,15,18 -- 10,18,15,20 -- 10,15,18,20 c. 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20 d. 15,20,10,18 -- 15,10,20,18 -- 10,15,20,18

c. 15,10,20,18 -- 10,15,20,18 -- 10,15,18,20

A left-right AVL imbalance calls for ___________ rotation(s); a right-right imbalance calls for ____________ rotation(s) to correct the immediate imbalance. a. 1 or 2, 1 or 2 b. 2 or more, 1 or more c. 2, 1 d. 1, 2

c. 2, 1

Which of the following arrays represents a binary max-heap? a. 25, 12, 16, 13, 10, 8, 14 b. 25, 12, 16, 13, 10, 8, 14 c. 25, 14, 16, 13, 10, 8, 12 d. 25, 14, 12, 13, 10, 8, 16

c. 25, 14, 16, 13, 10, 8, 12

What is the maximum height of an AVL-tree with 7 nodes? (Assume the height of a tree with a single node is 1.) a. 2 b. 3 c. 4 d. 5

c. 4

Considering the following AVL tree, which of the following is the updated AVL tree after insertion of 70? 60 / \ 20 100 / \ 80 120 A) 70 B) 80 C) 80 / \ / \ / \ 60 100 60 100 60 100 / / \ / / \ / \ \ 20 80 120 20 70 120 20 70 120

c. C

When inserting into a 2-3-4 tree, the new value is always inserted ___________. a. In the root. b. As the middle value of a 4-node. c. In a leaf node. d. (You cannot know for certain)

c. In a leaf node.

What are characteristics of a good pivot in the quicksort algorithm? a. It does not matter, all pivots are equally effective. b. It is close to the mean value of the list. c. It is close to the median value of the list. d. It is either very large or very small compared to the rest of the list.

c. It is close to the median value of the list.

The Big O of the number of exchanges of selection sort is ___. The Big O of the comparisons is ___. a. O(n), O(n) b. O(n2), O(n2) c. O(n), O(n2) d. O(n), O(1)

c. O(n), O(n2)

"Divide-and-conquer" refers to: a. The list being divided into sublists with equal numbers of elements in each, then those sorted sublists are merged back together. b. The list being divided into only two sublists, never more or less, which are sorted and merged back together. c. The list being divided into smaller sublists, then those sorted sublists are merged back together.

c. The list being divided into smaller sublists, then those sorted sublists are merged back together.

When 2 rotations are needed in an AVL tree, the first rotation should be around the ________; the second rotation should be around the __________. a. parent, child in the same direction b. child, parent in the same direction c. child, parent in the opposite direction d. parent, child in the opposite direction

c. child, parent in the opposite direction

What is the primary advantage of heap sort over merge sort? a. Heap sort is easier to visualize. b. Heap sort is significantly faster than heap sort. c. Heap sort is stable, while merge sort is unstable. d. Heap sort requires less space than merge sort.

d. Heap sort requires less space than merge sort.

The inorder traversal sequence of a binary tree is A B C. The root is _______. a. A b. B c. C d. Not a unique binary tree.

d. Not a unique binary tree.

Which of the following most accurately describes the insertion sort algorithm? a. Finding the largest chunk of the sorted list, and then sorting afterward. b. Gradually shifting larger items to the back of the array, or smaller items to the front. c. Picking the smallest item and moving it to the front of the list until the list is sorted. d. Placing each item into the correct position in the list one at a time, like a hand of cards.

d. Placing each item into the correct position in the list one at a time, like a hand of cards.

Which of the following most accurately describes the quicksort algorithm? a. Placing every item into a heap and moving the top item into the sorted list. b. Sorting the first element, and then adding items from the rest of the list recursively. c. Splitting the array in thirds, and sorting the sub-arrays recursively. d. Splitting the array in halves based on size, and sorting the halves recursively.

d. Splitting the array in halves based on size, and sorting the halves recursively.

Suppose you want to traverse a hash table of names in alphabetical order. How would you do that? a. Use an iterator. b. Use the remove operator. c. Use the subscript operator or the at() function. d. This cannot be done.

d. This cannot be done.

Traversal algorithms are fairly simple. What attribute of trees makes that so? a. Trees are linear data structures. b. Trees are normally smaller than other data structures. c. Trees are normally larger than other data structures. d. Trees are recursive data structures.

d. Trees are recursive data structures.

Which of the following is true about the selection sort? a. Each element is examined only once. b. It is one of the most complex sorting algorithms. c. The code executes in O(n) time if the elements are sorted already. d. With each pass, an element jumps to its final location.

d. With each pass, an element jumps to its final location.

Which of the following is NOT a property of a 2-3-4 Tree? a. Each node stores three values at most sorted from smallest to greatest. b. All leaf nodes are at the same level (perfectly balanced). c. An internal (non-leaf) node can either have 2, 3 or 4 children. d. A leaf node can have 2, 3 or 4 items but no children. e. All of the above are properties of a 2-3-4 Tree.

e. All of the above are properties of a 2-3-4 Tree.

An associative set can be implemented using a. Binary Search Tree. b. Ordered linked list. c. Chained hash table. d. Probed hash table. e. Any of the above.

e. Any of the above.

Which of the following is a true about Binary Trees? a. Every binary tree is either complete or full. b. Every complete binary tree is also a full binary tree. c. Every full binary tree is also a complete binary tree. d. No binary tree is both complete and full. e. None of the above are true.

e. None of the above are true.

Shell sort can be interpreted as an improved version of which sorting algorithm? a. Bubble sort b. Insertion sort c. Selection sort d. Merge sort

b. Insertion sort

If the local root has an AVL imbalance of -2 and both its children have balances of 0, ___________. a. do a double rotation b. do a single rotation c. do nothing d. you messed up; this cannot happen

b. do a single rotation

A heap a. is a full and complete binary tree. b. is a full binary tree. c. only requires the root value to be greater than or equal to all items in the tree. d. requires every subtree to be a heap.

D. requires every subtree to be a heap.


Kaugnay na mga set ng pag-aaral

Psych 310 Exam 2 practice questions

View Set

Transfer of Title by Deed; Recording

View Set

Series 7 - Taxes & Tax Shelters: Types of Taxable Income

View Set

New York Language School - Ways to answer on "How are you?" question

View Set

Chapter 3: Interaction of X-Radiation

View Set

Chapter 62: Caring for Clients with Traumatic Musculoskeletal Injuries

View Set

Computer Concept for End Users: Unit 7

View Set

Week 7 Gastrointestinal System NCLEX questions

View Set

A&P - Physiology of Respiration (Quiz 4)

View Set