SE250:lab-6:vpup001

From Marks Wiki
Jump to navigation Jump to search

This lab is about binary search trees. I don't think I am going to finish this lab. I had an error with my code and it took me ages to fix it. It did not work in visual studio so I had to use the GNU command. When we call the makeRandomTree function in the main file...

Node *node = makeRandomTree( 10 );

I took the lecturer's help. I had it as "Node* node = makeRandomTree( 10 );" at the beginning so it did not work I guess but I don't know the difference between them and I am not really sure if that was the error

  • What is the difference between 'Node *node' and 'Node* node'?

I have done a graph in Excel by changing the value of size. I have chosen a scale of 10 because I realized that taking 5 does not make much difference to height. I have chosen the value of height ranging from 0 to 200 (went up by 10) and I have also done 250 and 300 because the height from 170 to 200 was the same and I wanted to see if it changes and it did. You can see the graph in the link below. Excel Graph(Height vs Size)

I am onto task 2 now. In the minimum function we look at the left child and return it if its not empty and if there is no left child we return the node. We do the same thing for the maximum function we look at the right child and return it if its not empty and if there is no right child we return the node.

This is my code for minimum...

Node* minimum( Node* node ) {
  	 while (node->left != empty){
              node = node->left;
        }
        return node;
}

So, it looks at the left child(since it is the minimum) and it returns it and if there is no left child it returns the node. This is my code for maximum...

Node* maximum( Node* node ) {
  	while (node->right != empty){
             node = node->right;
       }
       return node;
}

So, it looks at the right child(since it is the maximum) and it returns it and if there is no right child it returns the node.