Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a bst with int values. Generate 1000 random numbers in the bst, Don\'t in

ID: 3622300 • Letter: C

Question

Create a bst with int values. Generate 1000 random numbers in the bst, Don't insert duplicates. Now we want to find which inorder traversal is better.Use start=clock(); //code to check speed end=clock(); output the difference. #include ctime at the beginning.Which inorder traversal method is faster?

Explanation / Answer

//here is one of the inorder traversal in c code that will traverse and give the number of clock ticks to execute it. #include #include #include typedef struct bnode{ int key; struct bnode* left; struct bnode* right; }BNODE; void printKeysReverse(BNODE* current); void inorder(BNODE* current); void insert(BNODE **root,int key); int search(BNODE *root,int num) { if(root == NULL) return 0; if(root->key == num ) return 1; else if(num key) return search(root->left,num); else return search(root->right,num); } int main(void){ BNODE* root=NULL; int num=0; int i; for(i=0;iright=NULL; newnode->left=NULL; if ((*root)==NULL){ *root=newnode; (*root)->key=val; return; } if (valkey) insert(&(*root)->left,val); else insert(&(*root)->right,val); }//end void inorder(BNODE *root){ if (root==NULL) return ; inorder(root->left); // printf("%d ",root->key); inorder(root->right); }//end inorder