Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the implementation of Binary Tree: template class BinNodePtr { private: int it; // The node's value BinNodePtr* lc; // left child pointer BinNodePtr* rc;

Given the implementation of Binary Tree:

template class BinNodePtr {

private:

int it; // The node's value

BinNodePtr* lc; // left child pointer

BinNodePtr* rc; // right child pointer

public:

int& val() { return it; }

BinNodePtr* left() const { return lc;}

BinNodePtr* right() const { return rc;}

};

void traversal(BinNode* subroot) {

if (subroot == NULL) return;

cout val();

traversal(subroot->left());

traversal(subroot->right());

}

Figure 1

a)

What is the type of the traversal represented by traversal()?

(2 marks)

b)

Assume variable root is equal to the root of the tree shown in Figure 1, write down the

output of traversal(root).

(5 marks)

c)

Assume the given tree is the Binary Search Tree, draw the updated tree after removing 51.

(3 marks)

d)

Write a recursive function that returns the height of a binary tree. Your function should

have the following prototype.

(10 marks)

int height(BinNode* subroot)

image text in transcribed

2. 2. [20 marks] 51 Given the implementation of Binary Tree: template class BinNodePtr { private: int it; The node's value BinNode Ptr* lc; left child pointer BinNodePtr* rc; right child pointer public: int& val() { return it; } BinNodeftr* 'left() const { return lc;}. BinNodeftr* right') const { return rc; } }; void traversal (BinNode* subroot) { if (subroot == NULL) return; cout val(); traversal (subroot->left (; } 13 74 20 56 Figure 1 a) What is the type of the traversal represented by traversal()? (2 marks) b) Assume variable root is equal to the root of the tree shown in Figure 1, write down the output of traversal (root). (5 marks) c) Assume the given tree is the Binary Search Tree, draw the updated tree after removing 51. (3 marks) d) Write a recursive function that returns the height of a binary tree. Your function should have the following prototype. (10 marks) int height (BinNode* subroot)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Presentations Approaches to Conveying Information

Answered: 1 week ago