Purchase Solution

Implementing Operations on Binary Trees

Not what you're looking for?

Ask Custom Question

Consider the following definition of a Binary Tree structure:

typedef struct BTnode *node;
struct BTnode {
int key;
node left;
node right;
};

1. Write a function in C programming language that can find and return the height of a Binary Tree.
2. Write a function in C programming language that can find and return the cost of the most expensive path from the root of a Binary Tree to a leaf.
3. Write a function in C programming language that finds if a particular Binary Tree is balanced.

More explanations are provided in the attached document.

Purchase this Solution

Solution Summary

Attached solution contains just the function implementations. Code has been commented well, but even without that logic is quite clear as it is based on recursion. This implementation makes use of an auxiliary function min_height in determining whether a tree is balanced as per the given criteria or not.

Solution Preview

Please find attached 450363.c containing just the function implementations. Code has been commented well, but even without that logic is quite clear as it is based on recursion. This implementation makes use of an auxiliary function min_height in determining whether a tree is balanced as per the given criteria or not.

#include <stdio.h>

/* Binary Tree structure */

typedef struct BTnode *node;
struct BTnode {
int key;
node left;
node right;
};

/*
* This function finds and returns the height of a Binary Tree.
*
* The height of a binary tree is the length of the longest path from root of
* the Binary Tree to a leaf.
*
* This implementation considers that the height of a null tree is 0 and that of
* a single node tree is 1.
*/

int height (node root)
{
if (root == (node) NULL)
return 0;
else
{
...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.