Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please answer this question and give detailed reasons for your answer (explain). Thank you. 2. (20 pts.) Imagine a generalized version of binary heap where
Please answer this question and give detailed reasons for your answer (explain). Thank you.
2. (20 pts.) Imagine a generalized version of binary heap where each non-leaf node has z children instead of 2. a. Show how you would represent such a heap using arrays. Show how to reach to the children nodes and parent nodes. Remember that for binary heap, given a node at position i, its left and right children are at positions 2i and 2i + 1, respectively. Also given a non-root node at position i, its parent node is at position [1/2]. Derive these formulas for your generic heap. Justify your answer. b. What is the height of the heap tree in terms of n and z where n is the total number of elements in the heap and z is the number of children each non- leaf node could have? Justify your answer. Remember that for binary heap, its height is [log2(n)]. 2. (20 pts.) Imagine a generalized version of binary heap where each non-leaf node has z children instead of 2. a. Show how you would represent such a heap using arrays. Show how to reach to the children nodes and parent nodes. Remember that for binary heap, given a node at position i, its left and right children are at positions 2i and 2i + 1, respectively. Also given a non-root node at position i, its parent node is at position [1/2]. Derive these formulas for your generic heap. Justify your answer. b. What is the height of the heap tree in terms of n and z where n is the total number of elements in the heap and z is the number of children each non- leaf node could have? Justify your answer. Remember that for binary heap, its height is [log2(n)]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started