Question

How many levels will there be in a complete binary tree is it has n number...

How many levels will there be in a complete binary tree is it has n number of nodes?

looking for formula

Homework Answers

Answer #1

Complete Binary Tree: A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible

Suppose height of tree = h. then #levels (L) = h+1 .

then maximum possible nodes in complete binary tree is when all levels are completely filled means

at rpot level i.e. level 1 #nodes = 1 = 2^0

at level 2 #nodes = 2=2^1

at level 3 #nodes = 4=2^2

at level 4 #nodes = 8=2^3

at level 5 #nodes =16= 2^4

.

.

.

.

.

at level h #nodes = 2^(h-1)

at level h+1 #nodes = 2^h

total = 2^0 + 2^1 + 2^2 + 2^3 + ………+2^(h-1) + 2^h

====> 1+2+4+8+…………………………………….+2^h

so given number of nodes in complete binary tree must be at most = total

i.e. n<= total

n<= 1+2+4+8+…………………………………….+2^h

n<= 2^(h+1)

n<= 2^L (becoz, L= h+1)

log2(n) <=L

L >= log2(n)

L = ceil ( log2(n) )

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. a) Suppose that a binary tree of height h has n nodes. Show that h...
1. a) Suppose that a binary tree of height h has n nodes. Show that h ≥ log2 (n+2) - 1. b) Using the formula in part (a) find the minimum height if a binary tree with 1000 nodes. c) What is the maximum possible height of a binary tree with 1000 nodes?
How can I prove that any node of a binary search tree of n nodes can...
How can I prove that any node of a binary search tree of n nodes can be made the root in at most n − 1 rotations?
Problem 3 Given a BST with N nodes, how many tree shapes are there with height...
Problem 3 Given a BST with N nodes, how many tree shapes are there with height N-1? Explain your reasoning. Problem 4 Given a BST with N nodes, how many tree shapes are there with height N-2? Explain your reasoning . Problem 5 Consider an empty 2-3 tree. Draw the tree after each of the following operations is executed: insert 0, insert 9, insert 2, insert 6, insert 7, insert 3, insert 8, delete 2, delete 6
Prove that a full non-empty binary tree must have an odd number of nodes via induction
Prove that a full non-empty binary tree must have an odd number of nodes via induction
Suppose a binary tree stores integers. Write efficient methods (and give their Big-Oh running times) that...
Suppose a binary tree stores integers. Write efficient methods (and give their Big-Oh running times) that take a reference to a binary tree root T and compute a. the number of nodes with two children that contain the same value **JAVA**
A binary tree isfullif every non-leaf node has exactly two children. For context, recallthat we saw...
A binary tree isfullif every non-leaf node has exactly two children. For context, recallthat we saw in lecture that a binary tree of heighthcan have at most 2h+1−1 nodes, and thatit achieves this maximum if it iscomplete, meaning that it is full and all leaves are at the samedistance from the root. Findμ(h), theminimumnumber of nodes that a full tree of heighthcan have, and prove your answer using ordinary induction onh. Note that tree of height of 0 isa single...
Construct a Binary Search Tree using the following data:   (5 pts)                 54           37   &nb
Construct a Binary Search Tree using the following data:   (5 pts)                 54           37           47           28           44           71           40           60 (Make sure to show dummy nodes) b) Illustrate how will you search for V = 39 from the above tree and how many searches will be needed. (5 pts) c) Illustrate how you will delete the root from the above tree, redraw the tree after deletion. (5 pts). Redraw the tree.
Let T be a complete binary tree such that node v stores the entry (p(v), 0),...
Let T be a complete binary tree such that node v stores the entry (p(v), 0), where p(v) is the level number of v. Is tree T a heap? Why or why not? I know that a complete binary tree is a heap, but shouldn't we also take into consideration the values that it is storing into the tree: (p(v), 0)? The heap tree could be either a min-heap or max-heap. If we order the the value based of p(v)...
How many n-digit binary numbers do not start with 0?
How many n-digit binary numbers do not start with 0?
Show that the total degree of a complete graph with n nodes is n(n-1) using INDUCTION....
Show that the total degree of a complete graph with n nodes is n(n-1) using INDUCTION. Do not apply (a) the result on the total degree of a graph proven (b) the formula for the number of edges in a complete graph.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT