0% found this document useful (0 votes)
300 views4 pages

Heap

These are typical exam questions from Chapter 11 of a textbook on heaps and B-trees. There are 14 short answer questions and 12 multiple choice questions covering topics like the properties of heaps and B-trees, operations like insertion and deletion, and time complexity analysis of tree algorithms.

Uploaded by

Thawban Hassan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
300 views4 pages

Heap

These are typical exam questions from Chapter 11 of a textbook on heaps and B-trees. There are 14 short answer questions and 12 multiple choice questions covering topics like the properties of heaps and B-trees, operations like insertion and deletion, and time complexity analysis of tree algorithms.

Uploaded by

Thawban Hassan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

These are typical exam questions from Chapter 11 of the textbook.

These exact questions might not be on your exam, but if you research and find the right answers to these questions, that should be good preparation for a real exam. (It's also possible that some of this material was not covered in your class.) At the moment there are 14 short answer questions and 12 multiple choice questions in this file. Short Answers 1. Suppose that we want to create a heap where each node contains Short Answers information of some data type called Item (which has a default Section 11.1 constructor and a correct value semantics). What additional factor Heaps is required for the Item data type? 2. A heap is a binary tree where the entries can be compared using the usual six comparison operations (that form a total order semantics). Write the two rules that the binary tree must follow in order for the structure to actually be a heap. 3. Give two different reasons to explain why the following binary tree is not a heap:
4. 5. 6. 7. 8. 10. 11. 12. 13. 14. 16. 17. 18. 19. 20. 91 / 77 / 68 \ 81 910 / \ 77 / 68 \ 1 66 / \ 3 11 \ 46 \ 11

9. Draw a new heap that is created by inserting 82 into the following heap:

15. Draw a new heap that is created by removing one item from the following heap:
910 / \ 77 / 68 \ 1 66 / \ 3 11

21. Suppose that you are performing a reheapification downward. Write a precise condition that describes the situation that causes the reheapification to stop. 22. Suppose that you are performing a reheapification upward. Write a precise condition that describes the situation that causes the reheapification to stop. 23. Suppose that a non-leaf node in a B-tree contains 42 entries. How Short Answers many children does the node have? Section 11.2 24. Draw an example of a B-tree with four nodes and seven integer B-Trees entries. The value of MINIMUM is 1 for this tree. 25. Draw a new B-tree that is created by inserting 82 into the following B-tree. For this example, the minimum number of items in each node is 1. Note that the rightmost leaf starts with two entries, 71 and 93.
26. 27. 28. 29. 30. 56 / 7 / 2 \ 8 \ 66 / \ 63 71 and 93

31. Draw a new B-tree that is created by deleting 63 from the following B-tree. For this example, the minimum number of items in each node is 1. Note that the rightmost leaf starts with two entries, 71 and 93.
32. 33. 34. 35. 36. 56 / 7 / 2 \ 8 \ 66 / \ 63 71 and 93

37. Suppose that a B-tree is declared so that MAXIMUM (the maximum number of items in a node) is 84. What is the value of MINIMUM (the minimum number of items in a nonroot node)? 38. Suppose that a B-tree is declared so that MAXIMUM (the maximum number of items in a node) is 84. Write one clear sentence to describe why each node's data array is set up to hold up to 85 items (one more than MAXIMUM). 39. Suppose that a and b are two positive integers and n is some non-negative number. Write an equation to show the relationship between log base a of n and log base b of n. Give a derivation to show that the relationship is valid. Multiple Choice 1. What feature of heaps allows them to be efficiently implemented Multiple Choice using a partially filled array? Section 11.1 o A. Heaps are binary search trees. Heaps o B. Heaps are complete binary trees. o C. Heaps are full binary trees. o D. Heaps contain only integer data. 2. If a heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), where is the entry with the greatest value? o A. data[0] o B. data[n-1] o C. data[n] o D. data[2*n + 1] o E. data[2*n + 2] 3. Select the true statement about the worst-case time for operations on heaps. o A. Niether insertion nor removal is better than linear. o B. Insertion is better than linear, but removal is not. o C. Removal is better than linear, but insertion is not. o D. Both insertion and removal are better than linear. 4. Suppose that we have implemented a priority queue by storing the items in a heap (using an array for the heap items). We are now executing a reheapification upward and the outof-place node is at data[i] with priority given by data[i]. Which of the following boolean expressions is TRUE to indicate that the reheapification IS NOT YET DONE. o A. (i > 0) o B. (data[(i-1)/2] < data[i]) o C. (i > 0) && (data[(i-1)/2] < data[i]) Short Answers Section 11.3 Trees, Logs, and Time Analysis

D. (i > 0) || (data[(i-1)/2] < data[i]) 5. Suppose that we have implemented a priority queue by storing the items in a heap. We are now executing a reheapification downward and the out-of-place node has priority of 42. The node's parent has a priority of 72, the left child has priority 52 and the node's right child has priority 62. Which statement best describes the status of the reheapification. o A. The reheapification is done. o B. The next step will interchange the two children of the out-of-place node. o C. The next step will swap the out-of-place node with its parent. o D. The next step will swap the out-of-place node with its left child. o E. The next step will swap the out-of-place node with its right child. 6. Which formula is the best approximation for the depth of a heap with n nodes? o A. log (base 2) of n o B> The number of digits in n (base 10) o C. The square root of n o D. n o E. The square of n 7. Which statement is true for a B-tree? Multiple Choice o A. All entries of a node are greater than or equal to the Section 11.3 entries in the node's children. B-trees o B. All leaves are at the exact same depth. o C. All nodes contain the exact same number of entres. o D. All non-leaf nodes have the exact same number of children. 8. Suppose that a non-leaf node in a B-tree has 41 entries. How many children will this node have? o A. 2 o B. 40 o C. 41 o D. 42 o e. 82 9. Suppose that a B-tree has MAXIMUM of 10 and that a node already contains the integers 1 through 10. If a new value, 11, is added to this node, the node will split into two pieces. What values will be in these two pieces? o A. The first piece will have only 1 and the second piece will have the rest of the numbers. o B. The first piece will have 1 through 5 and the second piece will have 6 through 11. o C. The first piece will have 1 through 5 and the second piece will have 7 through 11. o D. The first piece will have 1 through 6 and the second piece will have 7 through 11. o E. The first piece will have 1 through 10 and the second piece will have only 11. 10. Suppose that X is a B-tree leaf containing 41 entries and having at least one sibling. Which statement is true? o A. Any sibling of X is also a leaf.

o o o

B. Any sibling of X contains at least 41 entries. C. The parent of X has exactly 42 entries. D. X has at least 41 siblings. Multiple Choice Section 11.3 Trees, Logs, and Time Analysis

11. Suppose you run a O(log n) algorithm with an input size of 1000 and the algorithm requires 110 operations. When you double the input size to 2000, the algorithm now requires 120 operations. What is your best guess for the number of operations required when you again double the input size to 4000? o A. 130 o B. 140 o C. 150 o D. 160 o E. 170 12. Tree algorithms typically run in time O(d) . What is d? o A. The depth of the tree. o B. The number of divisions at each level. o C. The number of entries in each node. o D. The number of nodes in the tree. o E. The total number of entries in all the nodes of the tree.

You might also like