Test2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Left child(index)

2 * index + 1 if 2 * index + 1 < n

Right child(index)

2 * index + 2 if 2 * index + 2 < n

What is the minimum number of internal nodes in a binary tree with 8 nodes?

4

What is the minimum number of nodes in a FULL binary tree with height 3?

7

Parent(index)

(index−1)/2 if r≠0

In a max-heap containing n elements, what is the position of the element with the greatest value? 2∗n+2 The rightmost leaf node The leftmost leaf node n+1 Possibly in any leaf node n−1 0 2∗n+1 n

0

A BST is another name for a binary tree. True False

False

Heapsort (as the code is written in this module) is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys. True False

False

If you are given the order of the nodes as visited by a preorder traversal and the order of the nodes as visited by a postorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values. True False

False

The system will perform exact mach queries only, when stored in main memory, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

A disadvantage of Heapsort is: It is not stable (i.e., records with equal keys might not remain in the same order after sorting) None of these answers Its average case running time is O(n^2) It needs a lot of auxilliary storage

It is not stable (i.e., records with equal keys might not remain in the same order after sorting)

BST search, insert, and delete operations typically run in time O(d). What is d? The number of nodes in the tree The number of entries in each node The total number of entries in all the nodes of the tree The depth of the relevant node in the tree The number of divisions at each level

The depth of the relevant node in the tree

Assume that for some binary tree node implementation, a pointer requires 8 bytes and a data object requires 16 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store two pointers and a data field, and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2 x P/2) + D = P + D(2∗P/2)+D=P+D and the overhead is (2 x P/2)(2∗P/2). = P/(P+D) = 8/24 = 1/3

(Assuming no duplicate key values:) The order of the input records has what impact on the number of comparisons required by Heapsort (as presented in this module)? None There is a constant factor difference There is a big difference, the asymptotic running time can change

There is a constant factor difference

Visiting each element in a tree is known as: Inserting Merging Enumerating Traversing Sorting

Traversing

If you are given the order of the nodes as visited by a postorder traversal and the order of the nodes as visited by an inorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values. True False

True

If you are given the order of the nodes as visited by a preorder traversal and the order of the nodes as visited by an inorder traversal, do you have enough information to reconstruct the original tree? Assume that the nodes all have unique values. True False

True

When you print out the nodes of binary tree, the leaf nodes appear in the same relative order for the preorder, inorder, and postorder traversals. True False

True

Right sibling(index)

index + 1 if index is odd and index + 1 < n

Left sibling(index)

index − 1 if index is even and index ≠ 0

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a left sibling, where will the left sibling's position be in the array? i+1 2∗i+2 i−1 None of the above

i−1

How much auxilliary space or overhead (beyond the array holding the records) is needed by Heapsort? Θ(n^2) Θ(1) Θ(logn) Θ(n)

Θ(1)

What is the running time of Heapsort when the input is an array where all key values are equal? Θ(n^2) Θ(n) Θ(logn) Θ(n ^ n) Θ(nlogn)

Θ(n)

What traversal? static void XXX(BinNode rt) { if (rt == null) return; XXX(rt.left()); visit(rt); XXX(rt.right()); }

Inorder

Which of these is a true statement about the worst-case time for operations on heaps? Insertion is better than linear, but removal is not Neither insertion nor removal are better than linear Removal is better than linear, but insertion is not Both insertion and removal are better than linear

Both insertion and removal are better than linear

A binary tree is another name for a BST. True False

False

The system will support range queries, when stored in main memory, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Linear Index

The system will support range queries, when stored on disk, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Linear Index

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a parent, where will the parent's position be in the array? 2∗i+2 i+1 2∗i+1 None of the above

None of the above (i−1)/2

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a left child, where will the left child's position be in the array? 2∗i+2 (i−1)/2 i+1 None of the above

None of the above 2∗i+1

In a max-heap containing n elements, what is the position of the element with the least value? n 0 2∗n+2 n+1 Possibly in any leaf node 2∗n+1 n−1 The rightmost leaf node The leftmost leaf node

Possibly in any leaf node

What traversal? static void XXX(BinNode rt) { if (rt == null) return; XXX(rt.left()); XXX(rt.right()); visit(rt); }

Postorder

What traversal? static void XXX(BinNode rt) { if (rt == null) return; visit(rt); XXX(rt.left()); XXX(rt.right()); }

Preorder

In which cases are the time complexities the same for Heapsort? Worst and Best Worst and Average Best and Average Worst, Average and Best

Worst, Average and Best

The system will perform exact mach queries only, when stored in main memory, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

