Scheme of valuvation 1 What is a Binary tree? State its properties? How it is represented using array and linked list, give example. binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child. 1) The maximum number of nodes at level l of a binary tree is 2 l-1. 2) Maximum number of nodes in a binary tree of height h is 2 h 1. Array and linked list representation 2 Describe the Binary search tree with an example. Write the recursive function to search for a key value in binary search tree. Example with explanation struct node* search(struct node* root, int key) // Base Cases: root is null or key is present at root if (root == NULL root->key == key) return root; 2+2+2+2 4+4 3 4 // Key is greater than root's key if (root->key < key) return search(root->right, key); // Key is smaller than root's key return search(root->left, key); Write the functions to traverse a given tree using (i) inorder (ii) Postorder (iii)preorder. algorithm Inorder(tree) 1. Traverse the left subtree, i.e., call Inorder(left-subtree) 2. Visit the root. 3. Traverse the right subtree, i.e., call Inorder(right-subtree) Algorithm Preorder(tree) 1. Visit the root. 2. Traverse the left subtree, i.e., call Preorder(left-subtree) 3. Traverse the right subtree, i.e., call Preorder(right-subtree) Algorithm Postorder(tree) 1. Traverse the left subtree, i.e., call Postorder(left-subtree) 2. Traverse the right subtree, i.e., call Postorder(right-subtree) 3. Visit the root. example Write a function in c to delete a node from a given Binary search tree considering all the cases. Given a binary search tree and a key, this function deletes the key and returns the new root */ struct node* deletenode(struct node* root, int key) // base case if (root == NULL) return root; // If the key to be deleted is smaller than the root's key, // then it lies in left subtree if (key < root->key) root->left = deletenode(root->left, key); 2+2+2+2
// If the key to be deleted is greater than the root's key, // then it lies in right subtree else if (key > root->key) root->right = deletenode(root->right, key); // if key is same as root's key, then This is the node // to be deleted else // node with only one child or no child if (root->left == NULL) struct node *temp = root->right; free(root); return temp; else if (root->right == NULL) struct node *temp = root->left; free(root); return temp; // node with two children: Get the inorder successor (smallest // in the right subtree) struct node* temp = minvaluenode(root->right); // Copy the inorder successor's content to this node root->key = temp->key; // Delete the inorder successor root->right = deletenode(root->right, temp->key); return root; 5 Write a node structure for the linked representation of Polynomial. Write a function to add 2 Polynomials represented using Linked list. struct Node int coeff; int pow; struct Node *next; ; 2+6 void polyadd(struct Node *poly1, struct Node *poly2, struct Node *poly) while(poly1->next && poly2->next) // If power of 1st polynomial is greater then 2nd, then store 1st as it is // and move its pointer if(poly1->pow > poly2->pow) poly->coeff = poly1->coeff;
6 7 // If power of 2nd polynomial is greater then 1st, then store 2nd as it is // and move its pointer else if(poly1->pow < poly2->pow) poly->pow = poly2->pow; poly->coeff = poly2->coeff; // If power of both polynomial numbers is same then add their coefficients else poly->coeff = poly1->coeff+poly2->coeff; // Dynamically create new node poly->next = (struct Node *)malloc(sizeof(struct Node)); poly = poly->next; poly->next = NULL; while(poly1->next poly2->next) if(poly1->next) poly->coeff = poly1->coeff; if(poly2->next) poly->pow = poly2->pow; poly->coeff = poly2->coeff; poly->next = (struct Node *)malloc(sizeof(struct Node)); poly = poly->next; poly->next = NULL; What is Depth First Search?.Write a program to print all the nodes reachable from a vertex using dfs. DFS algorithm is to traverse the graph in such a way that it tries to go far from the root node. Stack is used in the implementation of the depth first search. void dfs(int v) int i; visited[v]=1; for(i=1;i<=n;i++) if(a[v][i] == 1&& visited[i] == 0 ) 2+6
printf("%d ", i); dfs(i); 9 10.What is graph? Give the matrix and adjacent list representation of graph? Graph: A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges. 2 ways of representation 1.Adjacency list 2.Adjacency Matrix explanation with example. Write an algorithm for insertion sort.also trace the algorithm for the data 30, 20, 10, 40, 50, 60, 70. def insertionsort(alist): for index in range(1,len(alist)): currentvalue = alist[index] position = index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position = position-1 alist[position]=currentvalue alist = [54,26,93,17,77,31,44,55,20] insertionsort(alist) print(alist) Briefly explain the basic operations that can be performed on a file. Explain indexed Sequential file organization. File operations Explanation for indexed sequential with example What is hashing? Explain the different collision resolution techniques with example? Definition Linear probing&chaining explanation 2+3+3 4+4 2+3+3