SE250:lab-6:srag014

From Marks Wiki
Jump to navigation Jump to search

Lab 6

This lab's all about trees. Started off by recapping the theory behind them....

Task 1

The first task was to do an experiment to measure the expected height of a binary search tree constructed by inserting elements in a random order.This task took me a while to do as I was a bit lost on where to start, in the end with some help, I managed to figure out that we had to use the makeRandomtree and use a for loop too.The relationship I derived from my graph was height is directly proportional to the size (roughly). Note: Had difficulty uploading graph, will do it later.

Task 2

The second task was to implement the maximum and minimum function. This task wasnt too bad as the theory behind it is fairly easy. The minimum value is the leftmost value and the max is the rightmost.

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

Task3

The third task was to implement the lookup function.