The system will perform exact mach queries only, when stored on disk, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

The system will perform exact mach queries only, when stored on disk, working on a static database (no inserts or deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Closed Hash Table

Which statement is false? Every non-root node in a binary tree has exactly one parent Every binary tree has at least one node Every non-empty binary tree has exactly one root node Every node in a binary tree has exactly two children None of the above

Every binary tree has at least one node

Which feature of heaps allows them to be efficienty implemented using an array? Heaps are full binary trees Heaps are binary search trees Heaps are complete binary trees Heaps are binary trees

Heaps are complete binary trees

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a left child, where will the left child's position be in the array? 2∗i+2 i+2 i+1 None of the above

2∗i+1

Consider a node R of a complete binary tree whose value is stored in position i of an array representation for the tree. If R has a right child, where will the right child's position be in the array? 2∗i+1 2∗i+2 i+1 None of the above

2∗i+2

Suppose T is a binary tree with 14 nodes. What is the minimum possible height of T?

3

What is the minimum number of nodes in a complete binary tree with height 3?

8

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 21 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

= (2 x P) / (2 x P + D) = 8/29

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 24 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store two pointers and a data field, and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

= P / (P + D) = 4/28 = 1/7

The system will support range queries, when stored on disk, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

B+ Tree

Why does function preorder2() presented in the Traversal module make only half as many recursive calls as function preorder()? Because there are half as many leaf nodes Because only internal nodes get called Because there are half as many nodes Because half of the pointers are null

Because half of the pointers are null

The system will support range queries, when stored in main memory, working on a dynamic database (supports inserts and deletes). Binary Search Tree (assume that it is balanced) Closed Hash Table Linear Index B+ Tree

Binary Search Tree (assume that it is balanced)

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 28 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + (D/2) = P + D/2(2∗P/2)+(D/2)=P+D/2 and the overhead is PP. It is probably simpler to think of it as 2*P + D2∗P+D total space and 2*P2∗P overhead. = (P x 2)/ (P x 2 + D) = 8/36 = 2/9

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 6 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + (D/2) = P + D/2(2∗P/2)+(D/2)=P+D/2 and the overhead is PP. It is probably simpler to think of it as 2*P + D2∗P+D total space and 2*P2∗P overhead. = (P x 2)/(P x 2 + D) = 8/14 = 4/7

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 9 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + (D/2) = P + D/2(2∗P/2)+(D/2)=P+D/2 and the overhead is PP. It is probably simpler to think of it as 2*P + D2∗P+D total space and 2*P2∗P overhead. = (P x 2)/(P x 2 + D) = 8/17

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 14 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + (D/2) = P + D/2(2∗P/2)+(D/2)=P+D/2 and the overhead is PP. It is probably simpler to think of it as 2*P + D2∗P+D total space and 2*P2∗P overhead. = (P x 2)/(P x 2 + D) = 8/22 = 4/11

Assume that for some binary tree node implementation, a pointer requires 4 bytes and a data object requires 32 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store only two pointers (no data field), and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + (D/2) = P + D/2(2∗P/2)+(D/2)=P+D/2 and the overhead is PP. It is probably simpler to think of it as 2*P + D2∗P+D total space and 2*P2∗P overhead. = (P x 2)/(P x 2 + D) = 8/40 = 1/5

Assume that for some binary tree node implementation, a pointer requires 8 bytes and a data object requires 12 bytes. Further assume that we are storing a Full binary tree, that the internal nodes are implemented to store two pointers and a data field, and that the leaf nodes store only a data field. Type a fraction (like "1/2") that represents the fraction of the total space taken up by overhead. Give your fraction in lowest terms.

The total space is therefore (2*P/2) + D = P + D(2∗P/2)+D=P+D and the overhead is (2*P/2)(2∗P/2). = P/(P+D) = 8/20 = 2/5

The nn nodes in a binary tree can be visited in: Θ(1) time Theta(\log n) Θ(n) time Θ(nlogn) time Θ(n^2) time

Θ(n) time

What is the best-case time for Heapsort to sort an array of n records that each have unique key values? Θ(logn) Θ(n^2) Θ(nlogn) Θ(n) Θ(n^n)

Θ(nlogn)


Conjuntos de estudio relacionados

Subjunctive Spanish (copied from MARIA_SMITH514)

View Set

SC214 General Biology II Problem Set #2

View Set

Part 4 - Brand Extension & Co-branding

View Set

Growth and Development & Health Promotion (Ch. 3-7)

View Set

Globalization: Markets, Production, and Challenges

View Set

Prep U Renal questions for Exam 2

View Set