Draw an example of a heap whose keys are all the odd numbers from 1 to 59 (with no repeats), such that the insertion of an entry with key 32 would cause up-heap bubbling to proceed all the way up to...
Recent Questions
1. Hillary claims that a postorder traversal of a heap will list its keys in nonincreasing order. Draw an example of a heap that proves her wrong.2. Illustrate all the steps of the adaptable...
1. Show that the sum ppearing in the analysis of heap-sort, is Ω(nlogn).2. Bill claims that a preorder traversal of a heap will list its keys in nondecreasing order. Draw an example of a heap that...
Let H be a heap storing 15 entries using the array-based representation of a complete binary tree. What is the sequence of indices of the array that are visited in a preorder traversal of H? What...
1. Explain why the description of down-heap bubbling does not consider the case in which position p has a right child but not a left child.2. Is there a heap H storing seven entries with distinct...
1. Illustrate the execution of the in-place heap-sort algorithm on the following input sequence: (2, 5, 16, 4, 10, 23, 39, 18, 26, 15).2. Let T be a complete binary tree such that position p stores...
1. At which positions of a heap might the third smallest key be stored?2. At which positions of a heap might the largest key be stored?3. Consider a situation in which a user has numeric keys and...
1. Illustrate the execution of the insertion-sort algorithm on the input sequence of the previous problem.2. Give an example of a worst-case sequence with n elements for insertion-sort, and show...
Illustrate all the steps of the adaptable priority queue call replaceKey(e, 18) for entry e storing (5, A) in the heap of Figure 9.1.Figure 9.1
1. Can you adapt your solution to the previous problem to make removeMin run in O(1) time for the UnsortedPriorityQueue class? Explain your answer.2. Illustrate the execution of the selection-sort...
An airport is developing a computer simulation of air-traffic control that handles events such as landings and takeoffs. Each event has a time stamp that denotes the time when the event will occur....
What does each removeMin call return within the following sequence of priority queue ADT operations: insert(5, A), insert(4, B), insert(7, F), insert(1, D), removeMin( ), insert(3, J), insert(6, L),...
1. How long would it take to remove the ⌈logn⌉ smallest elements from a heap that contains n entries, using the removeMin operation?2. Suppose you set the key for each position p of a binary tree T...
1. Write a program that can input and display a person’s family tree.2. Write a program that visualizes an Euler tour traversal of a proper binary tree, including the movements from node to node and...
1. Write a program that takes as input a general tree T and a position p of T and converts T to another tree with the same set of position adjacencies, but now with p as its root.2. Write a program...
Write a program that can play Tic-Tac-Toe effectively. (See Section 3.1.5.) To do this, you will need to create a game tree T, which is a tree where each position corresponds to a game...
A slicing floor plan divides a rectangle with horizontal and vertical sides using horizontal and vertical cuts. (See Figure 8.23a.) A slicing floor plan can be represented by a proper binary tree,...
Write a program that takes as input a fully parenthesized, arithmetic expression and converts it to a binary expression tree. Your program should display the tree in some way and also print the...
The min method for the UnsortedPriorityQueue class executes in O(n) time, as analyzed in Table 9.2. Give a simple modification to the class so that min runs in O(1) time. Explain any necessary...
The memory usage for the LinkedBinaryTree class can be streamlined by removing the parent reference from each node, and instead implementing a Position as an object that keeps a list of nodes...
1. Implement the binary tree ADT using the array-based representation described in Section 8.3.22. Implement the tree ADT using a linked structure as described in Section 8.3.3. Provide a reasonable...
Let T be a binary tree with n positions. Define a Roman position to be a position p in T, such that the number of descendants in p’s left subtree differ from the number of descendants in p’s right...
As mentioned in Exercise C-6.19, postfix notation is an unambiguous way of writing an arithmetic expression without parentheses. It is defined so that if “(exp1)op(exp2)” is a normal (infix) fully...
The indented parenthetic representation of a tree T is a variation of the parenthetic representation of T (see Code Fragment 8.26) that uses indentation and line breaks as illustrated in Figure...
Let T be a binary tree with n positions, and, for any position p in T, let dp denote the depth of p in T. The distance between two positions p and q in T is dp + dq − 2da, where a is the lowest...
Suppose each position p of a binary tree T is labeled with its value f(p) in a level numbering of T. Design a fast method for determining f(a) for the lowest common ancestor (LCA), a, of two...
Let T be a tree with n positions. Define the lowest common ancestor (LCA) between two positions p and q as the lowest position in T that has both p and q as descendants (where we allow a position to...
1. Design an algorithm for drawing general trees, using a style similar to the inorder traversal approach for drawing binary trees.2. Let the rank of a position p during a traversal be defined such...
Implement the tree ADT using the binary tree representation described in Exercise C-8.52. You may adapt the LinkedBinaryTree implementation.Exercise C-8.52We can define a binary tree representation...
We can define a binary tree representation T′ for an ordered general tree T as follows (see Figure 8.21):• For each position p of T, there is an associated position p′ of T′ . • If p is a leaf of T,...
Algorithm preorderDraw draws a binary tree T by assigning x- and y-coordinates to each position p such that x(p) is the number of nodes preceding p in the preorder traversal of T and y(p) is the...
Repeat Exercise C-8.47, implementing the AbstractBinaryTree’sinorder method.Exercise C-8.47To implement the preorder method of the AbstractTree class, we relied on the convenience of creating a...
Repeat Exercise C-8.47, implementing the postorder method of the AbstractTree class.Exercise C-8.47To implement the preorder method of the AbstractTree class, we relied on the convenience of...
1. Describe, in pseudocode, a nonrecursive method for performing an inorder traversal of a binary tree in linear time.2. To implement the preorder method of the AbstractTree class, we relied on the...
Design algorithms for the following operations for a binary tree T:• preorderNext(p): Return the position visited after p in a preorder traversal of T (or null if p is the last node visited). •...
1. Give an O(n)-time algorithm for computing the depths of all positions of a tree T, where n is the number of nodes of T.2. The balance factor of an internal position p of a proper binary tree is...
1. Modify the LinkedBinaryTree class to formally support the Cloneable interface, as described in Section 3.6.2. Give an efficient algorithm that computes and prints, for every position p of a tree...
1. Describe how to clone a LinkedBinaryTree instance representing a proper binary tree, with use of the attach method.2. Describe how to clone a LinkedBinaryTree instance representing a (not...
Redo the previous problem for the algorithm postorderDraw that is similar to preorderDraw except that it assigns x(p) to be the number of nodes preceding position p in the postorder...
We can simplify parts of our LinkedBinaryTree implementation if we make use of of a single sentinel node, such that the sentinel is the parent of the real root of the tree, and the root is...
Recent Comments