100 likes | 171 Views
Question 1. (a) Student Folding Computed Actual Number Address Address 98003446 187 7 7 98018241 285 5 5 98019602 305 5 5->6 98137942 592 2 2 98158891 796 6 6->7->8 . Question 1. (b) Average = (1 + 1 + 2 + 1 + 3) / 5 = 1.6
E N D
Question 1 (a) Student Folding Computed Actual Number Address Address 98003446 187 7 7 98018241 285 5 5 98019602 305 5 5->6 98137942 592 2 2 98158891 796 6 6->7->8
Question 1 (b) Average = (1 + 1 + 2 + 1 + 3) / 5 = 1.6 (c)Since each cell in the table is eventually probed, if the table is not full, the collision can be resolved. (d) Similar to quadratic probing, all elements that hash to the same location will try the same collision resolution sequence. Thus secondary clustering problem cannot be resolved. But primary clustering problem similar to linear probing will not occur because there is no difference between records that hash to neighbouring and distant cells.
Question 2 Convert the infix expression, A^B*C-D+E/F/(G+H), into postfix expression Answer: AB^C*D-EF/GH+/+
Expression tree + - / * D + / C ^ F E G H A B
Question 3 A strictly binary tree is one that every non-leaf node has non-empty left and right subtrees. Write a recursive algorithm to determine if a binary tree is strictly binary or not. Assume the following data structure is given struct node { struct node *left; int info; struct node *right; };
Question 3 int binary (nodeptr root) { if (root!=NULL) if((root->left!= NULL && root-> right == NULL) || (root->left == NULL && root-> right !=NULL)) return (0); else return(binary(root->left) * binary(root->right)); else return (1); } Answer
Question 4 Sum=0; for (j=0;j<N;j++) for (k=0;k<N*N;k++) Sum++; Answer: NxN2 = N3
Question 4 Sum=0; for (j=0;j<N;j++) for (k=0;k<j;k++) Sum++; Answer: 1 + 2 + 3 +…. + (N-1) = N(N-1)/2
Question 5 Show and describe how to implement three stacks in one array Answer: - one from bottom up - one from top down - one from middle
Question 5 Show and describe how to implement three stacks in one array - if third stack collides with either one => needs to move - one reasonable strategy: move it so that its center is halfway between tops of two stacks