Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sixth: Binary Search Tree (20 points) In the sixth part, you have to implement a binary search tree. The tree must satisfy the binary search

Sixth: Binary Search Tree (20 points)

In the sixth part, you have to implement a binary search tree. The tree must satisfy the binary search tree property: the key in each node must be greater than all keys stored in the left sub-tree, and smaller than all keys in right sub-tree. You have to dynamically allocate space for each node and free the space for the nodes at the end of the program.

Input format: This program takes a file name as an argument from the command line. The file is either blank or contains successive lines of input. Each line starts with a character, either i, followed by a tab and then an integer. Your program should insert that number in the binary search tree if it is not already there. If it is already present, you will not change the tree.

Output format: Your program will print all the elements in the tree in ascending order. To print elements in ascending order, you will need to traverse the tree in-order. In an in-order traversal you will visit the left child, then the parent and the right child. You can find more information about in-order traversal at: https://en.wikipedia.org/wiki/Tree_traversal#In-order_(LNR) The elements have to be printed in a single line separated by tabs. Your program should print error (and nothing else) if the input file does not exist.

Example Execution:

Lets assume we have a file file1.txt with the following contents:

i 5

i 3

i 4

i 3

i 6

Executing the program in the following fashion should produce the output shown below:

$./sixth file1.txt

3 4 5 6

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

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

Students also viewed these Databases questions

Question

8. Demonstrate aspects of assessing group performance

Answered: 1 week ago