1. Suppose that d ≥ 2 is an integer
constant. In a d-ary tree, each node has at most
d nonempty subtrees. For example, the trees discussed
along with heaps had d = 2. We can represent a nearly
complete d-ary tree with n nodes using an array
whose indexes range from 0 to n−1. (This is different from
Cormen’s arrays, whose indexes range from 1 to n.)
Suppose that i is the index
of a node in the array. Then CHILD(i, j) is the
index of the jth child of the node at i, where 1
≤ j ≤ d. If there is no such child, then
CHILD(i, j) ≥ n. Also,
PARENT(i) is the index of the parent of the node at
i. If there is no such parent, then PARENT(i)
< 0.
1a. (5 points.) Show a short algorithm for CHILD. Your algorithm must run in Θ(1) time.
1b. (5 points.) Show a short algorithm for PARENT. Your algorithm must run in Θ(1) time.
Child:
child(i,j){
return d*i + j
}
Parent:
parent(i)
{
return [i - 1] / d
}
1. Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node...
Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node has at most d nonempty subtrees. For example, the trees discussed along with heaps had d = 2. We can represent a nearly complete d-ary tree with n nodes using an array whose indexes range from 0 to n−1. (This is different from Cormen’s arrays, whose indexes range from 1 to n.) Suppose that i is the index of a node in the array....
Suppose that binary heaps are represented using explicit links. Give a simple algorithm to find the tree node that is at implicit position i. instructions: provide Java-like pseudocode. The implicit position of a node refers to the index it would have if the heap was stored in the array format reviewed in class (first element at index 1).
2. A regular binary tree is a binary tree whose internal nodes all have two subtrees (left and right). In other words, all their nodes have either zero subtrees (in which case they are leaves) or two subtrees (in which case they are internal nodes). Suppose that you have a boolean function that tells you, for each node of the tree, whether it is a leaf or not (call it: leaf(n), for node n). a) Write a recursive function that...
In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree of height with each node having at most two children with the property that value of a node is at most the value of its children. Such heap containing n elements can be represented (stored) as an array with the property Suppose that you would like to construct a & min Heap: each node has at most& children and the value of a node...
It is due in 2 hours.. Thanks !
Suppose that an algorithm runs on a tree containing n nodes. What is the time complexity of the algorithm if the time spent per node in the tree is proportional to the number of grandchildren of the node? (Assume that the algorithm spends O(1) time for every node that does not have a grandchild.) In modern software development, a useful utility called make is usually employed to manage the compilation order of...
You are given a binary tree of the form:
Each node in the tree has a left child and a right child. Each
of the children will be extended as a linked list. Every node has
the following attributes: key, left node, right node, and next
node. The next node allows a node, that is a part of the tree, to
be extended as a linked list. The diamonds represent the next
nodes, which are part of the linked list...
Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes The key T.key is the root node's key. The left child T.left is Ts left subtree, which is an AVL tree (possibly E). The right child T.right is T's right subtree, which is an AVL tree (possibly E). (a) 5 marsl Write a function RANGECOUNT(T, lo, hi) to count the number of nodes in an AVL tree with...
4. Consider the following subtree of a balanced AVL tree a b AA d X Y d+1 d+2 Now, suppose that subtrees (i.e., subtree X and subtree Y) to be both two levels deeper than its right subtree (i.e., subtree Z) so that we have the following unbalanced AVL tree node at the bottom of subtree Z is deleted, causing its two left a a b d d+1 X d+2 Describe how the AVL tree can be rebalanced. Draw the...
Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes: • The key T.key is the root node’s key. • The left child T.left is T’s left subtree, which is an AVL tree (possibly E). • The right child T.right is T’s right subtree, which is an AVL tree (possibly E). (a) [5 marks] Write a function RangeCount(T, lo, hi) to count the number of nodes in an...
Need them in c++ 1. Give the code for the definition of a node for the linked implementation of a tree that contains integer data. 2. In the array implementation of a tree in C, if the data for anode in in index i, what are the indices of its two children? 3. Draw the binary search treethat resultsfor insertingthe following numbers, in the order given, into aninitially empty tree: 64, 14, 23, 84, 67, 2, 8, 73, 89, 47. 4. Describe, in detail, the algorithm for deleting a node from a binary search tree. (make sure you have differentcases fornodes with 0, 1, or 2 children.