Home / Expert Answers / Computer Science / bst-exercise-1-in-this-exercise-we-will-take-some-basic-bst-properties-and-start-to-write-some-r-pa111

(Solved): BST exercise #1 In this exercise, we will take some basic BST properties and start to write some R ...



BST exercise #1
In this exercise, we will take some basic BST properties and start to write some Racket code to implement BSTNow call the node constructor, and bind the result to a named symbol. Note that we need to build the nodes from the bottom

BST exercise #1 In this exercise, we will take some basic BST properties and start to write some Racket code to implement BSTs and some of the functions to operate on them. We will work on other functions in the next exercises, and eventually combine all the functions into the finished project. Struct Definition for BST Node (struct node (value count left right) #:mutable #:transparent) The name of the struct is "node" and there are four fields: value, count, left, right. The following functions are created automatically by Racket in support of the struct definition. - Test for membership: (node? n) - Constructor: (node v c|r) - Field Accessors: (node-value n), (node-count n), (node-left n), (node-right \( n \) ) - Field Mutators: (set-node-value! n v), (set-node-count! n c), (set-node-left! n l), (set-node-right! n r) Symbolic names for all functions are derived from name of the struct and name of its fields, as defined by you. Note that characters like "?" and "!" are not special characters in Racket, they are just part of the regular character set and can be used as part of the name of a symbol or function. Before we can write any functions we can manually define a tree for testing. Here I show how to create a BST and give symbolic names to each node, then build the tree in Racket using only the node constructor, starting at the bottom and working up to the root. This creates an actual BST in Racket that will be useful for testing our functions as we get them written. After we write a definition of the "insert" function, we won't need to build trees manually. But until "insert" is written, these manually built trees will be useful for testing. Here's a sketch of a typical BST, this one with 10 nodes. Each node has been labeled with the symbolic name we will use for it. Now call the "node" constructor, and bind the result to a named symbol. Note that we need to build the nodes from the bottom up so that node names are defined before we use them as links in another node. (define \( \mathrm{n} 10 \) (node 701 null null)) (define n09 (node 651 null n10)) (define n08 (node 301 null null)) (define n07 (node 871 null null)) (define n06 (node 601 null n09)) (define n05 (node 371 n08 null)) (define n04 (node 121 null null)) (define n03 (node 751 n06 n07)) (define n01 (node 501 n02 n03)) You can try some simple test cases here based on the nodes you just defined. \( \begin{array}{ll}\text { (node? n10) } & ; \text { test for membership for node } \mathrm{n} 10 \\ \text { (node-value } \mathrm{n} 10) & ; \text { access of value field of node } \mathrm{n} 10 \\ \text { (node-count n08) } & ; \text { access of count field of node } \mathrm{n} 08\end{array} \)


We have an Answer from Expert

View Expert Answer

Expert Answer


#include using namespace std; struct BST { int value; int count; BST *left, *right; // Default constructor. BST(); // Parameterized constru
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe