SE250:lab-6:hlin079

From Marks Wiki
Jump to navigation Jump to search

task1

int main(){
    int i;
    for (i=1;i<100;i++){
	printf("%d\n",height(makeRandomTree(i)));

    }
}

I used a for loop to increase the size of the tree from 1 to99. After that I measured the height of each tree. I used Excel to plot the graph to find the relationship between height of the tree and the size of tree. The graph for that is on: http://img208.imageshack.us/img208/1999/40449269bf1.jpg I used another for loop to increase the size of tree from 1 to 10000. I plotted the graph for that as well, I found that the height for the much greater size of binary tree (I e. 10000) is not much higher the height of the smaller size of the binary tree (ie.98).

task2

Node* minimum( Node* node ) {
    if (node==empty){
	return empty;
    }
    for (; node->left !=empty;node=node->left){
    }
    return node;
}
}
Node* maximum( Node* node ) {
 if (node==empty){
	return empty;
    }
    for (; node->right!=empty;node=node->right){
	return node;
    }
}