a)
Heap is a data structure which is an almost complete binary tree. which means that if tree is of height 'h' then all the nodes till height 'h-1' needs to be completely filled. Thus we can easily calculate the minimum number of keys required, which has to be all levels of 'h-1' filled plus one node at height 'h'.
Thus if a heap of height 'h' is considered we get minimum number of nodes as,
total number of nodes till height 'h-1' + one node at height 'h'
= (-1) + 1
=
Thus smallest number of keys required for a heap of height h is
.
For maximum number of keys in a heap. The heap of height 'h' has to be completely filled. As per the definition it has to be a complete binary tree. Thus maximum number of nodes will be same as the number of nodes for a complete binary tree with height 'h'.
Thus, maximum number of keys equals to ( -1)
b)
Now, from the above conclusions the minimum and maximum number
of keys for a binary heap is
and (
-1)
respectively.
Thus, for a tree with 'n' number of nodes, it has to lie between then maximum and minimum number of nodes. Thus, we get the following relation.
n
(
-1)
Taking logarithms of base 2, we get
h-1
h //log 1
=0
Thus from this we conclude that, the height of binary heap with
'n' nodes follows .
Thus height of heap with 'n' nodes is .
(a) Find the smallest and the largest number of keys that a heap of height h...
Suppose you have a B-tree of height h and minimum degree k. What is the largest number of keys that can be stored in such a B-tree? Prove that your answer is correct.
1. In a heap, the upper bound on the number of leaves is: (A) O(n) (B) O(1) (C) O(logn) (D) O(nlogn) 2. In a heap, the distance from the root to the furthest leaf is: (A) θ(nlogn) (B) θ(logn) (C) θ(1) (D) θ(n) 3. In a heap, let df be the distance of the furthest leaf from the root and let dc be the analogous distance of the closest leaf. What is df − dc, at most? (A) 1 (C)...
Prove by mathematical induction that а. h log2 for any binary tree with height h and the number of leaves I b. h > log3 ] for any ternary tree with height h and the number of leaves I.
Rank the following lists from smallest on the left to largest on the right. If two entries have equal value, state equal value. (a) Zeff for the Li 1s, 2s, and 2p orbitals. (b) Zeff for the Li2+ 1s, 2s, and 2p orbitals. (c) r for the F 1s, 2s, and 2p orbitals. (d) |Zeff(2s) – Zeff(2p) for Li, F, and Ne. (e) For an H atom, the uncertainty of the e location, for the e in the 1s, 3p,...
Let T be a heap storing n keys. Give an efficient algorithm for
reporting all
the keys in T that are smaller than or equal to a given query key x
(which is
not necessarily in T). For example, given the heap of Figure 5.6
and query key
x = 7, the algorithm should report 4, 5, 6, 7. Note that the keys
do not need to be
reported in sorted order. Ideally, your algorithm should run in
O(k) time,...
Show that the tree height of a height-balanced binary search tree with n nodes is O(log n). (Hint: Let T(h) denote the fewest number of nodes that a height-balanced binary search tree of height h can have. Express T(h) in terms of T(h-1) and T(h-2). Then, find a lower bound of T(h) in terms of T(h-2). Finally, express the lower bound of T(h) in terms of h.)
Provide an O(k log k) algorithm that uses a heap data structure to find the kth largest element from the heap of n elements where n > k. Sketch your algorithm. (Hint: You may need to use an additional heap) Use the example data below to demonstrate the process. (e.g. Find the 7 largest element from this heap and it should be 45) Justify the running time. Heap H 100 80 70 40 50 65 60 20 40 10 30...
(e) Consider an initially empty max-heap, where the following keys are to be inserted one at a time: 11, 19, 23, 12, 13, 17, 13, 14, 18, and 33. Draw the tree that results after building this max-heap. (f) Is it possible to find the maximum in a min-heap in O(log n) time? Justify. Important Notes: • For part (e) of this problem, you must draw the min (or max) heaps using the appropriate graphics tools at your convenience.
4. Use the AM-GM inequality to find the largest right circular cylinder that is inscribed in a right cone with base radius R and height H. Also determine the radius and height of the largest such cylinder.
4. Use the AM-GM inequality to find the largest right circular cylinder that is inscribed in a right cone with base radius R and height H. Also determine the radius and height of the largest such cylinder.
For a simple BST (without any balancing) storing n keys and of height h, the running time of the search operation (for a worst-case instance) is o (log h) 0 (h) o O(n) o (log n)