Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview: This project is for testing the use of binary search trees and files. In this assignment, you will be using a binary search tree

Overview: This project is for testing the use of binary search trees and files. In this assignment, you will be using a binary search tree to gather information about the frequency of letter distributions in a file.

Project: Your program will open a file containing a dump of text and build a binary tree for the frequencies of characters. For example, in the string cadabcdaa, the frequencies of characters are: a: 4 b: 1 c: 2 d: 2

And the corresponding binary tree will be:

image text in transcribed

Notice that the tree is sorted by the order of characters and not the numbers. For example, since c was observed first, it is made the root node.

Output: Once your program is done, do an inorder traversal of the tree, outputting the data in the following format: a : 4 b : 1 c : 2 d : 2

Additional Notes: (1) Ignore any characters (including newlines) other than alphabets (a to z and A to Z). (2) Ensure that any file handling errors are dealt with, such as the file not existing or a read not working.

In case you had no idea where to start, below is a sample code structure:

struct node{ char character; int count; node *left; node *right; } void add_node(char character){ // ToDo } void print_inorder(){ // ToDo } // Note: You may also create a class called BTree and have all the functions inside. int main (){ // ... // Create a tree root // Read file character by character and build the tree // call print_inorder(); // ... }
C 2 a 4 d 2 b 1

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

When does the stated amount of a liability equal its present value?

Answered: 1 week ago

Question

What is conservative approach ?

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago

Question

How could assessment be used in an employee development program?

Answered: 1 week ago