Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structure in C++ In this assignment you're going to implement splay trees, and then re-use some of your code from assignment 1 to create

Data Structure in C++

image text in transcribed

In this assignment you're going to implement splay trees, and then re-use some of your code from assignment 1 to create a tree register machine, a machine with four registers whose values are search trees. Implement AVL trees (with parent pointers). Implement it as a binary search tree with integer keys (i.e., an ordered set). Your nodes should have type struct node {int key; node* left; node right node parent; int height;}; Note that maintaining parent pointers complicates some of the algorithms I would suggest implementing the basic. unbalanced BST operations first, and then adding the parent pointers and making sure everything still works, and finally adding the balancing code You must implement the following tree operations: node * & find (node * & root, int value); void insert(node *& root, int value); void remove (node *& root, int value); void print(std::ostream& out, node* root) node *merge (node* 1, node* t2); boo1 Be sure to correctly handle the case where (i.e.. the empty tree)! Depending on how you feel about references vs. pointers. you might prefer to change the & (reference to pointer) parameters to (double-pointer). A single pointer will not suffice, however. The print function is mostly for your convenience in testing your code: you can print your trees in any format you'd like, though Id suggest using an in order traversal. as that will print the elements of the tree in numerical order (hopefully!). Likewise, the check function should return true if the tree has the correct tree structure (ordering, pointers connected correctly. etc.) To "merge" two trees, you can simply insert all the nodes of one into the other. although there are more efficient ways of doing it... In this assignment you're going to implement splay trees, and then re-use some of your code from assignment 1 to create a tree register machine, a machine with four registers whose values are search trees. Implement AVL trees (with parent pointers). Implement it as a binary search tree with integer keys (i.e., an ordered set). Your nodes should have type struct node {int key; node* left; node right node parent; int height;}; Note that maintaining parent pointers complicates some of the algorithms I would suggest implementing the basic. unbalanced BST operations first, and then adding the parent pointers and making sure everything still works, and finally adding the balancing code You must implement the following tree operations: node * & find (node * & root, int value); void insert(node *& root, int value); void remove (node *& root, int value); void print(std::ostream& out, node* root) node *merge (node* 1, node* t2); boo1 Be sure to correctly handle the case where (i.e.. the empty tree)! Depending on how you feel about references vs. pointers. you might prefer to change the & (reference to pointer) parameters to (double-pointer). A single pointer will not suffice, however. The print function is mostly for your convenience in testing your code: you can print your trees in any format you'd like, though Id suggest using an in order traversal. as that will print the elements of the tree in numerical order (hopefully!). Likewise, the check function should return true if the tree has the correct tree structure (ordering, pointers connected correctly. etc.) To "merge" two trees, you can simply insert all the nodes of one into the other. although there are more efficient ways of doing it

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

More Books

Students also viewed these Databases questions