Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i complete the question use this one the first one i forger somthing Q: 3. A) Given the program trace the insertion function to complete

image text in transcribed
image text in transcribed
image text in transcribed
i complete the question use this one the first one i forger somthing image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Q: 3. A) Given the program trace the insertion function to complete the tree below. (10 pts) 18 #include #include struct node int data; struct node *leftChild; struct node "rightChild; }; struct node *root NULL; void insert(int data) struct node *tempNode = (struct node*) malloc(sizeof(struct node)); struct node *current; struct node *parent; tempNode->data data; tempNode->leftChild = NULL; tempNode->rightChild = NULL; //if tree is empty if (root = NULL) { root = tempNode; } else current = root; parent = NULL; while (1) parent -current; //go to left of the tree if (data data) current current- >leftChild; //insert to the left if (current = NULL) parent->left Child if (root != NULL) post_order_traversal (root- >leftChild); post_order_traversal (root- >rightChild); printf("d", root->data); } int main() { int i; int array[7] = { 18, 27, 42, 31, 19, 10, 35, 14); for (i = 0; i data); printf(" "); Jelse printf("x 1 Element not found (d). ", i); 1 i 15; temp - search(i); if(temp != NULL) printf("%d) Element found.", temp->data); printf(" "); Helse printf("X) Element not found (d). ", 1); } printf(" Preorder traversal: "); pre_order_traversal (root); printf(" Inorder traversal: "); inorder_traversal (root); printf (" Post order traversal: "); printf("%d) Element found.", temp->data); printf(" "); }else{ printf(" * ] Element not found (id). ", i); i = 15; temp - search(i); if (temp ! - NULL) printf("%d) Element found.", temp->data); printf(" "); else printf("X1 Element not found (d). ", i); printf(" Preorder traversal: "); pre_order_traversal (root); printf(" inorder traversal: "); inorder_traversal (root); printf(" Post order traversal: "); post_order_traversal (root); return 0; Q: 3. B) After you complete the tree trace search algorithm to find 31 and 15. You should print which nodes were visited to find or search for them. (15 pts) Q: 3. C) Trace the postorder traversal, preorder traversal and inorder traversal functions to print the postorder, preorder and inorder outputs. (15 pts) Q: 3. A) Given the program trace the insertion function to complete the tree below. (10 pts) 18 #include #include struct node int data; struct node *leftChild; struct node *rightChild; hi struct node *root = NULL; void insert(int data) struct node *tempNode = (struct node*) malloc(sizeof(struct node)); struct node *current; struct node *parent; tempNode->data data; tempNode->leftchild = NULL; tempNode->rightChild - NULL; //if tree is empty if (root == NULL) { root = tempNode; } else current = root; parent = NULL; while (1) parent = current; //go to left of the tree if (data data) current = current- >left Child; //insert to the left if (current = NULL) parent->leftChild tempNode; return; 1 }//go to right of the tree else current current >rightChild; //insert to the right if (current == NULL) parent->rightChild tempNode; return; struct node* search int data) struct node *current - root; printf("Visiting elements: "); while (current->data data) if (current != NULL) printf("d", current->data); //go to left tree if (current->data > data) current = current->leftChild; //else go to right tree else current = current->rightChild; > /ot found if (current == NULL) { return NULL; return current; void pre_order_traversal (struct node* root) if (root != NULL) printf("%d", root->data); pre_order_traversal (root- >leftChild); pre_order_traversal (root- >rightChild); 1 void inorder_traversal (struct node* root) if (root != NULL) inorder_traversal (root- >leftchild); printf("%d", root->data); inorder_traversal (root->rightChild): void post_order_traversal (struct node root) if (root != NULL) post_order_traversal (root- >leftChild); post_order_traversal (root- >rightChild); printf("d", root->data); } int main() int i; int array(71 10, 35, 14); = { 18, 27, 42, 31, 19, for (i = 0; i data) printf(" "); Helse printf("[ X ] Element not found (d) . ", i); printf("%d) Element found.", temp->data); printf(" "); }else{ printf(" * ] Element not found (id). ", i); i = 15; temp - search(i); if (temp ! - NULL) printf("%d) Element found.", temp->data); printf(" "); else printf("X1 Element not found (d). ", i); printf(" Preorder traversal: "); pre_order_traversal (root); printf(" inorder traversal: "); inorder_traversal (root); printf(" Post order traversal: "); post_order_traversal (root); return 0; Q: 3. B) After you complete the tree trace search algorithm to find 31 and 15. You should print which nodes were visited to find or search for them. (15 pts) Q: 3. C) Trace the postorder traversal, preorder traversal and inorder traversal functions to print the postorder, preorder and inorder outputs. (15 pts)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago