Given the heap as shown below, answer the questions. a) Is this a Max Heap or Min Heap? b) Show the process of removing the root step by step. You need to draw the tree for each swap operation and...

Given the heap as shown below, answer the questions.
a) Is this a Max Heap or Min Heap?
b) Show the process of removing the root step by step. You need to draw the tree for each swap operation
and each remove operation.


Document Preview:

Problem 1. Heaps Given the heap as shown below, answer the questions. a) Is this a Max Heap or Min Heap? b) Show the process of removing the root step by step. You need to draw the tree for each swap operation and each remove operation.Problem 2. Binary Tree a) A binary tree can be represented in several ways. One way of representing binary trees is through lists. Here is a list representation of a simple binary tree (the first element is the root, the second element is the left subtree, and the third element is the right subtree). For example, the list (A (B (D) (E))(C)) represents the following tree. Given the following list representation of a simple binary tree: ( a ( b ( d ( k ( ) ( i ) ) ( ) ) (e ( ) ( ) ) ) ( c ( f ( ) ( ) ) ( g ( ) ( ) ) ) ) Please draw the corresponding tree. b) What is the post-order traversal of this tree? c) For any binary tree, write a function in C++ that prints out each node’s data level by level. Nodes are on the same level if they are the same distance from the root. Output a new line character at the end of each level. Nodes on the same level are separated by a single space. Each node in the binary tree can have 0, 1 or 2 children. Sample Input: Sample Output: 10 9 22 16 5Node is defined as: struct Node { node* left; node* right; int data; }; Complete the function defined here (Hint: a queue might be helpful): void printTree(node* root) { /* Your code */ }



May 23, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here