Knowledge check.
- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[j+1]=arr[max];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
Temp = SortArray[j];
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->left,temp);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(stack[ARRAY_SIZE] == StackTop-1)
{
printf("Stack overflow");
return;
}
StackTop =StackTop +1;
stack[StackTop]=input;
}
int Pop(int input)
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop = StackTop -1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
StackTop=StackTop-1;
TopValue=stack[StackTop];
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
}
HeapArry[i]=tmp;
i=i/2;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=mid; k< =j; k++)
{
temp[j]=arr[k];
k++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data > node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else if(arr[j]!=arr[m])
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else if(data != node->data)
{
node->right = DeleteNode(node, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex] = newnode->next;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[j+1];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->left;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==node->left)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=StackTop;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
queue[front]=rear;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode->next = hashTable[0].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
low = (mid + high) % 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
Temp = SortArray[j];
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
mid=(min+max)/2;
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop = ARRAY_SIZE;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop =StackTop+1;
stack[StackTop]=input;
}
int Pop(int input)
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop =StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
rear = rear->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[m];
m++;
}
else
{
temp[i]=arr[j];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear++]=input;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front++];
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->left,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be removed to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
myNode->next=temp;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
temp->next=front->next;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> left = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]==arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right =node->left;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
int queue[ARRAY_SIZE], rear=0, front=0;
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[rear++];
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i+1]=arry[j+1];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,tmp,1);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i!=1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else if(node->left)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j+1];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node == NULL)
node = node->left;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
hashTable[hashIndex].head = myNode->next;
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
free(temp);
front = front->next;
input=temp->Data;
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
temp->left=InsertNode(node,input);
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==value)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
else high=low/2;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
temp[i]=arr[j];
j++;
if(arr[j]< =arr[m])
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
while(i!=0)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
else if(data == (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j] !=arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp -> left = temp -> right = NULL;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->left == NULL)
node=temp->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>size)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[temp]=arry[j+1];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]< arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
StackTop=TopVal;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE - 1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop-1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->right);
printf("%d ",node->data);
PrintPostorder(node->left);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
temp->next=front;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[ARRAY_SIZE]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp->next;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear->next=NULL;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
queue[rear]=front;
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else if(node->right)
return FindMin(node->right);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
queue[rear]=input;
rear=rear+1;
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop(int input);
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop =StackTop+1;
stack[StackTop]=input;
}
int Pop(int input)
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop =StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->left);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->right == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
arry[pivot]=arry[j];
arry[j]=temp;
temp=arry[pivot];
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return node;
else
return FindMin(node->left);
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
{
printf("Value is found \n");
}
{
printf("Value is not present in the list \n");
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = key;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[ARRAY_SIZE]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==node->right)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
StackTop=StackTop-1;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[j] = SortArray[j + 1];
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE];
int rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = newnode->key;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) - 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=front+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]!=arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]||i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value != SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
return;
}
if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int StackTop;
int stack[StackTop];
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
arry[i]=arry[j];
temp=arry[i];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==node->right)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push();
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push()
{
if(StackTop==ARRAY_SIZE - 1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop + 1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop - 1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == myNode->next)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
rear=rear+1;
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
HeapArry[i/2]=tmp;
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be removed to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].head->next = newnode->next;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
if(arry[i]!=arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==rear)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
rear=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=input;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
{
node=node->left;
return FindMin(node->left);
}
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i+1];
i++;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
{
high = mid - 1;
low = mid - 1;
}
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[mid]=arr[max];
j--;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be removed to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
newnode->next = hashTable[hashIndex].head;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==queue[front])
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
rear=front+1;
printf("%d ",queue[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == temp->next->data)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
arry[i+1]=arry[j];
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMin(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
stack[++StackTop]=ARRAY_SIZE;
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->right = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->left, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=rear;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=rear;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[size/2]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
StackTop=StackTop - 1;
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[i+1] = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = SortArray[NumOfValues];
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
rear=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]!=arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
temp->next=StackTop;
StackTop=temp;
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[i] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
queue[rear]=value;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid - 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(stack[ARRAY_SIZE]==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be reordered and corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
rear=front+1;
queue[front]=input;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
StackTop=temp;
StackTop->next=NULL;
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=rear;
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->right);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be added to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
stack[++StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode->next = hashTable[hashIndex].head->next;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
i++;
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE];
int rear=front=ARRAY_SIZE;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be reordered to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
stack[StackTop]=input;
StackTop=StackTop+1;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(temp->left));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop+1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop=StackTop-1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = Node->next;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]!=HeapArry[j+1]))
size++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
SortArray[i] = SortArray[j + 1];
Temp = SortArray[i];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
{
temp[i]=arr[j];
j++;
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered and corrected to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[i] = SortArray[i + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
high = mid - 1;
if (value < SortArray[mid])
mid = (low + high) - 2;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
{
node->right = InsertNode(node->right,data);
}
if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=temp->next;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=rear+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE - 1)
{
printf("Stack overflow");
return;
}
StackTop=StackTop + 1;
stack[StackTop]=input;
}
int Pop()
{
int TopValue;
if(StackTop== ARRAY_SIZE - 1)
{
printf("Stack is empty");
return -1;
}
TopValue = stack[StackTop];
StackTop=StackTop - 1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
if (SortArray[j] > SortArray[j + 1])
{
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
front=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[++rear]=input;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
front=front+1;
value=queue[front];
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
if(arry[i]==arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=front->next;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
MergeLists(arr,min,mid,max);
Split(arr,mid+1,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int rear=0, front=0;
int queue[front];
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=temp+1;
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
temp=temp->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == front)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i!= j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[pivot+1]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be corrected to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct hash *)malloc(sizeof(struct hash));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
front = front->next;
input=temp->Data;
free(temp);
return input;
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be removed to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
{
myNode->next=temp;
hashTable[hashIndex].head = myNode->next;
}
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be removed to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
StackTop=StackTop->next;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)/2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
|
|
|
|
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==TopVal)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the MergeSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void MergeLists(int *arry,int ,int ,int );
void Split(int *arry,int ,int );
int main()
{
int arr[30];
int i,size;
printf("Enter number of elements : \n");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=0; i< size; i++)
{
scanf("%d",&arr[i]);
}
Split(arr,0,size-1);
printf("\nSorted list : ");
for(i=0; i< size; i++)
printf("%d ",arr[i]);
getch();
return 0;
}
void Split(int *arr,int min,int max)
{
int mid;
if(min< max)
{
mid=(min+max)%2;
Split(arr,min,mid);
Split(arr,mid+1,max);
MergeLists(arr,min,mid,max);
}
}
void MergeLists(int *arr,int min,int mid,int max)
{
int temp[30];
int i,j,k,m;
j=min;
m=mid+1;
for(i=min; j< =mid && m< =max ; i++)
{
if(arr[j]< =arr[m])
{
temp[i]=arr[j];
j++;
}
else
{
temp[i]=arr[m];
m++;
}
}
if(j>mid)
{
for(k=m; k< =max; k++)
{
temp[i]=arr[k];
i++;
}
}
else
{
for(k=j; k< =mid; k++)
{
temp[i]=arr[k];
i++;
}
}
for(k=min; k< =max; k++)
arr[k]=temp[k];
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
rear->next=NULL;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j==size)||(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
{
HeapArry[j+1]=HeapArry[tmp];
break;
}
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in program should be reordered to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
struct node *newnode = CreateNode(key, name, mark);
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
newnode->next = (hashTable[hashIndex].head);
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
int stack[ARRAY_SIZE];
int StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
if(StackTop==ARRAY_SIZE-1)
{
printf("Stack overflow");
return;
}
StackTop =StackTop +1;
stack[StackTop]=input;
}
int Pop(int input)
{
int TopValue;
if(StackTop==-1)
{
printf("Stack is empty");
return -1;
}
TopValue=stack[StackTop];
StackTop = ARRAY_SIZE -1;
return TopValue;
}
void Display()
{
int i;
printf("\nStack Elements:");
for(i=0; i< =StackTop; i++)
{
printf("%d ",stack[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=input;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to implement a Hash table using linked lists which contains the operations Insertion, Deletion and Searching a key value. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct node
{
int key,Mark;
char name[100];
struct node *next;
};
struct hash
{
struct node *head;
int count;
};
struct hash *hashTable = NULL;
int ElementCount = 0;
struct node * CreateNode(int key, char *name, int mark);
void InsertToTable(int key, char *name, int mark);
void DeleteFromTable(int key);
void SearchElement(int key);
void DisplayTable();
void main()
{
int NumOfElements, choice, key, mark;
char name[100];
printf("Enter the number of elements:");
scanf("%d", &NumOfElements);
ElementCount = NumOfElements;
hashTable = (struct hash *)calloc(NumOfElements, sizeof (struct hash));
InsertToTable(1001,"Stella",99);
InsertToTable(1002,"Jenn",88);
InsertToTable(1003,"Alli",90);
DeleteFromTable(1002);
SearchElement(1003);
DisplayTable();
}
struct node * CreateNode(int key, char *name, int mark)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->Mark = mark;
strcpy(newnode->name, name);
newnode->next = NULL;
return newnode;
}
void InsertToTable(int key, char *name, int mark)
{
int hashIndex = key % ElementCount;
struct node *newnode = CreateNode(key, name, mark);
if (!hashTable[hashIndex].head)
{
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count = 1;
return;
}
hashTable[hashIndex].head = newnode;
hashTable[hashIndex].count++;
return;
}
void DeleteFromTable(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *temp, *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Given input is not present in hash Table\n");
return;
}
temp = myNode;
while (myNode != NULL)
{
if (myNode->key == key)
{
flag = 1;
if (myNode == hashTable[hashIndex].head)
hashTable[hashIndex].head = myNode->next;
else
temp->next = myNode->next;
hashTable[hashIndex].count--;
free(myNode);
break;
}
temp = myNode;
myNode = myNode->next;
}
if (flag)
printf("Data is deleted from Hash Table\n");
else
printf("Given data is not present in Hash table\n");
return;
}
void SearchElement(int key)
{
int hashIndex = key % ElementCount;
int flag = 0;
struct node *myNode;
myNode = hashTable[hashIndex].head;
if (!myNode)
{
printf("Element is not found in the table \n");
return;
}
while (myNode != NULL)
{
if (myNode->key == key)
{
printf("StudentID : %d\n", myNode->key);
printf("Name : %s\n", myNode->name);
printf("Mark : %d\n", myNode->Mark);
flag = 1;
break;
}
myNode = myNode->next;
}
if (!flag)
printf("Element unavailable in hash table\n");
return;
}
void DisplayTable()
{
struct node *myNode;
int i;
for (i = 0; i < ElementCount; i++)
{
if (hashTable[i].count == 0)
continue;
myNode = hashTable[i].head;
if (!myNode)
continue;
printf("\nData at index %d :\n", i);
printf("StudentID Name Mark \n");
while (myNode != NULL)
{
printf("%-12d", myNode->key);
printf("%-15s", myNode->name);
printf("%d\n", myNode->Mark);
myNode = myNode->next;
}
}
return;
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be removed to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
node=node->right;
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
struct Node
{
int Data;
struct Node* next;
}*rear, *front;
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int value)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->Data=value;
if (rear == NULL)
{
rear=temp;
rear->next=NULL;
front=rear;
}
else
{
rear->next=temp;
rear=temp;
temp->next=rear->next;
}
}
int Dequeue()
{
struct Node *temp=front;
int input;
if(temp==NULL)
{
printf("\nQueue is empty");
return 0;
}
else
{
front = front->next;
input=temp->Data;
free(temp);
return input;
}
}
void Display()
{
struct Node *temp=front;
if(temp!=NULL)
{
printf("\nElements are : ");
while(temp!=NULL)
{
printf("\t%d",temp->Data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nQueue is Empty");
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be reordered to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
return node;
else
FindMax(node->right);
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[j+1];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE];
int rear=front=ARRAY_SIZE;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be reordered to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
if (value < SortArray[mid])
{
mid = (low + high) / 2;
high = mid - 1;
}
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to sort a given list of elements using the QuickSort technique. Which of the following statement(s) given in the program should be removed to make the program compile, link and run and give the desired output?
void QuickSort(int *arry,int,int);
int main()
{
int arry[20],size,i;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter elements: ",size);
for(i=0; i< size; i++)
scanf("%d",&arry[i]);
QuickSort(arry,0,size-1);
printf("Sorted list: ");
for(i=0; i< size; i++)
printf(" %d",arry[i]);
}
void QuickSort(int *arry,int first,int last)
{
int pivot,temp,i,j;
if(first< last)
{
pivot=first;
i=first;
j=last;
while(i< j)
{
while(arry[i]< =arry[pivot]&&i< last)
i++;
while(arry[j]>arry[pivot])
j--;
while(arry[j]==arry[pivot])
i--;
if(i< j)
{
temp=arry[i];
arry[i]=arry[j];
arry[j]=temp;
}
}
temp=arry[pivot];
arry[pivot]=arry[j];
arry[j]=temp;
QuickSort(arry,first,j-1);
QuickSort(arry,j+1,last);
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be removed to make the program compile, link and run and give the desired output?
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
int queue[ARRAY_SIZE], rear=0, front=0;
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear]=input;
rear=rear+1;
front=front+1;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
rear=front+1;
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
while((i>1)&&(HeapArry[i/2]< tmp))
{
HeapArry[i]=HeapArry[i/2];
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
}
HeapArry[j/2]=tmp;
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
temp->next=StackTop;
StackTop=temp;
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
{
high = mid + 1;
low = mid + 1;
}
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to enqueue/dequeue the elements from a queue. Which of the following statement(s) given in the given program should be corrected to make the program compile, link and run and give the desired output?
int queue[ARRAY_SIZE], rear=0, front=0;
#define ARRAY_SIZE 10
void Enqueue(int);
int Dequeue();
void Display();
int main()
{
Enqueue(100);
Enqueue(200);
Enqueue(300);
Enqueue(400);
Dequeue();
Display();
}
void Enqueue(int input)
{
if(front==ARRAY_SIZE)
{
printf("\n Queue is full");
return;
}
else
{
queue[rear++]=input;
}
}
int Dequeue()
{
int value;
if(front==rear)
{
printf("\n Queue is empty");
return -1;
}
value=queue[front];
front=front+1;
return value;
}
void Display()
{
int i;
printf("\nThe queue elements are:");
for(i=front; i< rear; i++)
{
printf("%d ",queue[i]);
}
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop->next=NULL;
}
else
{
temp->next=StackTop;
StackTop=temp;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The given program is used to sort a given list of elements using the HeapSort technique. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
void Insert(int *HeapArry, int);
void Heapsort(int *HeapArry, int, int);
int main()
{
int HeapArry[20];
int i,j,size,tmp,k;
printf("Enter the number of elements to sort : ");
scanf("%d",&size);
printf("Enter the elements : \n");
for(i=1; i< =size; i++)
{
scanf("%d",&HeapArry[i]);
Insert(HeapArry,i);
}
j=size;
for(i=1; i< =j; i++)
{
tmp=HeapArry[1];
HeapArry[1]=HeapArry[size];
HeapArry[size]=tmp;
size--;
Heapsort(HeapArry,1,size);
}
printf("\n Sorted list is : ");
size=j;
for(i=1; i< =size; i++)
printf("%d ",HeapArry[i]);
getch();
return 0;
}
void Insert(int *HeapArry, int i)
{
int tmp;
tmp=HeapArry[i];
HeapArry[i]=HeapArry[i/2];
while((i>1)&&(HeapArry[i/2]< tmp))
{
i=i/2;
}
HeapArry[i]=tmp;
}
void Heapsort(int *HeapArry, int i, int size)
{
int tmp,j;
tmp=HeapArry[i];
j=i*2;
while(j< =size)
{
if((j< size)&&(HeapArry[j]< HeapArry[j+1]))
j++;
if(HeapArry[j]< HeapArry[j/2])
break;
HeapArry[j/2]=HeapArry[j];
j=j*2;
}
HeapArry[j/2]=tmp;
}
The following program is used to sort the elements using Bubble sort and search for an element using the Binary search technique. Which of the following statement(s) in the program should be removed to make the program compile, link and run and give the desired output?
void BubbleSort(int *SortArray,int NumOfValues);
void BinarySearch(int *SortArray,int NumOfValues,int value);
void main()
{
int SortArray[10];
int i, j, NumOfValues, Temp, value;
printf("Enter the number of values to be sorted : \n");
scanf("%d", &NumOfValues);
printf("Enter the values : \n");
for (i = 0; i < NumOfValues; i++)
{
scanf("%d", &SortArray[i]);
}
printf("Entered values are : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
BubbleSort(SortArray,NumOfValues);
printf("Sorted list : \n");
for (i = 0; i < NumOfValues; i++)
{
printf("%d\n", SortArray[i]);
}
printf("Enter value to be searched : \n");
scanf("%d", &value);
BinarySearch(SortArray,NumOfValues,value);
}
void BubbleSort(int *SortArray,int NumOfValues)
{
int i,j,Temp;
for (i = 0; i < NumOfValues; i++)
{
for (j = 0; j < (NumOfValues - i - 1); j++)
{
if (SortArray[j] > SortArray[j + 1])
{
Temp = SortArray[j];
SortArray[j] = SortArray[j + 1];
SortArray[j + 1] = Temp;
}
}
}
}
void BinarySearch(int *SortArray,int NumOfValues,int value)
{
int mid,high,low;
low = 1;
high = NumOfValues;
do
{
high = (mid + high) % 2;
mid = (low + high) / 2;
if (value < SortArray[mid])
high = mid - 1;
else if (value > SortArray[mid])
low = mid + 1;
}
while (value != SortArray[mid] && low < = high);
if (value == SortArray[mid])
{
printf("Value is found \n");
}
else
{
printf("Value is not present in the list \n");
}
}
The given program is used to push/pop the elements from a stack. Which of the following statement(s) given in the program should be reordered to make the program compile, link and run and give the desired output?
struct Node
{
int data;
struct Node *next;
}*StackTop;
void Push(int input);
int Pop();
void Display();
void main()
{
StackTop=NULL;
Push(100);
Push(200);
Push(300);
Push(500);
Pop();
Display();
}
void Push(int input)
{
struct Node *temp;
temp=(struct Node *)malloc(sizeof(struct Node));
temp->data=input;
if (StackTop == NULL)
{
StackTop=temp;
StackTop->next=NULL;
}
else
{
StackTop=temp;
temp->next=StackTop;
}
}
int Pop()
{
struct Node *TopVal;
int input;
TopVal=StackTop;
if(StackTop==NULL)
{
printf("\nStack is empty");
return -1;
}
else
{
StackTop = StackTop->next;
input=TopVal->data;
free(TopVal);
return input;
}
}
void Display()
{
struct Node *temp=StackTop;
if(temp!=NULL)
{
printf("\nElements are:\n");
while(temp!=NULL)
{
printf("\t%d\n",temp->data);
temp=temp->next;
}
printf("\n");
}
else
printf("\nStack is Empty");
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the program should be corrected to make it compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else if(data > node->data)
{
node->right = DeleteNode(node->right, data);
}
else
{
if(node->right && node==NULL)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}
The following program is used to perform Insertion, Deletion and Search operations on a Binary Search Tree and display the values in Inorder, PreOrder and PostOrder. Which of the following statement(s) given in the choices should be added to the program at some point to make the program compile, link and run and give the desired output?
typedef struct Node
{
int data;
struct Node *left;
struct Node *right;
} Node;
Node* FindMin(Node *node);
Node* FindMax(Node *node);
Node * InsertNode(Node *node,int data);
Node * DeleteNode(Node *node,int data);
Node * FindElement(Node *node, int data);
void PrintInorder(Node *node);
void PrintPreorder(Node *node);
void PrintPostorder(Node *node);
void main()
{
Node *root = NULL;
Node * temp;
root=InsertNode(root, 40);
root=InsertNode(root, 10);
root=InsertNode(root, 20);
root=InsertNode(root, 35);
root=InsertNode(root, 50);
root=InsertNode(root, 80);
root=DeleteNode(root, 50);
temp=FindElement(root, 80);
if(temp==NULL)
{
printf("Element not found\n");
}
else
{
printf("Element Found\n");
}
PrintInorder(root);
PrintPreorder(root);
PrintPostorder(root);
}
Node* FindMin(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left)
return FindMin(node->left);
else
return node;
}
Node* FindMax(Node *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right)
FindMax(node->right);
else
return node;
}
Node * InsertNode(Node *node,int data)
{
if(node==NULL)
{
Node *temp;
temp = (Node *)malloc(sizeof(Node));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = InsertNode(node->right,data);
}
else if(data < (node->data))
{
node->left = InsertNode(node->left,data);
}
return node;
}
Node * DeleteNode(Node *node, int data)
{
Node *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = DeleteNode(node->left, data);
}
else
{
if(node->right && node->left)
{
temp = FindMin(node->right);
node -> data = temp->data;
node -> right = DeleteNode(node->right,temp->data);
}
else
{
temp = node;
if(node->left == NULL)
node = node->right;
else if(node->right == NULL)
node = node->left;
free(temp);
}
}
return node;
}
Node * FindElement(Node *node, int data)
{
if(node==NULL)
{
return NULL;
}
if(data > node->data)
{
return FindElement(node->right,data);
}
else if(data < node->data)
{
return FindElement(node->left,data);
}
else
{
return node;
}
}
void PrintInorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintInorder(node->left);
printf("%d ",node->data);
PrintInorder(node->right);
}
void PrintPreorder(Node *node)
{
if(node==NULL)
{
return;
}
printf("%d ",node->data);
PrintPreorder(node->left);
PrintPreorder(node->right);
}
void PrintPostorder(Node *node)
{
if(node==NULL)
{
return;
}
PrintPostorder(node->left);
PrintPostorder(node->right);
printf("%d ",node->data);
}