SE250:lab-6:rbha033

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (14 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Lab 6

Task 1

This task took a very long time to get done, possibly because of the trial and error method used to try and display the data in the best possible way.

Here's the Code:

int main(){
	int h,i;
	Node *node = 0;
	for(i=0; i<250; i++){
		node = makeRandomTree(i);
		h= height(node);
		printf("%d\n", h);
	}
	return 0;
}

Here are the results plotted: <html><img src=http://www.geocities.com/racbhat13/Untitled.jpg></html>

Task 2

Here's the code:

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

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

int main(void){
	Node *node, *max, *min;
	int minKey, maxKey, rootKey;
	for (i=1; i<100; i=i*2){
		node = makeRandomTree(15);
		rootKey = node ->key;
		min = minimum(node);
		minKey = min->key;
		max = maximum(node);
		maxKey = max->key;
		printf( "I = %d: Min = %d, Root = %d, Max = %d\n", i, minKey, rootKey, maxKey);
	}
	return 0;
}

Here are the Results:

H:\SoftEng250\Lab 6>lab6
I = 1: Min = 41, Root = 41, Max = 29358
I = 2: Min = 153, Root = 491, Max = 32391
I = 4: Min = 1869, Root = 5447, Max = 31322
I = 8: Min = 778, Root = 4664, Max = 32757
I = 16: Min = 288, Root = 12316, Max = 30106
I = 32: Min = 3548, Root = 15350, Max = 31101
I = 64: Min = 2082, Root = 16944, Max = 32439

Task 3

Task 4

Task 5

Task 6