Question
part C please
8 BST 15 Points Given a BST T with root r write algorithms (pseudocode) to determine: (a) The height of T. (b) The maximum el
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

BELOW IS THE ALGO IN PSEUDOCODE

int isHeightBalanced(Node* root, bool& isBalanced)
{
// base case: tree is empty or tree is not balanced
if (root == nullptr || !isBalanced)
return 0;

// get height of left subtree
int left_height = isHeightBalanced(root->left, isBalanced);

// get height of right subtree
int right_height = isHeightBalanced(root->right, isBalanced);

// tree is unbalanced if absolute difference between height of
// its left subtree and right subtree is more than 1
if (abs(left_height - right_height) > 1)
isBalanced = false;

// return height of subtree rooted at current node
return max(left_height, right_height) + 1;
}

// Main function to check if given binary tree is height balanced or not
bool isHeightBalanced(Node* root)
{
bool isBalanced = true;
isHeightBalanced(root, isBalanced);

return isBalanced;
}

CALL THE FUNCTION AS

isHeightBalanced(T)

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
part C please 8 BST 15 Points Given a BST T with root r write algorithms...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q8 BST 15 Points Given a BST T with root r write algorithms (pseudocode) to determine:...

    Q8 BST 15 Points Given a BST T with root r write algorithms (pseudocode) to determine: (a) The height of T. (b) The maximum element in T. (c) If T is height balanced. Please select file(s) Select file(s) Q9 Double 15 Points Consider inserting the keys 10, 22, 31, 4, 15, 28, 17, 88,59 into a hash tabl- (1) lend

  • Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import...

    Java help! Please help complete the min method below in bold. import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /** * Provides an implementation of a binary search tree * with no balance constraints, implemented with linked nodes. * * * */ public class Bst<T extends Comparable<T>> implements Iterable<T> { ////////////////////////////////////////////////////////////////// // I M P L E M E N T T H E M I N M E T H O D B E L O W...

  • Q9 11 Points Let V and W be two vector spaces over R and T:V +...

    Q9 11 Points Let V and W be two vector spaces over R and T:V + W be a linear transformation. We call a linear map S: W+V a generalized inverse of Tif To SoT = T and Soto S=S. 09.1 3 Points If T is an isomorphism, show that T-1 is the unique generalized inverse of T. Please select file(s) Select file(s) Save Answer Q9.2 4 Points If S is a generalized inverse of T show that V =...

  • Please select file(s) Select file(s) Q9 Double 15 Points Consider inserting the keys 10, 22, 31,...

    Please select file(s) Select file(s) Q9 Double 15 Points Consider inserting the keys 10, 22, 31, 4, 15, 28, 17, 88, 59 into a hash table of length m 11 using open addressing with the auxiliary hash function l'(k) = k. Illustrate the result of inserting these keys using linear probing, using quadratic probing with c1 3, and using double hashing with h1(k) = k and h2(k) = 1 + (k mod (m – 1)). See Cormen p.272 1 and...

  • Q7 8 Points Let V, W, and U be three finite dimensional vector spaces over R...

    Q7 8 Points Let V, W, and U be three finite dimensional vector spaces over R and T:V + W and S : W + U be two linear transformations. Q71 4 Points Show that null(S o T) < null(T) + null(S) Please select file(s) Select file(s) Save Answer Q7.2 4 Points Show that rank(SoT) > rank(T) + rank(S) - dim(W) (Hint: Use part (1) at some point) Please select file(s) Select file(s) Save Answer

  • Question B1 You are given the following Java classes: public class Queue { private static class...

    Question B1 You are given the following Java classes: public class Queue { private static class Node { Object object; Node next; Node () { object = null; next = null; } Node (Object object, Node next) { this.object = object; this.next = next; private Node header; private int size = 0; // size shows the no of elements in queue public Object dequeue () { if (size == 0 ) { return null; else { Object remove_object = header.object;...

  • Q7 8 Points Let V, W, and U be three finite dimensional vector spaces over R...

    Q7 8 Points Let V, W, and U be three finite dimensional vector spaces over R and T:V + Wand S : W → U be two linear transformations. Q7.1 4 Points Show that null(So T) < null(T) + null(S) Please select file(s) Select file(s) Save Answer Q7.2 4 Points Show that rank(S • T) > rank(T) + rank(S) – dim(W) (Hint: Use part (1) at some point)

  • Q2 15 Points Let A € Mnxn(R). Define trace(A) = {1-1 Qiji (i. e. the sum...

    Q2 15 Points Let A € Mnxn(R). Define trace(A) = {1-1 Qiji (i. e. the sum of the diagonal entries) and tr : Mnxn(R) +R, A H trace(A). Q2.1 2 Points Show that U = {A € Mnxn(R): trace(A) = 0} is a subspace of Mnxn (R). Please select file(s) Select file(s) Q2.2 4 Points Compute dim(im(tr)) Enter your answer here and dim(ker(tt) Enter your answer here each (1pt) Justify your answer. (2pt) Enter your answer here Q2.3 5 Points...

  • Q2 15 Points Let n E N and A € Mnxn(R). Define trace(A) = 21=1 Qişi...

    Q2 15 Points Let n E N and A € Mnxn(R). Define trace(A) = 21=1 Qişi (i. e. the sum of the diagonal entries) and tr : Mnxn(R) +R, A H trace(A). Q2.3 5 Points Find a basis for ker(tr) and verify that it is in fact a basis. Please select file(s) Select file(s) Save Answer Q2.4 3 Points Show that for any A € Mnxn(R) there is B e ker(tr) and a € R such that A = B+a....

  • package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values...

    package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values * * Complete each function below. * Write each function as a separate recursive definition (do not use more than one helper per function). * Depth of root==0. * Height of leaf==0. * Size of empty tree==0. * Height of empty tree=-1. * * TODO: complete the functions in this file. * DO NOT change the Node class. * DO NOT change the name...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT